Memcached源碼分析——串連狀態變化分析

來源:互聯網
上載者:User

轉換條件限定: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中學習到很多知識。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.