mongobridge close client ports on kill

This commit is contained in:
Aaron 2009-05-20 14:16:14 -04:00
parent 3b2ae5b7fb
commit c5ffd65fb2
1 changed files with 17 additions and 12 deletions

View File

@ -58,33 +58,26 @@ private:
MessagingPort &mp_; MessagingPort &mp_;
}; };
set<MessagingPort*> ports;
class MyListener : public Listener { class MyListener : public Listener {
public: public:
MyListener( int port ) : Listener( "", port ) {} MyListener( int port ) : Listener( "", port ) {}
virtual void accepted(MessagingPort *mp) { virtual void accepted(MessagingPort *mp) {
ports.insert( mp );
Forwarder f( *mp ); Forwarder f( *mp );
boost::thread t( f ); boost::thread t( f );
} }
}; };
void helpExit() {
cout << "usage mongobridge --port <port> --dest <destUri>" << endl;
cout << " port: port to listen for mongo messages" << endl;
cout << " destUri: uri of remote mongod instance" << endl;
::exit( -1 );
}
void check( bool b ) {
if ( !b )
helpExit();
}
auto_ptr< MyListener > listener; auto_ptr< MyListener > listener;
#if !defined(_WIN32) #if !defined(_WIN32)
#include <execinfo.h> #include <execinfo.h>
void cleanup( int sig ) { void cleanup( int sig ) {
close( listener->socket() ); close( listener->socket() );
for ( set<MessagingPort*>::iterator i = ports.begin(); i != ports.end(); i++ )
(*i)->shutdown();
::exit( 0 ); ::exit( 0 );
} }
@ -101,6 +94,18 @@ void setupSignals() {
inline void setupSignals() {} inline void setupSignals() {}
#endif #endif
void helpExit() {
cout << "usage mongobridge --port <port> --dest <destUri>" << endl;
cout << " port: port to listen for mongo messages" << endl;
cout << " destUri: uri of remote mongod instance" << endl;
::exit( -1 );
}
void check( bool b ) {
if ( !b )
helpExit();
}
int main( int argc, char **argv ) { int main( int argc, char **argv ) {
setupSignals(); setupSignals();