标签:des cWeb com http style div img code c log t
This article mainly introduces the process of Memcached, libevent structure of the main thread and worker thread based on the processing of the connection state of mutual conversion (not involving data access operations), the main business logic is the drive_machine. State transition process does not involve all the state, at the same time, because of his ability, some state transition may be wrong, also please predecessors. Conversion conditions: TCP, ASCII protocol. (not including conn_swallow, binary protocols will use this state)
First introduces the connection, connection is connected to the conn Memcached definition of their own. All state, drive_machine () is the main conversion of the state of operation:
enum conn_states { conn_listening, /**<the socket which listens for connections /The main thread waits on the link*/ conn_new_cmd, /**<Prepare connection for next command /workerThreads are waiting for the command*/ conn_waiting, /**<waiting for a readable socket /workerThe thread is waitingsdfA readable information*/ conn_read, /**<reading in a command line /workerThread the read command*/ conn_parse_cmd, /**<try to parse a command from the input buffer /wokerThread*/ conn_write, /**<writing out a simple response /workerThread*/ conn_nread, /**<reading in a fixed number of bytes /workerBecause the command finished thread, Continue to read / conn_swallow, /**<swallowing unnecessary bytes w/o storing /worker thread, ASCIIThe agreement is not involved in this state*/ conn_closing, /**<closing this connection */ conn_mwrite, /**<writing out many items sequentially /workerThread, The response content to * / conn_max_state /**<Max state value (used for assertion) / marker for conn_states boundary, Beyond that states is wrong*/ };
In the Memcached.c (main), the main thread and worker thread to complete the necessary initialization, bind the corresponding libevent events, then the main thread monitor bind monitoring ports, do a good job recycling for formal. Below is the total conversion connection state graph.
Above is the conversion and connection status, analysis is not in place or wrong place please. In general, feel the Memcached application of libevent writes very standard, follow up with libevent, but also can learn from Memcached to a lot of knowledge.
reference from:http://www.programering.com/a/MzM3MjMwATU.html
Memcached source code analysis -- Analysis of change of state--reference,码迷,mamicode.com
Memcached source code analysis -- Analysis of change of state--reference
标签:des cWeb com http style div img code c log t
原文地址:http://www.cnblogs.com/davidwang456/p/3701881.html