Skip to content

Commit

Permalink
Move bind_ip handling from me() to Me(). SERVER-1813
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeard0531 committed Sep 27, 2010
1 parent aab1fcf commit 8f6b5ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion db/repl/rs_initiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace mongo {
bob b;
b.append("_id", name);
bob members;
members.append("0", BSON( "_id" << 0 << "host" << HostAndPort::me().toString() ));
members.append("0", BSON( "_id" << 0 << "host" << HostAndPort::Me().toString() ));
for( unsigned i = 0; i < seeds.size(); i++ )
members.append(bob::numStr(i+1), BSON( "_id" << i+1 << "host" << seeds[i].toString()));
b.appendArray("members", members.obj());
Expand Down
33 changes: 17 additions & 16 deletions util/hostandport.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ namespace mongo {
}

static HostAndPort me() {
const char* ips = cmdLine.bind_ip.c_str();
while(*ips){
string ip;
const char * comma = strchr(ips, ',');
if (comma){
ip = string(ips, comma - ips);
ips = comma + 1;
}else{
ip = string(ips);
ips = "";
}
HostAndPort h = HostAndPort(ip, cmdLine.port);
if (!h.isLocalHost()) {
return h;
}
}
return HostAndPort("localhost", cmdLine.port);
}

Expand Down Expand Up @@ -109,6 +93,23 @@ namespace mongo {
}

inline HostAndPort HostAndPort::Me() {
const char* ips = cmdLine.bind_ip.c_str();
while(*ips){
string ip;
const char * comma = strchr(ips, ',');
if (comma){
ip = string(ips, comma - ips);
ips = comma + 1;
}else{
ip = string(ips);
ips = "";
}
HostAndPort h = HostAndPort(ip, cmdLine.port);
if (!h.isLocalHost()) {
return h;
}
}

string h = getHostName();
assert( !h.empty() );
assert( h != "localhost" );
Expand Down

0 comments on commit 8f6b5ab

Please sign in to comment.