diff options
author | alerner <alerner@installer-desktop.(none)> | 2010-05-28 16:24:52 -0400 |
---|---|---|
committer | alerner <alerner@installer-desktop.(none)> | 2010-05-28 16:27:06 -0400 |
commit | c347ef85f53e814cf90a3a24f6e615305702d0d0 (patch) | |
tree | 096fe91670f56fd244a6278d37194947f038efff /util | |
parent | c9f99b7ef1079e5f2225878f451c9dadcdb6c38f (diff) | |
download | mongo-c347ef85f53e814cf90a3a24f6e615305702d0d0.tar.gz |
mongos now accepts a --bind_ip argument [SERVER-1156]
Diffstat (limited to 'util')
-rw-r--r-- | util/message_server.h | 19 | ||||
-rw-r--r-- | util/message_server_asio.cpp | 16 | ||||
-rw-r--r-- | util/message_server_port.cpp | 9 |
3 files changed, 24 insertions, 20 deletions
diff --git a/util/message_server.h b/util/message_server.h index 0ec220b61b3..a98a8645000 100644 --- a/util/message_server.h +++ b/util/message_server.h @@ -31,19 +31,20 @@ namespace mongo { virtual ~MessageHandler(){} virtual void process( Message& m , AbstractMessagingPort* p ) = 0; }; - + class MessageServer { public: - MessageServer( int port , MessageHandler * handler ) : _port( port ) , _handler( handler ){} - virtual ~MessageServer(){} + struct Options { + int port; // port to bind to + string ipList; // addresses to bind to + Options() : port(0), ipList(""){} + }; + + virtual ~MessageServer(){} virtual void run() = 0; - - protected: - - int _port; - MessageHandler* _handler; }; - MessageServer * createServer( int port , MessageHandler * handler ); + // TODO use a factory here to decide between port and asio variations + MessageServer * createServer( const MessageServer::Options& opts , MessageHandler * handler ); } diff --git a/util/message_server_asio.cpp b/util/message_server_asio.cpp index 327f7195c25..0c9479c48b6 100644 --- a/util/message_server_asio.cpp +++ b/util/message_server_asio.cpp @@ -204,9 +204,11 @@ namespace mongo { class AsyncMessageServer : public MessageServer { public: - AsyncMessageServer( int port , MessageHandler * handler ) - : MessageServer( port , handler ) - , _endpoint( tcp::v4() , port ) + // TODO accept an IP address to bind to + AsyncMessageServer( const MessageServer::Options& opts , MessageHandler * handler ) + : _port( opts.port ) + , _handler(handler) + , _endpoint( tcp::v4() , opts.port ) , _acceptor( _ioservice , _endpoint ) { _accept(); @@ -232,7 +234,7 @@ namespace mongo { _accept(); } - void _accept(){ + void _accept( ){ shared_ptr<MessageServerSession> session( new MessageServerSession( _handler , _ioservice ) ); _acceptor.async_accept( session->socket() , boost::bind( &AsyncMessageServer::handleAccept, @@ -243,13 +245,15 @@ namespace mongo { } private: + int _port; + MessageHandler * _handler; io_service _ioservice; tcp::endpoint _endpoint; tcp::acceptor _acceptor; }; - MessageServer * createServer( int port , MessageHandler * handler ){ - return new AsyncMessageServer( port , handler ); + MessageServer * createServer( const MessageServer::Options& opts , MessageHandler * handler ){ + return new AsyncMessageServer( opts , handler ); } } diff --git a/util/message_server_port.cpp b/util/message_server_port.cpp index 08e5b8200e5..ed751433173 100644 --- a/util/message_server_port.cpp +++ b/util/message_server_port.cpp @@ -73,9 +73,8 @@ namespace mongo { class PortMessageServer : public MessageServer , public Listener { public: - PortMessageServer( int port , MessageHandler * handler ) : - MessageServer( port , handler ) , - Listener( "", port ){ + PortMessageServer( const MessageServer::Options& opts, MessageHandler * handler ) : + Listener( opts.ipList, opts.port ){ uassert( 10275 , "multiple PortMessageServer not supported" , ! pms::handler ); pms::handler = handler; @@ -117,8 +116,8 @@ namespace mongo { }; - MessageServer * createServer( int port , MessageHandler * handler ){ - return new PortMessageServer( port , handler ); + MessageServer * createServer( const MessageServer::Options& opts , MessageHandler * handler ){ + return new PortMessageServer( opts , handler ); } TicketHolder connTicketHolder(20000); |