mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
port quit and allocatePorts
This commit is contained in:
parent
6ed1a1e376
commit
01f3e49668
@ -5,4 +5,4 @@ p.ensureIndex( { ts: 1 } );
|
||||
|
||||
e = p.find( { live: true, ts: { $lt: new Date( 1234119308272 ) }, cls: "entry", verticals: " alleyinsider" } ).sort( { ts: -1 } ).hint( { ts: 1 } ).explain();
|
||||
assert.eq( e.startKey.ts.getTime(), new Date( 1234119308272 ).getTime() );
|
||||
assert.eq( 1, e.endKey.ts.$minElement );
|
||||
assert.eq( 1, e.endKey.ts.$minElement );
|
||||
|
@ -27,6 +27,8 @@
|
||||
931187AE0F85463700A6DC44 /* pair3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = pair3.js; sourceTree = "<group>"; };
|
||||
931974610FB8C2BD001FE537 /* count.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = count.js; sourceTree = "<group>"; };
|
||||
931974EE0FB9C3A5001FE537 /* diskfull.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = diskfull.js; sourceTree = "<group>"; };
|
||||
931979800FBC67FB001FE537 /* mongo_vstudio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mongo_vstudio.cpp; sourceTree = "<group>"; };
|
||||
931979810FBC67FB001FE537 /* utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utils.cpp; sourceTree = "<group>"; };
|
||||
931A027A0F58AA4400147C0E /* jsobjmanipulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsobjmanipulator.h; sourceTree = "<group>"; };
|
||||
93202DE40F879CB600AF3B71 /* all.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = all.js; sourceTree = "<group>"; };
|
||||
93278F570F72D32900844664 /* gridfs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gridfs.cpp; sourceTree = "<group>"; };
|
||||
@ -323,6 +325,8 @@
|
||||
9302D9920F30AB8C00DFA4EF /* shell */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
931979800FBC67FB001FE537 /* mongo_vstudio.cpp */,
|
||||
931979810FBC67FB001FE537 /* utils.cpp */,
|
||||
9302D9930F30AB8C00DFA4EF /* collection.js */,
|
||||
9302D9940F30AB8C00DFA4EF /* db.js */,
|
||||
9302D9950F30AB8C00DFA4EF /* dbshell.cpp */,
|
||||
|
@ -92,9 +92,55 @@ namespace mongo {
|
||||
return ret.obj();
|
||||
}
|
||||
|
||||
void installShellUtils( Scope& scope ){
|
||||
BSONObj Quit(const BSONObj& args) {
|
||||
// If not arguments are given first element will be EOO, which
|
||||
// converts to the integer value 0.
|
||||
int exit_code = int( args.firstElement().number() );
|
||||
::exit(exit_code);
|
||||
return undefined_;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
BSONObj AllocatePorts( const BSONObj &args ) {
|
||||
uassert( "allocatePorts takes exactly 1 argument", args.nFields() == 1 );
|
||||
uassert( "allocatePorts needs to be passed an integer", args.firstElement().isNumber() );
|
||||
|
||||
int n = int( args.firstElement().number() );
|
||||
|
||||
vector< int > ports;
|
||||
for( int i = 0; i < n; ++i ) {
|
||||
int s = socket( AF_INET, SOCK_STREAM, 0 );
|
||||
assert( s );
|
||||
|
||||
sockaddr_in address;
|
||||
memset(address.sin_zero, 0, sizeof(address.sin_zero));
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_port = 0;
|
||||
address.sin_addr.s_addr = 0;
|
||||
assert( 0 == ::bind( s, (sockaddr*)&address, sizeof( address ) ) );
|
||||
|
||||
sockaddr_in newAddress;
|
||||
socklen_t len = sizeof( newAddress );
|
||||
assert( 0 == getsockname( s, (sockaddr*)&newAddress, &len ) );
|
||||
ports.push_back( ntohs( newAddress.sin_port ) );
|
||||
|
||||
assert( 0 == close( s ) );
|
||||
}
|
||||
|
||||
sort( ports.begin(), ports.end() );
|
||||
BSONObjBuilder b;
|
||||
b.append( "", ports );
|
||||
return b.obj();
|
||||
}
|
||||
#endif
|
||||
|
||||
void installShellUtils( Scope& scope ){
|
||||
scope.injectNative( "listFiles" , listFiles );
|
||||
scope.injectNative( "sleep" , JSSleep );
|
||||
scope.injectNative( "quit", Quit );
|
||||
#if !defined(_WIN32)
|
||||
scope.injectNative( "allocatePorts", AllocatePorts );
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user