轉換條件限定:TCP,ASCII協議。(狀態不包括conn_swallow,二進位協議才會用到此狀態)
1 總攬
enum conn_states { conn_listening, /**< the socket which listens for connections /主線程等待連結*/ conn_new_cmd, /**< Prepare connection for next command /worker線程等待命令*/ conn_waiting, /**< waiting for a readable socket /worker線程等待sdf中有可讀資訊*/ conn_read, /**< reading in a command line /worker線程讀命令*/ conn_parse_cmd, /**< try to parse a command from the input buffer /woker線程*/ conn_write, /**< writing out a simple response /worker線程*/ conn_nread, /**< reading in a fixed number of bytes /worker線程由於命令沒讀完,繼續讀取*/ conn_swallow, /**< swallowing unnecessary bytes w/o storing /worker線程,ASCII協議不涉及此狀態*/ conn_closing, /**< closing this connection */ conn_mwrite, /**< writing out many items sequentially /worker線程,響應內容中寫出*/ conn_max_state /**< Max state value (used for assertion) /用於標記conn_states邊界,超出說明states有錯*/};
2 接收串連分發給worker線程
3 資料讀入
4 命令解析
5 命令返回
6 結果輸出
7 小結
以上就是整個串連狀態的轉換情況了,分析不到位或者有誤的地方還請大家指正。總體來說,感覺Memcached對libevent的應用寫的十分標準,後續使用libevent時,也可以從Memcached中學習到很多知識。