コード例 #1
0
ファイル: message.cpp プロジェクト: 10genReviews/mongo
 void Message::send( MessagingPort &p, const char *context ) {
     if ( empty() ) {
         return;
     }
     if ( _buf != 0 ) {
         p.send( (char*)_buf, _buf->len, context );
     }
     else {
         p.send( _data, context );
     }
 }
コード例 #2
0
ファイル: message.cpp プロジェクト: 3rf/mongo
 void Message::send( MessagingPort &p, const char *context ) {
     if ( empty() ) {
         return;
     }
     if ( _buf != 0 ) {
         p.send( _buf, MsgData::ConstView(_buf).getLen(), context );
     }
     else {
         p.send( _data, context );
     }
 }
コード例 #3
0
ファイル: db.cpp プロジェクト: gilles/mongo
    void msg(const char *m, const char *address, int port, int extras = 0) {
        SockAddr db(address, port);

        //  SockAddr db("127.0.0.1", DBPort);
        //  SockAddr db("192.168.37.1", MessagingPort::DBPort);
        //  SockAddr db("10.0.21.60", MessagingPort::DBPort);
        //  SockAddr db("172.16.0.179", MessagingPort::DBPort);

        MessagingPort p;
        if ( !p.connect(db) ){
            log() << "msg couldn't connect" << endl;
            return;
        }

        const int Loops = 1;
        for ( int q = 0; q < Loops; q++ ) {
            Message send;
            Message response;

            send.setData( dbMsg , m);
            int len = send.header()->dataLen();

            for ( int i = 0; i < extras; i++ )
                p.say(/*db, */send);

            Timer t;
            bool ok = p.call(send, response);
            double tm = ((double) t.micros()) + 1;
            out() << " ****ok. response.data:" << ok << " time:" << tm / 1000.0 << "ms "
                  << "len: " << len << " data: " << response.singleData()->_data << endl;

            if (  q+1 < Loops ) {
                out() << "\t\tSLEEP 8 then sending again as a test" << endl;
                sleepsecs(8);
            }
        }
        sleepsecs(1);

        p.shutdown();
    }
コード例 #4
0
        /**
         * Handles incoming messages from a given socket.
         *
         * Terminating conditions:
         * 1. Assertions while handling the request.
         * 2. Socket is closed.
         * 3. Server is shutting down (based on inShutdown)
         *
         * @param arg this method is in charge of cleaning up the arg object.
         *
         * @return NULL
         */
        static void* handleIncomingMsg(void* arg) {
            TicketHolderReleaser connTicketReleaser( &Listener::globalTicketHolder );

            scoped_ptr<HandleIncomingMsgParam> himArg(static_cast<HandleIncomingMsgParam*>(arg));
            MessagingPort* inPort = himArg->inPort;
            MessageHandler* handler = himArg->handler;

            {
                string threadName = "conn";
                if ( inPort->connectionId() > 0 )
                    threadName = str::stream() << threadName << inPort->connectionId();
                setThreadName( threadName.c_str() );
            }

            verify( inPort );
            inPort->psock->setLogLevel(1);
            scoped_ptr<MessagingPort> p( inPort );

            string otherSide;

            Message m;
            try {
                LastError * le = new LastError();
                lastError.reset( le ); // lastError now has ownership

                otherSide = p->psock->remoteString();

#ifdef MONGO_SSL
                std::string x509SubjectName = p->psock->doSSLHandshake();
                inPort->setX509SubjectName(x509SubjectName);
#endif 
                handler->connected( p.get() );

                while ( ! inShutdown() ) {
                    m.reset();
                    p->psock->clearCounters();

                    if ( ! p->recv(m) ) {
                        if( !cmdLine.quiet ){
                            int conns = Listener::globalTicketHolder.used()-1;
                            const char* word = (conns == 1 ? " connection" : " connections");
                            log() << "end connection " << otherSide << " (" << conns << word << " now open)" << endl;
                        }
                        p->shutdown();
                        break;
                    }

                    handler->process( m , p.get() , le );
                    networkCounter.hit( p->psock->getBytesIn() , p->psock->getBytesOut() );
                }
            }
            catch ( AssertionException& e ) {
                log() << "AssertionException handling request, closing client connection: " << e << endl;
                p->shutdown();
            }
            catch ( SocketException& e ) {
                log() << "SocketException handling request, closing client connection: " << e << endl;
                p->shutdown();
            }
            catch ( const DBException& e ) { // must be right above std::exception to avoid catching subclasses
                log() << "DBException handling request, closing client connection: " << e << endl;
                p->shutdown();
            }
            catch ( std::exception &e ) {
                error() << "Uncaught std::exception: " << e.what() << ", terminating" << endl;
                dbexit( EXIT_UNCAUGHT );
            }
            catch ( ... ) {
                error() << "Uncaught exception, terminating" << endl;
                dbexit( EXIT_UNCAUGHT );
            }

            // Normal disconnect path.
#ifdef MONGO_SSL
            SSLManagerInterface* manager = getSSLManager();
            if (manager)
                manager->cleanupThreadLocals();
#endif
            handler->disconnected( p.get() );

            return NULL;
        }
コード例 #5
0
ファイル: listen.cpp プロジェクト: nosqldb/mongo
void Listener::accepted(boost::shared_ptr<Socket> psocket, long long connectionId ) {
    MessagingPort* port = new MessagingPort(psocket);
    port->setConnectionId( connectionId );
    acceptedMP( port );
}