Mongo source code learning (3) Request receiving Transport Layer

Source: Internet
Author: User

In the previous blog (Mongo source code learning (2) dB. CPP mongodbmain method analysis. the execution process of mongodbmain in CPP is analyzed, and initandlisten (serverglobalparams. port) to listen to the port. The default value is 27017. When the program is executed, it is disconnected and cannot be traced. There must be an accept method in another place to receive client requests. Then I found the folder transportlayer and found the relevant code.

Transport_layer.h

// Mongo namespace Mongo {class operationcontext; // transport namespace, I am a CPP white, the namespace can also be nested, todo: namespace learn the namespace transport {// connected SSL model. Todo: SSL can be used to understand Enum connectsslmode {kglobalsslmode, kenablessl, kdisablessl}; // What should be declared, todo: c ++ declares class reactor; // using can also be used like this. What is shared_ptr? You can understand it. // You can't write it anymore, in this case, let's take a look at Mongo's c ++ source code using reactorhandle = STD: shared_ptr <reactor>;/*** the transportlay Er moves messages between transport: endpoints and the database. * This class owns an acceptor that generates new endpoints from which it can * Source messages. ** the transportlayer creates session objects and maps them internally to * endpoints. new sessions are passed to the database (via a serviceentrypoint) * to be run. the database must then call additional methods on the transportlayer * t O manage the session in a get-message, handle-message, return-message cycle. * It must do this on its own thread (s ). ** references to the transportlayer shoshould be stored on service context objects. * // *** transportlayer transmits a message between transport: endpoints and database (that is, Mongo ). * This class has an acceptor, which can generate a new endpoints from the original message. ** Transportlay creates new session objects and maps them to endpoints in the internal part. The new session is passed to the database through a serviceentrypoint. You must call other transportlay methods to manage the sessions in the get-message, * handle-message and return-message cycles. In addition, these tasks must be done in its own thread. */Class transportlayer {// What is this ghost movie _ disallow_copying (transportlayer); Public: // declare various States static const status sessionunknownstatus; static const status shutdownstatus; static const status ticketsessionunknownstatus; static const status ticketsessionclosedstatus; // set the session object to a friend's friend class session; // virtual, todo: learn more about virtual ~ Transportlayer () = default; // connect to virtual statuswith <sessionhandle> connect (hostandport peer, connectsslmode sslmode, milliseconds timeout) = 0; // asynchronously connect virtual future <sessionhandle> asyncconnect (hostandport peer, connectsslmode sslmode, const reactorhandle & reactor, milliseconds timeout) = 0;/*** start the transportlayer. after this point, the transportlayer will be begin accepting active * session S from new transport: endpoints. * // *** start transportlayer. After that, the transportlayer starts to receive active sessions from the new transport: endpoints. */Virtual status start () = 0;/*** shut the transportlayer down. after this point, the transportlayer will * end all active sessions and won't accept new transport: endpoints. any * future callto wait () or asyncwait () will fail. this method is synchronous and * will not return until all sessions have ended and any network connections have been * closed. * // *** disable transportlay. After that, the transportlayer terminates all active sessions and no longer receives new endpoints. * Any future calls to wait () and asyncwait () will fail. This method is synchronized and will not be returned until all sessions are completed * And all network connections are closed. */Virtual void Shutdown () = 0;/*** optional method for subclasses to setup their State before being ready to accept * connections. * // ** this is an optional method. Subclass can use this method to set their statuses when preparing to receive connections. */Virtual status setup () = 0; Enum whichreactor {kingress, kegress, role}; virtual reactorhandle getreactor (whichreactor which) = 0; virtual batonhandle makebaton (operationcontext * opctx) {return nullptr;} protected: transportlayer () = default ;};}// namespace transport} // namespace Mongo

Here we look at it a bit. The main roles are:

Transportlay: an acceptor receives a request, generates a new endpoints, creates a session, and maps the session internally to endpoints. At the same time, transportlay also transmits messages between endpoints and databases.

Session: Get-message, handle-message, and return-message, but these must be managed by the transportlayer.

Endpoints: the abstract concept of the end.

Acceptor: the one that receives the request.

Database: Our Mongo background

Mongo source code learning (3) Request receiving Transport Layer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.