summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-02-14 14:13:27 -0500
committerEliot Horowitz <eliot@10gen.com>2011-02-14 14:13:27 -0500
commit36f405d6a76d3940e0d589038edc5a2bd2a76c00 (patch)
tree835bcef07b223eef62abcbffc217fcf8cd60896d /client
parent6dee6f9498d0f5d2d5a5eac8e92fb9ff62124105 (diff)
parenta969a0168cdb23c8cfa0fbcb26a92d0cabebf411 (diff)
downloadmongo-36f405d6a76d3940e0d589038edc5a2bd2a76c00.tar.gz
Merge branch 'master' of github.com:mongodb/mongo
Diffstat (limited to 'client')
-rw-r--r--client/dbclient.cpp33
-rw-r--r--client/dbclient.h31
2 files changed, 42 insertions, 22 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp
index 631c6e6ccb5..b4214abbbb2 100644
--- a/client/dbclient.cpp
+++ b/client/dbclient.cpp
@@ -31,6 +31,39 @@
namespace mongo {
+ void ConnectionString::_fillServers( string s ) {
+
+ {
+ string::size_type idx = s.find( '/' );
+ if ( idx != string::npos ) {
+ _setName = s.substr( 0 , idx );
+ s = s.substr( idx + 1 );
+ _type = SET;
+ }
+ }
+
+ string::size_type idx;
+ while ( ( idx = s.find( ',' ) ) != string::npos ) {
+ _servers.push_back( s.substr( 0 , idx ) );
+ s = s.substr( idx + 1 );
+ }
+ _servers.push_back( s );
+
+ }
+
+ void ConnectionString::_finishInit() {
+ stringstream ss;
+ if ( _type == SET )
+ ss << _setName << "/";
+ for ( unsigned i=0; i<_servers.size(); i++ ) {
+ if ( i > 0 )
+ ss << ",";
+ ss << _servers[i].toString();
+ }
+ _string = ss.str();
+ }
+
+
DBClientBase* ConnectionString::connect( string& errmsg ) const {
switch ( _type ) {
case MASTER: {
diff --git a/client/dbclient.h b/client/dbclient.h
index ace3dd4d783..9cb6571ca85 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -154,13 +154,18 @@ namespace mongo {
}
ConnectionString( const string& s , ConnectionType favoredMultipleType ) {
+ _type = INVALID;
+
_fillServers( s );
- if ( _servers.size() == 1 ) {
+ if ( _type != INVALID ) {
+ // set already
+ }
+ else if ( _servers.size() == 1 ) {
_type = MASTER;
}
else {
_type = favoredMultipleType;
- assert( _type != MASTER );
+ assert( _type == SET || _type == SYNC );
}
_finishInit();
}
@@ -183,26 +188,8 @@ namespace mongo {
private:
- void _fillServers( string s ) {
- string::size_type idx;
- while ( ( idx = s.find( ',' ) ) != string::npos ) {
- _servers.push_back( s.substr( 0 , idx ) );
- s = s.substr( idx + 1 );
- }
- _servers.push_back( s );
- }
-
- void _finishInit() {
- stringstream ss;
- if ( _type == SET )
- ss << _setName << "/";
- for ( unsigned i=0; i<_servers.size(); i++ ) {
- if ( i > 0 )
- ss << ",";
- ss << _servers[i].toString();
- }
- _string = ss.str();
- }
+ void _fillServers( string s );
+ void _finishInit();
ConnectionType _type;
vector<HostAndPort> _servers;