Files
mongo/util/message_server_port.cpp
Eliot Horowitz 474d2c0d24 switch mongos to use MessageServer
use boost asio if it exists on the system
2009-03-02 13:35:34 -05:00

58 lines
1.4 KiB
C++

// message_server_port.cpp
#ifndef USE_ASIO
#include "message.h"
#include "message_server.h"
namespace mongo {
class PortMessageServer : public MessageServer , public Listener {
public:
PortMessageServer( int port , MessageHandler * handler ) :
MessageServer( port , handler ) ,
Listener( port ){
}
void threadRun( MessagingPort * p ){
assert( p );
Message m;
try {
while ( 1 ){
m.reset();
if ( ! p->recv(m) ) {
log() << "end connection " << p->farEnd.toString() << endl;
p->shutdown();
break;
}
_handler->process( m , p );
}
}
catch ( ... ){
problem() << "uncaught exception in PortMessageServer::threadRun, closing connection" << endl;
delete p;
}
}
virtual void accepted(MessagingPort * p) {
boost::thread thr( bind( &PortMessageServer::threadRun , this , p ) );
}
void run(){
listen();
}
};
MessageServer * createServer( int port , MessageHandler * handler ){
return new PortMessageServer( port , handler );
}
}
#endif