diff options
author | Aaron <aaron@10gen.com> | 2009-04-03 11:43:27 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-04-03 11:43:27 -0400 |
commit | 80de3918c38cee1935a6779e7b91561d3b823007 (patch) | |
tree | 5becfa052a3e848bb7600ef289ca28bec317841b /shell | |
parent | 83a1aded10fcbe7c42228e1fd1ebe27866b8c0aa (diff) | |
download | mongo-80de3918c38cee1935a6779e7b91561d3b823007.tar.gz |
sort allocated ports, since linux os doesn't allocate them in sorted order
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ShellUtils.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/shell/ShellUtils.cpp b/shell/ShellUtils.cpp index 5358cffd515..f9cb83837d6 100644 --- a/shell/ShellUtils.cpp +++ b/shell/ShellUtils.cpp @@ -553,8 +553,8 @@ Handle< Value > AllocatePorts( const Arguments &args ) { jsassert( args[0]->IsInt32() , "allocatePorts needs to be passed an integer" ); int n = args[0]->ToInt32()->Value(); - - Local< Array > ret = Array::New( n ); + + vector< int > ports; for( int i = 0; i < n; ++i ) { int s = socket( AF_INET, SOCK_STREAM, 0 ); assert( s ); @@ -569,11 +569,16 @@ Handle< Value > AllocatePorts( const Arguments &args ) { sockaddr_in newAddress; socklen_t len = sizeof( newAddress ); assert( 0 == getsockname( s, (sockaddr*)&newAddress, &len ) ); - ret->Set( Number::New( i ), Number::New( ntohs( newAddress.sin_port ) ) ); + ports.push_back( ntohs( newAddress.sin_port ) ); assert( 0 == close( s ) ); } + sort( ports.begin(), ports.end() ); + Local< Array > ret = Array::New( n ); + for( unsigned i = 0; i < ports.size(); ++i ) + ret->Set( Number::New( i ), Number::New( ports[ i ] ) ); + return ret; } |