0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

fix giving config servers with/without port

This commit is contained in:
Eliot Horowitz 2009-02-17 10:25:35 -05:00
parent 1a4ad3f915
commit 2aae06ec8b
2 changed files with 25 additions and 11 deletions

View File

@ -170,7 +170,7 @@ namespace mongo {
if ( configHosts.empty() ) { if ( configHosts.empty() ) {
if ( ! infer ) { if ( ! infer ) {
out() << "--griddb or --infer required\n"; out() << "--configdb or --infer required\n";
exit(7); exit(7);
} }
stringstream sl, sr; stringstream sl, sr;
@ -184,17 +184,12 @@ namespace mongo {
right = sr.str(); right = sr.str();
} }
else { else {
stringstream sl, sr; hostLeft = getHost( configHosts[0] , false );
sl << configHosts[0]; left = getHost( configHosts[0] , true );
hostLeft = sl.str();
sl << ":" << Port;
left = sl.str();
if ( configHosts.size() > 1 ) { if ( configHosts.size() > 1 ) {
sr << configHosts[1]; hostRight = getHost( configHosts[1] , false );
hostRight = sr.str(); right = getHost( configHosts[1] , true );
sr << ":" << Port;
right = sr.str();
} }
} }
@ -240,6 +235,22 @@ namespace mongo {
return true; return true;
} }
string ConfigServer::getHost( string name , bool withPort ){
if ( name.find( ":" ) ){
if ( withPort )
return name;
return name.substr( 0 , name.find( ":" ) );
}
if ( withPort ){
stringstream ss;
ss << name << ":" << Port;
return ss.str();
}
return name;
}
ConfigServer configServer; ConfigServer configServer;
Grid grid; Grid grid;
} }

View File

@ -115,6 +115,9 @@ namespace mongo {
call at startup, this will initiate connection to the grid db call at startup, this will initiate connection to the grid db
*/ */
bool init( vector<string> configHosts , bool infer ); bool init( vector<string> configHosts , bool infer );
};
private:
string getHost( string name , bool withPort );
};
} // namespace mongo } // namespace mongo