{"id":48144,"date":"2025-07-30T10:53:55","date_gmt":"2025-07-30T02:53:55","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/48144.html"},"modified":"2025-07-30T10:53:55","modified_gmt":"2025-07-30T02:53:55","slug":"%e3%80%90%e4%bb%bfmuduo%e5%ba%93%e5%ae%9e%e7%8e%b0%e5%b9%b6%e5%8f%91%e6%9c%8d%e5%8a%a1%e5%99%a8%e3%80%91connection%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/48144.html","title":{"rendered":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757"},"content":{"rendered":"<\/p>\n<h4>\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668<\/h4>\n<ul>\n<li>\u4e00.Connection\u6a21\u5757<\/li>\n<li>\u4e8c.\u6210\u5458\u53d8\u91cf<\/li>\n<li>\n<ul>\n<li>1.\u8fde\u63a5\u552f\u4e00ID(\u8fde\u63a5\u7ba1\u7406)<\/li>\n<li>2.Socket\u5bf9\u8c61(\u5957\u63a5\u5b57\u64cd\u4f5c\u7ba1\u7406)<\/li>\n<li>3.Channel\u5bf9\u8c61(\u8fde\u63a5\u4e8b\u4ef6\u7ba1\u7406)<\/li>\n<li>4.Buffer\u5bf9\u8c61(\u7f13\u51b2\u533a\u7ba1\u7406)<\/li>\n<li>5.ConnStatus\u5bf9\u8c61(\u8fde\u63a5\u72b6\u6001\u7ba1\u7406)<\/li>\n<li>6.EventLoop\u5bf9\u8c61(\u8fde\u63a5\u76d1\u63a7\/\u5b9a\u65f6\u4efb\u52a1\u7ba1\u7406)<\/li>\n<li>7.Any\u5bf9\u8c61(\u4e0a\u4e0b\u6587\u7ba1\u7406)<\/li>\n<li>8.\u662f\u5426\u542f\u52a8\u975e\u6d3b\u8dc3\u8d85\u65f6\u8fde\u63a5\u9500\u6bc1\u6807\u5fd7\u4f4d<\/li>\n<li>9.5\u4e2a\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09.\u6210\u5458\u51fd\u6570<\/li>\n<li>\n<ul>\n<li>1.\u79c1\u6709\u6210\u5458\u51fd\u6570(\u4e3a\u5185\u90e8\u63d0\u4f9b\u7684\u63a5\u53e3)<\/li>\n<li>\n<ul>\n<li>1.1\u5bf9\u8fde\u63a5\u7684\u64cd\u4f5c\u8981\u90fd\u653e\u5165\u5bf9\u5e94\u7684\u7ebf\u7a0b\u4e2d\u8fd0\u884c<\/li>\n<li>\n<ul>\n<li>EnableInactiveReleaseInLoop()<\/li>\n<li>CancelInactiveReleaseInLoop()<\/li>\n<li>EstablishedInLoop()<\/li>\n<li>SendInLoop()<\/li>\n<li>ShutdownInLoop()<\/li>\n<li>ReleaseInLoop()<\/li>\n<li>UpgradeInLoop()<\/li>\n<\/ul>\n<\/li>\n<li>1.2\u63cf\u8ff0\u7b26\u7684\u5c31\u7eea\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570\u6784\u5efa<\/li>\n<li>\n<ul>\n<li>HandleRead()<\/li>\n<li>HandleWrite()<\/li>\n<li>HandleClose()<\/li>\n<li>HandleError()<\/li>\n<li>HandleEvent()<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>2.\u516c\u6709\u6210\u5458\u51fd\u6570(\u4e3a\u5916\u90e8\u63d0\u4f9b\u7684\u63a5\u53e3)<\/li>\n<li>\n<ul>\n<li>2.1\u6784\u9020\u51fd\u6570<\/li>\n<li>2.2\u5bf9\u8fde\u63a5\u64cd\u4f5c\u7684\u51fd\u6570<\/li>\n<li>2.3\u5bf9\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u8bbe\u7f6e\u7684\u51fd\u6570<\/li>\n<li>2.4\u5bf9\u6210\u5458\u53d8\u91cf\u64cd\u4f5c\u7684\u51fd\u6570<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e00.Connection\u6a21\u5757<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730025343-68898937b5df1.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> Connection\u6a21\u5757\u5c01\u88c5\u4e86Socket\u6a21\u5757&#xff0c;Buffer\u6a21\u5757&#xff0c;Channel\u6a21\u5757&#xff0c;EventLoop\u6a21\u5757\u7b49\u3002 \u5b83\u5b9e\u73b0\u5bf9\u4e00\u4e2a\u901a\u4fe1\u5957\u63a5\u5b57\u7684\u6574\u4f53\u7ba1\u7406&#xff0c;\u6bcf\u4e00\u4e2a\u8fdb\u884c\u6570\u636e\u901a\u4fe1\u7684\u5957\u63a5\u5b57(\u4e5f\u5c31\u662f\u901a\u8fc7accept\u83b7\u53d6\u5230\u7684\u65b0\u8fde\u63a5)\u90fd\u4f1a\u901a\u8fc7Connection\u8fdb\u884c\u7ba1\u7406\u3002 \u4e3b\u8981\u7684\u5904\u7406\u6d41\u7a0b&#xff1a; accept\u83b7\u53d6\u5230\u65b0\u8fde\u63a5\u540e\u5c31\u901a\u8fc7Connection\u8fdb\u884c\u7ba1\u7406&#xff0c;\u5728Connection\u521b\u5efa\u4e4b\u5904&#xff0c;\u8be5\u5957\u63a5\u5b57\u5bf9\u5e94channel\u76845\u4e2a\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570\u5c31\u5df2\u7ecf\u88ab\u8bbe\u7f6e\u8fdb\u53bb\u3002\u7136\u540e\u542f\u52a8\u975e\u6d3b\u8dc3\u8d85\u65f6\u8fde\u63a5\u9500\u6bc1\u4efb\u52a1\u3002\u6700\u540e\u901a\u8fc7eventloop\u4e2d\u7684poller\u542f\u52a8\u8be5\u8fde\u63a5\u7684\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u3002 \u4e00\u65e6\u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e&#xff0c;\u5c31\u4f1a\u89e6\u53d1\u8bfb\u4e8b\u4ef6\u5c31\u7eea&#xff0c;\u5c31\u4f1a\u6267\u884c\u8bfb\u4e8b\u4ef6\u7684\u56de\u8c03\u51fd\u6570&#xff0c;\u8bfb\u56de\u8c03\u7684\u4e3b\u8981\u5de5\u4f5c\u5c31\u662f\u4eceSocket\u4e2d\u8bfb\u53d6\u5230\u5bf9\u7aef\u53d1\u9001\u7684\u6570\u636e&#xff0c;\u5e76\u653e\u5165\u7528\u6237\u6001\u7684\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u3002 \u6700\u540e\u8c03\u7528\u7528\u6237\u4f20\u5165\u8fdb\u884c\u7684\u4e1a\u52a1\u5904\u7406\u51fd\u6570&#xff0c;\u5bf9\u6570\u636e\u8fdb\u884c\u5904\u7406\u3002 \u5728\u4e1a\u52a1\u5904\u7406\u51fd\u6570\u4e2d\u5f53\u6570\u636e\u88ab\u5904\u7406\u5b8c\u540e&#xff0c;\u5c31\u4f1a\u8c03\u7528Connection\u7ed9\u7528\u6237\u63d0\u4f9b\u7684Send\u53d1\u9001\u63a5\u53e3&#xff0c;\u5c06\u6570\u636e\u653e\u5165\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d&#xff0c;\u7136\u540e\u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u3002 \u8bfb\u4e8b\u4ef6\u4e00\u65e6\u5c31\u7eea&#xff0c;\u5c31\u4f1a\u5c06\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u901a\u8fc7Socket\u53d1\u9001\u51fa\u53bb\u3002<\/p>\n<h2>\u4e8c.\u6210\u5458\u53d8\u91cf<\/h2>\n<p>   <span class=\"token comment\">\/\/ \u4e00.\u6210\u5458\u53d8\u91cf<\/span><br \/>\n<span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token keyword\">uint64_t<\/span> _conn_id<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ 1.\u8fde\u63a5\u7684\u552f\u4e00\u6807\u8bc6&#xff0c;\u7528\u6765\u7ba1\u7406\u548c\u67e5\u627e\u8fde\u63a5<\/span><br \/>\n    <span class=\"token comment\">\/\/ uint64_t _timer_id&#xff1b;\u5b9a\u65f6\u5668\u7684\u552f\u4e00id&#xff0c;\u8fd9\u91cc\u7b80\u5355\u4f7f\u7528\u8fde\u63a5\u7684id\u6765\u4ee3\u66ff<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _sockfd<span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ 2.\u8fde\u63a5\u5173\u8054\u7684\u63cf\u8ff0\u7b26<\/span><br \/>\n    Socket _socket<span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ 3.\u5bf9\u5957\u63a5\u5b57\u7684\u64cd\u4f5c\u7ba1\u7406<\/span><br \/>\n    Channel _channel<span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ 4.\u5bf9\u8fde\u63a5\u7684\u4e8b\u4ef6\u7ba1\u7406<\/span><br \/>\n    ConnStatus _status<span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ 5.\u8fde\u63a5\u7684\u72b6\u6001<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span>_loop<span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ 6.\u8fde\u63a5\u6240\u5173\u8054\u7684\u4e00\u4e2aloop<\/span><br \/>\n    Buffer _in_buffer<span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ 7.\u8f93\u5165\u7f13\u51b2\u533a&#xff0c;\u5b58\u653e\u7684\u662f\u4ecesocket\u4e2d\u8bfb\u53d6\u5230\u7684\u6570\u636e<\/span><br \/>\n    Buffer _out_buffer<span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ 8.\u8f93\u51fa\u7f13\u51b2\u533a&#xff0c;\u5b58\u653e\u7684\u662f\u8981\u53d1\u9001\u7ed9\u5bf9\u7aef\u7684\u6570\u636e<\/span><br \/>\n    Any _context<span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ 9.\u8fde\u63a5\u7684\u4e0a\u4e0b\u6587<\/span><br \/>\n    <span class=\"token keyword\">bool<\/span> _inactive_release<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ 10.\u7528\u6765\u662f\u5426\u542f\u52a8\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1\u7684\u6807\u5fd7\u4f4d&#xff0c;\u9ed8\u8ba4\u662f\u5173\u95ed\u7684false&#xff1b;<\/span><br \/>\n    <span class=\"token comment\">\/\/ 5\u4e2a\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> ConnectedCallback <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span>function<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">void<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> PtrConnection <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> MessageCallback <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span>function<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">void<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> PtrConnection <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">,<\/span> Buffer <span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> ClosedCallback <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span>function<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">void<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> PtrConnection <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> AnyEventCallback <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span>function<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">void<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> PtrConnection <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    ConnectedCallback _connected_callback<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ 11.\u5f53\u8fde\u63a5\u5b8c\u5168\u5efa\u7acb\u6210\u529f\u65f6\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570&#xff0c;\u5728Established()\u4e2d\u4f1a\u6267\u884c<\/span><br \/>\n    MessageCallback _message_callback<span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ 12.\u5f53\u8f93\u5165\u7f13\u51b2\u533a\u4e2d\u5b58\u5728\u6570\u636e\u65f6\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570&#xff0c;\u5728HandleRead()\u4e2d\u4f1a\u6267\u884c<\/span><br \/>\n    ClosedCallback _closed_callback<span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ 13.\u5f53\u8fde\u63a5\u5173\u95ed\u65f6\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570&#xff0c;\u5728Release()\u4e2d\u4f1a\u6267\u884c<\/span><br \/>\n    AnyEventCallback _anyevent_callback<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ 14.\u5f53\u8fde\u63a5\u4efb\u610f\u4e8b\u4ef6\u65f6\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    ClosedCallback _svr_closed_callback<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ 15.\u5f53\u670d\u52a1\u5668\u8981\u5173\u95ed\u8fde\u63a5\u65f6\u8981\u6267\u884c\u7684\u56de\u8c03\u51fd\u6570<\/span><\/p>\n<h3>1.\u8fde\u63a5\u552f\u4e00ID(\u8fde\u63a5\u7ba1\u7406)<\/h3>\n<p>\u8fd9\u4e2aID&#xff0c;\u7528\u4e8e\u8fde\u63a5\u7684\u7ba1\u7406\u548c\u67e5\u627e&#xff0c;\u6bcf\u4e00\u4e2a\u8fde\u63a5\u90fd\u6709\u552f\u4e00\u7684ID\u3002 \u8fd8\u8981\u6ce8\u610f\u8fde\u63a5\u8981\u9700\u8981\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u7684id&#xff0c;\u8fd9\u4e2a\u5b9a\u65f6\u5668id&#xff0c;\u5c31\u662f\u8bf4\u6211\u4eec\u5982\u679c\u8981\u542f\u52a8\u4e00\u4e2a\u975e\u6d3b\u8dc3\u8fde\u63a5\u7684\u9500\u6bc1\u4efb\u52a1\u3002\u90a3\u4e48&#xff0c;\u5f53\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1\u65f6\u4f60\u5c31\u5f97\u7ed9\u6211\u4e00\u4e2a\u6307\u5b9a\u7684\u5b9a\u65f6\u4efb\u52a1\u7684id\u3002\u548c\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\u3002\u6240\u4ee5\u6211\u6dfb\u52a0\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u91cc\u8fb9\u5fc5\u987b\u5f97\u8bbe\u7f6e\u4e00\u4e2atimerid\u3002<\/p>\n<p>\u56e0\u4e3a\u5f53\u4e00\u4e2a\u8fde\u63a5&#xff0c;\u6709\u4e8b\u4ef6\u89e6\u53d1\u4e86&#xff0c;\u5b83\u5c31\u8981\u53bb\u5237\u65b0\u8fd9\u4e2a\u8fde\u63a5\u7684\u6d3b\u8dc3\u5ea6\u3002\u5237\u65b0\u8fde\u63a5\u7684\u6d3b\u8dc3\u5ea6\u5c31\u662f\u8981\u5ef6\u8fdf\u8fd9\u4e2a\u8fde\u63a5\u7684\u4e00\u4e2a\u5b9a\u65f6\u9500\u6bc1\u4efb\u52a1\u7684\u6267\u884c&#xff0c; \u6240\u4ee5\u5462&#xff0c;\u5ef6\u8fdf\u5b9a\u65f6\u4efb\u52a1\u9996\u5148\u662f\u9700\u8981\u627e\u5230\u8be5\u5b9a\u65f6\u4efb\u52a1\u7684&#xff0c;\u600e\u4e48\u627e\u5462&#xff1f;\u6839\u636e\u5b9a\u65f6\u4efb\u52a1\u7684id\u5728\u54c8\u5e0c\u8868\u4e2d\u627e&#xff0c;\u6240\u4ee5\u5462\u8fd9\u4e2a\u5b9a\u65f6id\u5b83\u4e5f\u662f\u5fc5\u987b\u662f\u552f\u4e00\u7684\u3002 \u8fd9\u91cc\u76f4\u63a5\u7528connid\u6765\u8868\u793a\u5b9a\u65f6\u5668\u7684id\u4e86&#xff0c;\u540e\u9762\u64cd\u4f5c\u90fd\u4f1a\u53d8\u5f97\u7279\u522b\u7684\u65b9\u4fbf\u3002<\/p>\n<h3>2.Socket\u5bf9\u8c61(\u5957\u63a5\u5b57\u64cd\u4f5c\u7ba1\u7406)<\/h3>\n<p>Socket\u5bf9\u8c61\u662f\u5bf9\u5957\u4ef6\u5b57\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\u3002\u4ecesocket\u4e2d\u8bfb\u53d6\u6570\u636e&#xff0c;\u4ecesocket\u4e2d\u53d1\u9001\u6570\u636e\u7b49\u64cd\u4f5c\u3002<\/p>\n<h3>3.Channel\u5bf9\u8c61(\u8fde\u63a5\u4e8b\u4ef6\u7ba1\u7406)<\/h3>\n<p>\u90a3\u4ec0\u4e48\u65f6\u5019\u5bf9socket\u64cd\u4f5c\u5462&#xff1f;\u90a3\u80af\u5b9a\u662f\u67d0\u79cd\u4e8b\u4ef6\u5c31\u7eea\u4e86&#xff0c;\u53ef\u8bfb\u4e8b\u4ef6\u5c31\u7eea\u5c31\u53bb\u5bf9\u5957\u63a5\u5b57\u8fdb\u884c\u8bfb\u53d6\u64cd\u4f5c \u5199\u4e8b\u4ef6\u5c31\u7eea\u4e86\u5c31\u5bf9\u5957\u63a5\u5b57\u8fdb\u884c\u4e00\u4e2a\u5199\u5165\u6570\u636e\u64cd\u4f5c\u3002\u6240\u4ee5\u5462\u8fd8\u9700\u8981\u4e00\u4e2achannel\u5bf9\u8c61\u6765\u5bf9\u5404\u79cd\u4e8b\u4ef6\u8fdb\u884c\u7ba1\u7406\u3002<\/p>\n<h3>4.Buffer\u5bf9\u8c61(\u7f13\u51b2\u533a\u7ba1\u7406)<\/h3>\n<p>\u8fde\u63a5\u5171\u6709\u4e24\u4e2a\u7528\u6237\u6001\u7684\u7f13\u51b2\u533a&#xff0c;\u4e00\u4e2a\u662f\u63a5\u53d7\u7f13\u51b2\u533ain_buffer&#xff0c;\u4e00\u4e2a\u662f\u53d1\u9001\u7f13\u51b2\u533aout_buffer\u3002 \u8f93\u5165\u7f13\u51b2\u533a\u4e2d\u5b58\u50a8\u7684\u4ecesocket\u8bfb\u53d6\u5230\u7684\u6570\u636e\u3002 \u8f93\u51fa\u7f13\u51b2\u533a\u4e2d\u5b58\u50a8\u7684\u662f\u670d\u52a1\u5668\u5904\u7406\u5b8c\u8981\u53d1\u9001\u7ed9\u5bf9\u7aef\u7684\u6570\u636e\u3002<\/p>\n<p>\u8f93\u5165\u7f13\u51b2\u5b58\u653e\u6211\u4eec\u7684\u662f\u4ecesocket\u4e2d\u8bfb\u53d6\u5230\u7684\u6570\u636e&#xff0c;socket\u6b63\u5e38\u4f1a\u76f4\u63a5\u628a\u8bfb\u53d6\u5230\u7684\u6570\u636e\u653e\u5230\u6211\u4eec\u7684\u5185\u6838\u7f13\u51b2\u533a\u91cc\u9762\u6765&#xff0c;\u7136\u540e\u8ba9\u7528\u6237\u53bb\u8fdb\u884c\u4e00\u4e2a\u5904\u7406&#xff0c;\u4f46\u662f\u5904\u7406\u7684\u65f6\u5019\u5462&#xff0c;\u4f1a\u51fa\u73b0\u8fd9\u4e2a\u6570\u636e\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u6570\u636e&#xff0c;\u5982\u679c\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u6570\u636e&#xff0c;\u6211\u5c31\u5148\u4e0d\u5904\u7406&#xff0c;\u5c31\u653e\u5165\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u5b58\u7740\u3002 \u6848\u4f8b&#xff1a;\u5047\u8bbe\u6709\u4e00\u4e2a\u5ba2\u6237\u7aef\u7ed9\u6211\u4eec\u53d1\u9001\u4e86\u4e00\u4e2a\u8bf7\u6c42\u3002\u8fd9\u4e2a\u8bf7\u6c42\u8d85\u8fc7\u4e86\u5185\u6838\u63a5\u6536\u7f13\u51b2\u533a\u5927\u5c0f\u3002 \u5982\u679c\u7528\u6237\u4e0d\u628asocket\u63a5\u6536\u7f13\u51b2\u7684\u6570\u636e\u90fd\u8bfb\u51fa\u6765&#xff0c;\u90a3socket\u5c31\u65e0\u6cd5\u518d\u7ee7\u7eed\u63a5\u6536\u65b0\u7684\u6570\u636e\u4e86&#xff0c;\u4f46\u5982\u679c\u8bfb\u53d6\u51fa\u6765&#xff0c;\u4e5f\u4e0d\u662f\u5b8c\u6574\u7684\u6570\u636e&#xff0c;\u90a3\u4f60\u8fd9\u4e2a\u8bf7\u6c42\u6c38\u8fdc\u90fd\u4e0d\u53ef\u80fd\u5b8c\u6574\u3002 \u6240\u4ee5\u6211\u4eec\u8981\u628asocket\u63a5\u6536\u5230\u7684\u6570\u636e\u5462&#xff0c;\u5168\u90e8\u8981\u62ff\u51fa\u6765\u653e\u5230\u6211\u4eec\u7684\u7f13\u51b2\u533a\u91cc\u8fb9\u7f13\u5b58\u8d77\u6765\u3002<\/p>\n<hr \/>\n<p>\u670d\u52a1\u5668\u5904\u7406\u5b8c\u6570\u636e\u540e&#xff0c;\u5c31\u8981\u5c06\u54cd\u5e94\u53d1\u9001\u51fa\u53bb&#xff0c;\u53d1\u9001\u6570\u636e\u7684\u65f6\u5019\u5e76\u4e0d\u662f\u76f4\u63a5\u6765\u901a\u8fc7sock\u8fdb\u884c\u53d1\u9001\u800c\u662f\u5148\u628a\u6570\u636e\u653e\u5230\u7528\u6237\u6001\u53d1\u9001\u7f13\u51b2\u533a&#xff0c;\u7b49\u5230\u6211\u4eec\u7684socket\u63cf\u8ff0\u7b26\u4e8b\u4ef6\u53ef\u5199\u4e86\u7136\u540e\u518d\u53bb\u5199\u5165&#xff0c;\u5426\u5219\u7684\u8bdd&#xff0c;\u5982\u679c\u4f60\u76f4\u63a5\u8fdb\u884c\u6570\u636e\u53d1\u9001\u5c31\u4f1a\u5bfc\u81f4\u4e00\u4e2a\u60c5\u51b5\u90a3\u5c31\u662f\u5982\u679c\u53d1\u9001\u7f13\u51b2\u533asocket\u7684\u5185\u6838\u53d1\u9001\u7f13\u51b2\u533a\u91cc\u9762\u6570\u636e\u5df2\u7ecf\u6ee1\u4e86\u3002\u90a3\u4f60\u6570\u636e\u653e\u4e0d\u8fdb\u53bb\u4e86&#xff0c;\u4f60\u53d1\u9001\u662f\u4e0d\u662f\u5c31\u4f1a\u963b\u585e\u5728\u8fd9\u91cc\u8fb9\u5462&#xff1f;\u90a3\u4f60\u90a3\u4e48\u963b\u585e\u7684\u8bdd&#xff0c;\u7a0b\u5e8f\u5c31\u5361\u5728\u8fd9\u4e86\u3002 \u4ed6\u5c31\u5fc5\u987b\u6709\u4e00\u4e2a\u8f93\u5165\u7f13\u51b2\u533a\u628a\u4f60\u7684\u6570\u636e\u4f60\u5148\u653e\u5230\u8fd9\u4e2a\u7f13\u51b2\u533a\u91cc\u9762\u6765\u7b49\u5230\u53ef\u5199\u4e8b\u4ef6\u89e6\u53d1\u4e86\u80fd\u5199\u4e86\u518d\u53bb\u5199\u8fd9\u4e48\u4e00\u4e2a\u529f\u80fd<\/p>\n<h3>5.ConnStatus\u5bf9\u8c61(\u8fde\u63a5\u72b6\u6001\u7ba1\u7406)<\/h3>\n<p>\u5b58\u5728\u4e00\u4e2a\u95ee\u9898&#xff0c;\u4e00\u4e2a\u8fde\u63a5\u5982\u679c\u6211\u73b0\u5728\u8981\u53bb\u5173\u95ed&#xff0c;\u90a3\u6211\u5e94\u8be5\u76f4\u63a5\u5173\u95ed\u8fde\u63a5\u5417&#xff1f; \u4e0d\u662f\u7684&#xff01; \u5e94\u8be5\u662f\u5728\u8fde\u63a5&#xff0c;\u63a5\u53d7\u7f13\u51b2\u533a\u6ca1\u6709\u6570\u636e\u53ef\u5904\u7406\u4e86&#xff0c;\u53d1\u9001\u7f13\u51b2\u533a\u91cc\u8fb9\u4e5f\u6ca1\u6709\u6570\u636e\u518d\u53d1\u9001\u4e86\u8fd9\u65f6\u5019\u624d\u5e94\u8be5\u53bb\u5173\u95ed\u8fde\u63a5\u3002 \u6240\u4ee5\u8fd9\u65f6\u5019\u5462&#xff1f;\u5c31\u5e94\u8be5\u6709\u4e00\u4e2a\u72b6\u6001\u3002\u5b83\u6807\u8bb0\u8fde\u63a5\u5f53\u524d\u5b83\u662f\u5426\u5904\u4e8e\u4e00\u4e2a\u6b63\u5e38\u7684\u901a\u4fe1\u72b6\u6001\u6216\u8005\u4e00\u4e2a\u5f85\u5173\u95ed\u72b6\u6001\u6216\u8005\u4e00\u4e2a\u5173\u95ed\u72b6\u6001\u3002<\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">enum<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    DISCONNECTED<span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ \u8fde\u63a5\u5df2\u7ecf\u5173\u95ed\u4e86\u7684\u72b6\u6001<\/span><br \/>\n    CONNECTING<span class=\"token punctuation\">,<\/span>   <span class=\"token comment\">\/\/ \u8fde\u63a5\u521b\u5efa\u51fa\u6765&#xff0c;\u4f46\u5404\u79cd\u5c5e\u6027\u8fd8\u6ca1\u6709\u8bbe\u7f6e\u7684\u72b6\u6001&#xff0c;\u5f85\u5904\u7406\u72b6\u6001<\/span><br \/>\n    CONNECTED<span class=\"token punctuation\">,<\/span>    <span class=\"token comment\">\/\/ \u8fde\u63a5\u5b8c\u5168\u521b\u5efa\u6210\u529f&#xff0c;\u53ef\u4ee5\u901a\u4fe1\u7684\u72b6\u6001<\/span><br \/>\n    DISCONNECTING <span class=\"token comment\">\/\/ \u5f85\u5173\u95ed\u72b6\u6001<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> ConnStatus<span class=\"token punctuation\">;<\/span><\/p>\n<h3>6.EventLoop\u5bf9\u8c61(\u8fde\u63a5\u76d1\u63a7\/\u5b9a\u65f6\u4efb\u52a1\u7ba1\u7406)<\/h3>\n<p>connection\u63d0\u4f9b\u7684\u64cd\u4f5c&#xff0c;\u5176\u5b9e\u90fd\u662f\u7ed9\u7ec4\u4ef6\u4f7f\u7528\u8005\u6240\u63d0\u4f9b\u7684\u4e00\u4e2a\u63a5\u53e3&#xff0c;\u800c\u8fd9\u4e9b\u63a5\u53e3\u5462 \u5728\u8fdb\u884c\u4f7f\u7528\u7684\u65f6\u5019&#xff0c;\u5e76\u4e0d\u80fd\u8ba9\u7528\u6237\u76f4\u63a5\u53bb\u8fdb\u884c\u64cd\u4f5c&#xff0c;\u56e0\u4e3a&#xff0c;\u8981\u89e3\u51b3\u7ebf\u7a0b\u5b89\u5168\u7684\u4e00\u4e2a\u95ee\u9898\u3002 \u6240\u4ee5\u6211\u4eec\u5c31\u5fc5\u987b\u628a\u5bf9\u8fde\u63a5\u7684\u6240\u6709\u7684\u64cd\u4f5c\u90fd\u653e\u5230\u6211\u4eec\u7684\u4e00\u4e2aeventloop\u7ebf\u7a0b\u91cc\u8fb9\u53bb\u6267\u884c\u3002\u6240\u4ee5\u5c06connection\u5462\u7ed1\u5b9a\u5230\u56fa\u5b9a\u7684\u4e00\u4e2aeventloop\u7ebf\u7a0b\u4e0a\u53bb\u3002 \u90a3\u4e48\u5c31\u76f8\u5f53\u4e8e\u5728\u521b\u5efa\u4e00\u4e2a\u8fde\u63a5\u4e4b\u540e\u5462&#xff0c;\u5c31\u7ed9\u5b83\u5206\u914d\u4e86\u4e00\u4e2aloop\u90a3\u4e48&#xff0c;\u8fd9\u4e2a\u8fde\u63a5\u5c31\u6c38\u8fdc\u5de5\u4f5c\u5728\u5b83\u4e0a\u8fb9\u3002 eventloop\u4e2d\u7684poller\u6a21\u5757\u7528\u4e8e\u5bf9\u901a\u4fe1\u5957\u63a5\u5b57\u8fdb\u884c\u76d1\u542c\u3002 eventloop\u4e2d\u7684timerwheel\u6a21\u5757\u7528\u4e8e\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1\u3002<\/p>\n<h3>7.Any\u5bf9\u8c61(\u4e0a\u4e0b\u6587\u7ba1\u7406)<\/h3>\n<h3>8.\u662f\u5426\u542f\u52a8\u975e\u6d3b\u8dc3\u8d85\u65f6\u8fde\u63a5\u9500\u6bc1\u6807\u5fd7\u4f4d<\/h3>\n<p>\u5982\u679c\u8981\u542f\u52a8\u6216\u8005\u53d6\u6d88\u975e\u6d3b\u8dc3\u8fde\u63a5\u7684\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1,\u4e48\u6240\u4ee5\u4ed6\u5fc5\u987b\u5f97\u6709\u4e00\u4e2a\u6807\u5fd7\u4f4d\u80fd\u591f\u53bb\u63a7\u5236\u542f\u52a8\u53d6\u6d88&#xff0c;\u9ed8\u8ba4\u662f\u53d6\u6d88\u3002<\/p>\n<h3>9.5\u4e2a\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/h3>\n<p>\u8fd95\u4e2a\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u5176\u5b9e\u5b83\u5c31\u662f\u8fde\u63a5\u5728\u4e0d\u540c\u7684\u9636\u6bb5\u5e94\u8be5\u5e72\u7684\u4e8b \u60c5&#xff0c;\u800c\u4e0d\u662f\u67d0\u79cd\u4e8b\u4ef6\u89e6\u53d1&#xff0c;\u5b83\u6240\u5e72\u7684\u4e8b\u60c5\u3002\u4e00\u5b9a\u8981\u628a\u8fd9\u4e2a\u8981\u533a\u5206\u5f00\u4e86\u3002<\/p>\n<p>\u4e8b\u4ef6\u89e6\u53d1\u6307\u662f\u89e6\u53d1\u4e86\u53ef\u8bfb\u4e8b\u4ef6\u628a\u6570\u636e\u8bfb\u53d6\u51fa\u6765\u653e\u5230\u63a5\u6536\u7f13\u51b2\u533a&#xff0c;\u4f46\u662f\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u662f\u4ec0\u4e48\u5462&#xff1f;\u662f\u63a5\u6536\u5230\u6570\u636e\u653e\u5230\u63a5\u6536\u7f13\u51b2\u533a\u4e4b\u540e&#xff0c;\u90a3\u4e48\u5904\u4e8e\u8fd9\u4e2a\u9636\u6bb5\u7684\u65f6\u5019&#xff0c;\u6211\u5e94\u8be5\u8c03\u7528\u4eba\u5bb6\u7684\u4e1a\u52a1\u5904\u7406\u51fd\u6570\u662f\u4e0d\u662f\u6765\u8fdb\u884c\u5e94\u7528\u5904\u7406&#xff0c;\u5b83\u662f\u4e00\u4e2a\u67d0\u4e2a\u9636\u6bb5\u7684\u5904\u7406\u51fd\u6570\u3002 \u8fd9\u4e2a\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u5b83\u662f\u63d0\u4f9b\u7ed9\u5916\u754c\u6765\u8fdb\u884c\u5bf9\u8fde\u63a5\u7684\u67d0\u79cd\u64cd\u4f5c\u7684&#xff0c;\u6240\u4ee5\u5462&#xff0c;\u5bf9\u5916\u7684\u64cd\u4f5c\u90fd\u4f7f\u7528\u667a\u80fd\u6307\u9488\u6240\u7ba1\u7406\u7684\u5bf9\u8c61\u6765\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<h2>\u4e09.\u6210\u5458\u51fd\u6570<\/h2>\n<h3>1.\u79c1\u6709\u6210\u5458\u51fd\u6570(\u4e3a\u5185\u90e8\u63d0\u4f9b\u7684\u63a5\u53e3)<\/h3>\n<h4>1.1\u5bf9\u8fde\u63a5\u7684\u64cd\u4f5c\u8981\u90fd\u653e\u5165\u5bf9\u5e94\u7684\u7ebf\u7a0b\u4e2d\u8fd0\u884c<\/h4>\n<p>\u7ed9\u7528\u6237\u63d0\u4f9b\u4e00\u4e2a\u53d1\u9001\u6570\u636e\u7684\u64cd\u4f5c&#xff0c;\u5176\u5b9e\u5e76\u4e0d\u662f\u76f4\u63a5\u53bb\u53d1\u9001\u4e00\u4e2a\u6570\u636e&#xff0c;\u800c\u662f\u8981\u5148\u653e\u5165\u5bf9\u5e94\u7684\u4efb\u52a1\u961f\u5217\u4e2d&#xff0c;\u5728\u7ebf\u7a0b\u91cc\u8fb9\u6267\u884c\u3002 \u5173\u95ed\u8fde\u63a5\u90a3\u4e5f\u5e76\u4e0d\u662f\u76f4\u63a5\u53bb\u5173\u95ed&#xff0c;\u800c\u662f\u662f\u653e\u5230\u6211\u4eec\u7684\u4e00\u4e2a\u7ebf\u7a0b\u5f53\u4e2d\u518d\u53bb\u8fdb\u884c\u6267\u884c\u5173\u95ed\u3002\u6240\u4ee5\u8fd9\u4e9b\u63a5\u53e3&#xff0c;\u5176\u5b9e\u5185\u90e8\u5b83\u4eec\u90fd\u8981\u53bb\u8c03\u7528\u6211\u4eec\u7684\u4e00\u4e2aloop\u7684\u4e00\u4e2aruninloop&#xff0c;\u5c06\u5b83\u4eec\u52a0\u5165\u5230\u6211\u4eec\u7684\u4e00\u4e2a\u4efb\u52a1\u961f\u5217\u5f53\u4e2d\u53bb\u3002 \u5bf9\u4e8e\u8fde\u63a5\u7684\u64cd\u4f5c\u64cd\u4f5c\u5462&#xff0c;\u653e\u5230\u6211\u4eec\u7684\u4e00\u4e2aloop\u7ebf\u7a0b\u91cc\u8fb9\u53bb\u8fdb\u884c<\/p>\n<h5>EnableInactiveReleaseInLoop()<\/h5>\n<p>\u771f\u6b63\u6267\u884c\u542f\u52a8\u975e\u6d3b\u8dc3\u8d85\u65f6\u8fde\u63a5\u9500\u6bc1\u7684\u64cd\u4f5c\u3002 \u9996\u5148\u5c06\u6807\u5fd7\u4f4d\u8bbe\u7f6e\u4e3atrue&#xff0c;\u8868\u660e\u542f\u52a8\u3002 \u7136\u540e\u5224\u65ad\u65f6\u95f4\u8f6e\u5b9a\u65f6\u5668\u4e2d\u662f\u5426\u5b58\u5728\u8be5\u4efb\u52a1&#xff0c;\u5982\u679c\u5df2\u7ecf\u5b58\u5728&#xff0c;\u90a3\u4e48\u518d\u542f\u52a8\u5c31\u662f\u5237\u65b0\u8be5\u4efb\u52a1&#xff0c;\u5982\u679c\u4e0d\u5b58\u5728\u5c31\u6dfb\u52a0\u4e00\u4e2a\u5b9a\u65f6\u5668\u3002 \u7ed1\u5b9a\u7684\u9500\u6bc1\u4efb\u52a1\u5c31\u662fRelease\u51fd\u6570<\/p>\n<p> <span class=\"token comment\">\/\/ 3.\u771f\u6b63\u7684\u542f\u52a8\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">EnableInactiveReleaseInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> sec<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2460\u8bbe\u7f6e\u6807\u5fd7\u4f4d\u4e3atrue \u2461\u5224\u65ad\u662f\u5426\u5b58\u5728\u4efb\u52a1&#xff0c;\u5982\u679c\u5b58\u5728\u4efb\u52a1\u5219\u5237\u65b0\u5ef6\u8fdf\u4e00\u4e0b&#xff0c;\u5982\u679c\u4e0d\u5b58\u5728\u5219\u6dfb\u52a0\u4efb\u52a1<\/span><br \/>\n        _inactive_release <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">HasTaskE<\/span><span class=\"token punctuation\">(<\/span>_conn_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">\/\/ \u5b58\u5728\u4e86\u5c31\u76f4\u63a5\u5237\u65b0\u5ef6\u8fdf\u4e00\u4e0b<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RefreshTaskE<\/span><span class=\"token punctuation\">(<\/span>_conn_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u4e0d\u5b58\u5728\u5c31\u6dfb\u52a0<\/span><br \/>\n        _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">AddTaskE<\/span><span class=\"token punctuation\">(<\/span>_conn_id<span class=\"token punctuation\">,<\/span> sec<span class=\"token punctuation\">,<\/span> std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>Release<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>CancelInactiveReleaseInLoop()<\/h5>\n<p>\u771f\u6b63\u7684\u53d6\u6d88\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1\u7684\u64cd\u4f5c\u3002 \u9996\u5148\u5c06\u6807\u51c6\u4f4d\u8bbe\u7f6e\u4e3afasle&#xff0c;\u8868\u793a\u53d6\u6d88\u3002 \u5224\u65ad\u8be5\u4efb\u52a1\u662f\u5426\u5b58\u5728&#xff0c;\u5982\u679c\u5b58\u5728\u5c31\u53d6\u6d88\u8be5\u4efb\u52a1\u3002 \u6700\u7ec8\u4e5f\u662f\u6839\u636e\u4efb\u52a1\u5bf9\u8c61\u4e2d\u7684\u6807\u5fd7\u4f4d\u6765\u51b3\u5b9a&#xff0c;\u662f\u5426\u6267\u884c\u9500\u6bc1\u4efb\u52a1\u3002<\/p>\n<p><span class=\"token comment\">\/\/ 4.\u771f\u6b63\u7684\u53d6\u6d88\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">CancelInactiveReleaseInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        _inactive_release <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">HasTaskE<\/span><span class=\"token punctuation\">(<\/span>_conn_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">CancelTaskE<\/span><span class=\"token punctuation\">(<\/span>_conn_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5f53\u53d6\u6d88\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1\u65f6&#xff0c;canceled\u5c31\u4f1a\u8bbe\u7f6e\u4e3atrue\u3002\u5c31\u4e0d\u4f1a\u6267\u884c\u9500\u6bc1\u4efb\u52a1\u3002<\/p>\n<p> <span class=\"token comment\">\/\/ \u6790\u6784&#xff0c;\u5f53\u5bf9\u8c61\u91ca\u653e\u65f6\u6267\u884c\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u5e76\u4e14\u4ecetimerwheel\u4e2d\u79fb\u9664\u8be5\u5b9a\u65f6\u4efb\u52a1\u7684\u4fe1\u606f<\/span><br \/>\n    <span class=\"token operator\">~<\/span><span class=\"token function\">TimerTask<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>_canceled<span class=\"token punctuation\">)<\/span><span class=\"token comment\">\/\/\u5f53\u5916\u754c\u53d6\u6d88\u4e86\u5b9a\u65f6\u4efb\u52a1&#xff0c;cancel\u7684\u503c\u5c31\u4f1a\u88ab\u8bbe\u7f6e\u4e3atrue&#xff0c;cancel\u4e3atrue\u65f6\u5c31\u4e0d\u53bb\u6267\u884c\u9500\u6bc1\u4efb\u52a1<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token function\">_task_cb<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5b9a\u65f6\u4efb\u52a1\u9500\u6bc1\u540e&#xff0c;\u5c31\u4f1a\u5c06\u5bf9\u5e94\u7684\u4fe1\u606f\u4ece\u65f6\u95f4\u8f6e\u4e2d\u53bb\u9664<\/span><br \/>\n        <span class=\"token function\">_release_cb<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>EstablishedInLoop()<\/h5>\n<p>\u8fd9\u4e2a\u63a5\u53e3\u662f\u4e13\u95e8\u5411\u5916\u63d0\u4f9b\u7684\u4e00\u4e2a\u7528\u4e8e\u8fde\u63a5\u5efa\u7acb\u5b8c\u6210\u4e4b\u540e\u7684\u72b6\u6001&#xff0c;\u90a3\u4e48\u6240\u505a\u7684\u4e00\u4e2a\u5904\u7406 \u6bd4\u5982\u8fde\u63a5\u83b7\u53d6\u4e4b\u540e&#xff0c;\u6240\u5904\u7684\u72b6\u6001\u4e0b\u8981\u8fdb\u884c\u5404\u79cd\u8bbe\u7f6e&#xff0c;channel\u8981\u8bbe\u7f6e\u5b83\u7684\u51e0\u79cd\u4e8b\u4ef6\u56de\u8c03&#xff0c;\u4ee5\u53ca\u542f\u52a8\u8bfb\u76d1\u63a7\u3002\u7136\u540e\u5462\u8c03\u7528\u6211\u4eec\u7684\u4e00\u4e2a\u8fde\u63a5\u5b8c\u6210\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u90fd\u5c31\u90fd\u5728\u8fd9\u4e2a\u63a5\u53e3\u91cc\u8fb9\u3002<\/p>\n<p>\u5c31\u662f\u4e00\u4e2a\u8fde\u63a5\u4e00\u65e6\u5df2\u7ecf\u521b\u5efa\u51fa\u6765\u4e86&#xff0c;\u90a3\u6211\u63a5\u4e0b\u6765\u8981\u5e72\u4ec0\u4e48\u5462&#xff1f; \u5c31\u8981\u8bbe\u7f6echannel\u7684\u5404\u4e2a\u56de\u8c03\u51fd\u6570&#xff0c;\u7136\u540e\u628a\u5b83\u6dfb\u52a0\u5230\u6211\u4eec\u7684\u53ef\u8bfb\u76d1\u63a7\u91cc\u9762\u53bb\u5f00\u59cb\u76d1\u542c&#xff0c;\u4ee5\u53ca\u8c03\u7528\u5efa\u7acb\u6210\u529f\u9636\u6bb5\u7684\u56de\u8c03\u51fd\u6570\u3002<\/p>\n<p>\u5f53\u524d\u7684\u72b6\u6001\u5fc5\u987b\u662f\u4e0a\u5c42\u7684\u534a\u8fde\u63a5\u72b6\u6001CONNECTING&#xff0c;\u4e5f\u5c31\u662f\u8fde\u63a5\u8fd8\u6ca1\u6709\u5b8c\u5168\u7684\u8bbe\u7f6e\u5b8c\u6bd5&#xff0c;\u8fde\u63a5\u7684\u5404\u79cd\u64cd\u4f5c\u8fd8\u5e76\u6ca1\u6709\u5b8c\u5168&#xff0c;\u5728\u6784\u9020\u51fd\u6570\u91cc\u8fb9\u6211\u4eec\u5230\u65f6\u5019\u4f1a\u7ed9\u4ed6\u53bb\u90a3\u4e48\u8fdb\u884c\u5404\u79cd\u6784\u9020&#xff0c;\u8bbe\u7f6echannel\u7684\u56de\u8c03\u51fd\u6570\u3002\u53ea\u6709\u5728\u5b8c\u6210\u8c03\u7528\u8be5\u63a5\u53e3\u4e4b\u540e&#xff0c;\u90a3\u4e48\u5b83\u624d\u7b97\u662f\u8fde\u63a5\u771f\u6b63\u5b8c\u6210\u3002<\/p>\n<p>\u56e0\u4e3a\u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u8fd9\u4e00\u6b65\u662f\u4e0d\u80fd\u653e\u5230\u6784\u9020\u51fd\u6570\u91cc\u9762\u5b8c\u6210\u7684&#xff0c;\u56e0\u4e3a\u5b58\u5728\u4e00\u5f00\u59cb\u5c31\u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u4e86\u4e4b\u540e\u5c31\u6709\u53ef\u80fd\u7acb\u523b\u6709\u4e8b\u4ef6\u89e6\u53d1\u5c31\u7eea&#xff0c;\u5b83\u8fd9\u65f6\u5019\u5c31\u4f1a\u53bb\u6709\u53bb\u5237\u65b0\u8fde\u63a5\u7684\u6d3b\u8dc3\u5ea6\u53bb\u5ef6\u8fdf\u5b9a\u65f6\u4efb\u52a1\u7684\u6267\u884c&#xff0c;\u90a3\u95ee\u9898\u5c31\u6765\u4e86&#xff1a;\u5982\u679c\u653e\u5230\u6784\u9020\u51fd\u6570\u91cc\u8fb9\u7684\u8bdd&#xff0c;\u90a3\u8fd9\u65f6\u5019\u5462&#xff1f;\u8fd8\u6ca1\u6709\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1\u5462&#xff0c;\u90a3\u5230\u65f6\u5019\u518d\u53bb\u627e\u8fd9\u4e2a\u627e\u8fd9\u4e2a\u5b9a\u65f6\u4efb\u52a1\u7684\u65f6\u5019\u94c1\u5b9a\u662f\u627e\u4e0d\u7740\u7684\u6240\u4ee5\u903b\u8f91\u662f\u6709\u95ee\u9898\u7684\u3002<\/p>\n<p>\u6240\u4ee5\u5462&#xff0c;\u5c31\u662f\u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u4ed6\u5e94\u8be5\u662f\u5728\u8fde\u63a5\u8bbe\u7f6e\u4e86\u975e\u6d3b\u8dc3\u8fde\u63a5\u9500\u6bc1\u4efb\u52a1\u4e4b\u540e\u6765\u8fdb\u884c\u3002 \u6240\u4ee5\u542f\u52a8\u8bfb\u4e8b\u4ef6\u5c31\u7eea\u9700\u8981\u5355\u72ec\u8fdb\u884c&#xff0c;\u7136\u540e\u5462\u8fd9\u5757\u5b8c\u4e86\u4e4b\u540e\u5462&#xff0c;\u6211\u4eec\u7684\u4e00\u4e2a\u8fde\u63a5\u624d\u662f\u5b8c\u5168\u5904\u7406\u5b8c\u6bd5\u4e86&#xff0c;\u624d\u53ef\u4ee5\u6b63\u5e38\u901a\u4fe1\u4e86\u3002<\/p>\n<p> <span class=\"token comment\">\/\/ 5.\u8fde\u63a5\u521b\u5efa\u521d&#xff0c;\u8fd8\u9700\u8981\u5404\u79cd\u8bbe\u7f6e&#xff1a;\u2460\u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7 \u2461\u8c03\u7528connected_callback\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">EstablishedInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2460.\u8bbe\u7f6e\u72b6\u6001\u4e3aConnected \u2461\u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7 \u2462\u8c03\u7528connected_callback\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n        <span class=\"token function\">assert<\/span><span class=\"token punctuation\">(<\/span>_status <span class=\"token operator\">&#061;&#061;<\/span> CONNECTING<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u786e\u4fdd\u5f53\u524d\u8fde\u63a5\u7684\u72b6\u6001\u4e3aCONNECTING\u3002<\/span><br \/>\n        _status <span class=\"token operator\">&#061;<\/span> CONNECTED<span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u8c03\u7528\u5b8c\u8fd9\u4e2a&#xff0c;\u8fde\u63a5\u624d\u7b97\u771f\u6b63\u521b\u5efa\u5b8c\u6bd5<\/span><br \/>\n        _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">EnableRead<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7<\/span><br \/>\n        <span class=\"token comment\">\/\/ shared_from_this()\u662f\u8fd4\u56de\u5f53\u524d\u5bf9\u8c61\u7684shared_ptr\u5bf9\u8c61<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_connected_callback<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token function\">_connected_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>SendInLoop()<\/h5>\n<p>\u8fd9\u4e2a\u63a5\u53e3\u5462\u5e76\u4e0d\u662f\u5b9e\u9645\u7684\u53d1\u9001\u63a5\u53e3&#xff0c;\u53ea\u662f\u628a\u670d\u52a1\u5668\u5904\u7406\u5b8c\u7684\u6570\u636e\u653e\u5230\u4e86\u7528\u6237\u6001\u53d1\u9001\u7f13\u51b2\u533a&#xff0c;\u7136\u540e\u542f\u52a8\u53ef\u5199\u4e8b\u4ef6\u76d1\u63a7\u3002 \u5b9e\u9645\u7684\u53d1\u9001\u6570\u636e\u662f\u5728\u6211\u4eec\u7684\u4e00\u4e2aHandlewrite\u91cc\u8fb9\u6765\u5b8c\u6210\u7684&#xff0c;\u4e5f\u5c31\u89e6\u53d1\u4e86\u53ef\u5199\u4e8b\u4ef6\u4e4b\u540e\u624d\u53bb\u90a3\u4e48\u8fdb\u884c\u4e00\u4e2a\u53d1\u9001\u7684\u64cd\u4f5c\u3002<\/p>\n<p><span class=\"token comment\">\/\/ 1.\u771f\u6b63\u7684\u5c06\u6570\u653e\u5165\u5230\u53d1\u9001\u7f13\u51b2\u533a\u4e2d \u2460\u5c06\u8981\u53d1\u9001\u7ed9\u5bf9\u7aef\u7684\u6570\u636e\u653e\u5165\u5230\u8f93\u51fa\u7f13\u51b2\u533a\u4e2d \u2461\u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">SendInLoop<\/span><span class=\"token punctuation\">(<\/span>Buffer <span class=\"token operator\">&amp;<\/span>buf<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5728\u4e1a\u52a1\u5904\u7406\u51fd\u6570\u4e2d&#xff0c;\u5bf9\u6570\u636e\u5904\u7406\u5b8c\u540e&#xff0c;\u5c31\u8981\u8c03\u7528send\u5c06\u54cd\u5e94\u653e\u5165\u5230\u8f93\u51fa\u7f13\u51b2\u533a\u4e2d<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_status <span class=\"token operator\">&#061;&#061;<\/span> DISCONNECTED<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        _out_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteBufferAndPop<\/span><span class=\"token punctuation\">(<\/span>buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5c06\u54cd\u5e94\u653e\u5165\u8f93\u51fa\u7f13\u51b2\u533a\u4e2d<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteAble<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">EnableWrite<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>ShutdownInLoop()<\/h5>\n<p>\u8fd9\u4e2a\u63a5\u53e3\u4e5f\u4e0d\u662f\u5b9e\u9645\u7684\u4e00\u4e2a\u91ca\u653e\u8fde\u63a5\u64cd\u4f5c&#xff0c;\u5176\u5b9e\u5b83\u53ea\u662f\u9700\u8981\u53bb\u5224\u65ad\u7528\u6237\u6001\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u5f85\u5904\u7406&#xff0c;\u7528\u6237\u6001\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u5f85\u53d1\u9001\u3002<\/p>\n<p>\u5f53\u8c03\u7528\u8be5\u63a5\u53e3\u65f6&#xff0c;\u8fde\u63a5\u5c31\u9700\u8981\u8bbe\u7f6e\u4e3a\u6211\u4eec\u7684\u4e00\u4e2a\u534a\u5173\u95ed\u72b6\u6001&#xff0c;\u5c31\u662f\u6ca1\u6709\u6570\u636e\u5728\u5904\u7406\u4e86\u5c31\u53bb\u5173\u95ed\u5b83\u3002<\/p>\n<p>\u6709\u53ef\u80fd\u4f1a\u5b58\u5728\u4e00\u79cd\u60c5\u51b5\u5c31\u662f\u6211\u4eec\u7684\u63a5\u6536\u7f13\u51b2\u533a\u91cc\u9762\u662f\u6709\u6570\u636e\u7684&#xff0c;\u4f46\u662f&#xff0c;\u5b83\u6570\u636e\u53ef\u80fd\u4e0d\u5b8c\u6574\u6570\u636e&#xff0c;\u4e0a\u5c42\u7ec4\u4ef6\u4f7f\u7528\u8005\u4eba\u5bb6\u53ef\u80fd\u5bf9\u63a5\u6536\u7f13\u51b2\u533a\u7684\u6570\u636e\u6839\u672c\u5c31\u4e0d\u5904\u7406\u3002 \u4eba\u5bb6\u786e\u5b9e\u5c31\u662f\u6709\u6570\u636e&#xff0c;\u4f46\u662f\u6211\u4e0d\u60f3\u5904\u7406&#xff0c;\u90a3\u8981\u4e0d\u8981\u5173\u95ed\u8fde\u63a5&#xff1f;\u662f\u8981\u5173\u95ed\u8fde\u63a5\u7684\u3002 \u5c31\u53ea\u7ba1\u8bf4\u6211\u8ba9\u4f60\u5904\u7406\u4e00\u4e0b&#xff0c;\u4f60\u81ea\u5df1\u5904\u7406\u5b8c\u4e86&#xff0c;\u4e0d\u7ba1\u4f60\u6709\u6ca1\u6709\u5904\u7406\u5b8c&#xff0c;\u6211\u63a5\u4e0b\u6765\u90fd\u8981\u53bb\u91ca\u653e\u8fde\u63a5\u4e86\u7684\u3002<\/p>\n<p><span class=\"token comment\">\/\/ 2.\u5e76\u4e0d\u76f4\u63a5\u5173\u95ed&#xff0c;\u771f\u6b63\u7684\u5148\u68c0\u6d4b\u5224\u65ad\u8f93\u5165\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u5f85\u5904\u7406&#xff0c;\u8f93\u51fa\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u5f85\u53d1\u9001<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">ShutdownInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u9996\u5148\u5c06\u8fde\u63a5\u7684\u72b6\u6001\u8bbe\u7f6e\u4e3aDISCONNECTING,\u5f85\u5173\u95ed\u72b6\u6001<\/span><br \/>\n        _status <span class=\"token operator\">&#061;<\/span> DISCONNECTING<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5148\u68c0\u6d4b\u8f93\u5165\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_in_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>_message_callback<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token function\">_message_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>_in_buffer<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u518d\u68c0\u6d4b\u8f93\u51fa\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_out_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u5982\u679c\u6709\u6570\u636e\u5c31\u8981\u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteAble<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">EnableWrite<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5982\u679c\u6700\u540e\u90fd\u6ca1\u6709\u4e86\u6570\u636e\u5c31\u53ef\u4ee5\u91ca\u653e\u8fde\u63a5\u4e86<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_out_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token function\">Release<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>ReleaseInLoop()<\/h5>\n<p>\u8fd9\u4e2a\u63a5\u53e3\u624d\u662f\u771f\u6b63\u7684\u91ca\u653e\u8fde\u63a5\u7684\u64cd\u4f5c&#xff0c;\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1\u4e2d\u7684\u4efb\u52a1\u5c31\u662f\u8be5\u51fd\u6570\u3002 \u771f\u6b63\u7684\u91ca\u653e\u8fde\u63a5\u4e3b\u8981\u505a\u4e00\u4e0b\u6b65\u9aa4&#xff1a; 0.\u9996\u5148\u5c06\u8fde\u63a5\u72b6\u6001\u7f6e\u4e3a\u5df2\u5173\u95edDISCONNECTED\u72b6\u6001 1.\u79fb\u9664\u8be5\u8fde\u63a5\u5728poller\u4e2d\u6240\u6709\u7684\u76d1\u63a7 2.\u5173\u95ed\u8be5\u8fde\u63a5\u7684\u5957\u63a5\u5b57 3.\u5728\u5173\u95ed\u65f6\u5982\u679c\u65f6\u95f4\u8f6e\u5b9a\u65f6\u5668\u4e2d\u8fd8\u6709\u8be5\u8fde\u63a5\u7684\u4efb\u52a1&#xff0c;\u5c31\u8981\u53d6\u6d88\u4efb\u52a1\u3002 4.\u6700\u540e\u5148\u6267\u884c\u5173\u95ed\u9636\u6bb5\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570&#xff0c;\u4ee5\u53ca\u670d\u52a1\u5668\u771f\u6b63\u8981\u5173\u95ed\u8fde\u63a5\u7684\u64cd\u4f5c\u56de\u8c03\u51fd\u6570(\u5c31\u662f\u5c06\u8be5\u8fde\u63a5\u4ece\u7ba1\u7406\u8fde\u63a5\u8868\u4e2d\u79fb\u9664&#xff0c;\u5c06\u6700\u540e\u4e00\u4e2a\u8ba1\u6570\u5668\u51cf\u4e3a0&#xff0c;\u8fd9\u4e2a\u8fde\u63a5\u624d\u771f\u6b63\u7684\u88ab\u91ca\u653e\u6389)<\/p>\n<p> <span class=\"token comment\">\/\/ 6.\u771f\u6b63\u5b9e\u9645\u91ca\u653e\u8fde\u63a5\u7684\u64cd\u4f5c<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">ReleaseInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2460\u8bbe\u7f6e\u8fde\u63a5\u7684\u72b6\u6001\u4e3aDISCONNECTED<\/span><br \/>\n        _status <span class=\"token operator\">&#061;<\/span> DISCONNECTED<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2461\u79fb\u9664\u8fde\u63a5\u7684\u6240\u6709\u76d1\u63a7<\/span><br \/>\n        _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">Remove<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2462\u5173\u95ed\u5957\u63a5\u5b57<\/span><br \/>\n        _socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">Close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2463\u5982\u679c\u8fd9\u4e2a\u8fde\u63a5\u8fd8\u6709\u975e\u6d3b\u8dc3\u5b9a\u65f6\u9500\u6bc1\u4efb\u52a1&#xff0c;\u5c31\u8981\u53d6\u6d88\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u5426\u5219\u7b2c\u4e8c\u6b21\u9500\u6bc1\u4f1a\u62a5\u9519<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">HasTaskE<\/span><span class=\"token punctuation\">(<\/span>_conn_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token function\">CancelInactiveReleaseInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2464\u6267\u884c\u9636\u6bb5\u6027\u7684\u5173\u95ed\u56de\u8c03\u51fd\u6570<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u9996\u5148\u8981\u6267\u884c\u7684\u7528\u6237\u7ea7\u522b\u7684\u5173\u95ed\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570&#xff0c;\u4e0d\u80fd\u5148\u6267\u884c\u670d\u52a1\u5668\u5173\u95ed\u9636\u6bb5\u7684\u56de\u8c03\u51fd\u6570&#xff0c;\u56e0\u4e3a\u7b2c\u4e8c\u4e2a\u662f\u771f\u6b63\u7684\u5173\u95ed\u8fde\u63a5\u3002\u670d\u52a1\u5668\u4e2d\u5b58\u50a8\u7740\u6700\u7ec8\u7684\u8fde\u63a5\u7684shared_ptr\u5bf9\u8c61\u7684\u4e00\u4e2a\u8ba1\u6570<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5982\u679c\u5148\u6267\u884c\u7b2c\u4e8c\u4e2a\u5c31\u4f1a\u4f7f\u7b2c\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\u8bbf\u95ee\u8fde\u63a5\u91ca\u653e&#xff0c;\u91ce\u6307\u9488<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_closed_callback<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token function\">_closed_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_svr_closed_callback<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token function\">_svr_closed_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e2a\u7ec6\u8282&#xff0c;\u5f53\u65f6\u5199\u7684\u65f6\u5019\u51fa\u73b0bug&#xff0c;\u8c03\u8bd5\u4e86\u624d\u53d1\u73b0&#xff0c;\u5c31\u662f\u6700\u540e\u4e00\u4e2a\u884c&#xff0c;\u6ca1\u6709\u52a0\u5224\u65ad\u6761\u4ef6\u7684\u8bdd\u4f1a\u6bb5\u9519\u8bef\u3002 \u56e0\u4e3a\u5f53\u5b9a\u65f6\u9500\u6bc1\u4efb\u52a1\u6267\u884c\u65f6&#xff0c;\u5b83\u4f1a\u5224\u65ad\u5f53\u524d\u8fde\u63a5\u662f\u5426\u8fd8\u6709\u5176\u4ed6\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u800c\u8fd9\u4e2a\u65f6\u5019\u8be5\u8fde\u63a5\u7684\u5b9a\u65f6\u4efb\u52a1\u5bf9\u8c61\u4ee5\u53ca\u88ab\u9500\u6bc1\u4e86&#xff0c;\u4e0d\u7136\u600e\u4e48\u4f1a\u6267\u884c\u6790\u6784\u51fd\u6570\u5462&#xff0c;\u800c\u4e0b\u9762\u53c8\u60f3\u8981\u8bbf\u95ee\u8be5\u5bf9\u8c61&#xff0c;\u5982\u679c\u4e0d\u52a0\u4ee5\u5224\u65ad\u662f\u5426\u5b58\u5728&#xff0c;\u5c31\u4f1a\u53d1\u751f\u9519\u8bef\u3002<\/p>\n<p> <span class=\"token keyword\">void<\/span> <span class=\"token function\">CancelTimerInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">uint64_t<\/span> id<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">auto<\/span> it <span class=\"token operator\">&#061;<\/span> _timers<span class=\"token punctuation\">.<\/span><span class=\"token function\">find<\/span><span class=\"token punctuation\">(<\/span>id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>it <span class=\"token operator\">&#061;&#061;<\/span> _timers<span class=\"token punctuation\">.<\/span><span class=\"token function\">end<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        PtrTask pt <span class=\"token operator\">&#061;<\/span> _timers<span class=\"token punctuation\">[<\/span>id<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">lock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u83b7\u53d6weakptr\u4fdd\u5b58\u7684shared_ptr,<\/span><br \/>\n        <span class=\"token comment\">\/\/\u5f53\u6267\u884cRelease\u7684\u65f6\u5019\u8bf4\u660e\u4efb\u52a1\u5bf9\u8c61\u5df2\u7ecf\u88ab\u91ca\u653e\u4e86&#xff0c;\u53ea\u6709\u91ca\u653e\u4e86\u624d\u4f1a\u8c03\u7528\u6790\u6784\u51fd\u6570\u6267\u884c\u91cc\u9762\u7684\u4efb\u52a1\u3002<\/span><br \/>\n        <span class=\"token comment\">\/\/\u800c\u8be5\u5bf9\u8c61\u5df2\u7ecf\u90fd\u88ab\u91ca\u653e\u6389\u4e86&#xff0c;\u83b7\u53d6\u5230\u8be5\u5bf9\u8c61\u7684shared_ptr\u4e5f\u5c31\u4e3a\u7a7a&#xff0c;\u5c31\u4e0d\u4f1a\u518d\u533a\u8bbf\u95ee\u8be5\u5bf9\u8c61<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>pt<span class=\"token punctuation\">)<\/span> pt<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">canceled<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>UpgradeInLoop()<\/h5>\n<h4>1.2\u63cf\u8ff0\u7b26\u7684\u5c31\u7eea\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570\u6784\u5efa<\/h4>\n<p>\u63cf\u8ff0\u7b26\u7684\u5404\u79cd\u4e8b\u4ef6\u600e\u4e48\u5904\u7406\u90fd\u662f\u7531\u8fde\u63a5\u8bbe\u7f6e\u7684&#xff0c;\u53ea\u6709\u8fde\u63a5\u77e5\u9053\u5f53\u8bfb\u4e8b\u4ef6\u5c31\u7eea\u65f6\u8981\u5e72\u561b&#xff0c;\u5f53\u5199\u4e8b\u4ef6\u5c31\u7eea\u65f6\u8981\u5e72\u561b\u3002 \u6240\u4ee5\u8981\u5728\u8fde\u63a5\u5185\u90e8\u8bbe\u7f6e\u597d\u8bfb\/\u5199\/\u6302\u65ad\/\u9519\u8bef\/\u4efb\u610f5\u4e2a\u4e8b\u4ef6\u7684\u56de\u8c03\u51fd\u6570\u3002\u8fd9\u91cc\u5148\u6784\u5efa\u51fa\u6765&#xff0c;\u7136\u540e\u5728\u8fde\u63a5\u7684\u6784\u9020\u91cc\u9762&#xff0c;\u4f1a\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n<h5>HandleRead()<\/h5>\n<p>\u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e\u8fc7\u6765&#xff0c;\u5c31\u4f1a\u89e6\u53d1\u8bfb\u4e8b\u4ef6\u5c31\u7eea&#xff0c;\u8bfb\u4e8b\u4ef6\u5c31\u7eea\u5e94\u8be5\u5e72\u4ec0\u4e48\u5462&#xff1f; \u9996\u5148\u4ecesocket\u4e2d\u8bfb\u53d6\u5bf9\u65b9\u53d1\u9001\u6765\u7684\u6570\u636e&#xff0c;\u7136\u540e\u653e\u5165\u5230\u7528\u6237\u6001\u7684\u63a5\u53d7\u7f13\u5b58\u533a\u4e2d\u3002 \u6700\u540e\u8c03\u7528\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u5373\u4e1a\u52a1\u5904\u7406\u51fd\u6570\u3002 \u7ec6\u8282&#xff1a; \u5982\u679crecv\u8bfb\u53d6\u5c0f\u4e8e\u96f6&#xff0c;\u5c31\u662fsocket\u8bfb\u53d6\u6570\u636e\u8fc7\u7a0b\u51fa\u9519\u4e86\u600e\u4e48\u529e&#xff1f; \u5e94\u8be5\u76f4\u63a5\u5173\u95ed\u8fde\u63a5\u5417&#xff1f; \u660e\u663e\u4e0d\u662f&#xff0c;\u51fa\u9519\u4e86\u4e0d\u80fd\u76f4\u63a5\u5173\u95ed\u8fde\u63a5&#xff0c;\u5b83\u5e94\u8be5\u8fd9\u65f6\u5019\u5e72\u4ec0\u4e48\u5462&#xff1f;\u5b83\u8fd9\u65f6\u5019\u5e94\u8be5\u505a\u7684\u4e00\u4e2a\u4e8b\u60c5\u5c31\u770b\u4e00\u4e0b\u6211\u4eec\u7684\u53d1\u9001\u7f13\u51b2\u533a\u8fd8\u6709\u6ca1\u6709\u6570\u636e\u5f85\u53d1\u9001\u3002\u6211\u4eec\u7684\u63a5\u6536\u7f13\u51b2\u533a\u6709\u6ca1\u6709\u6570\u636e\u5f85\u5904\u7406\u3002 \u6240\u4ee5\u6211\u4eec\u5e94\u8be5\u76f4\u63a5\u8fd4\u56de\u8c03\u7528shutdowninloop(); \u4e3a\u4ec0\u4e48\u5462&#xff1f;\u56e0\u4e3a\u670d\u52a1\u5668\u8fd9\u8fb9\u7684\u8bfb\u53d6\u51fa\u9519&#xff0c;\u4f46\u5b83\u4e4b\u524d\u53ef\u80fd\u8bfb\u53d6\u8fc7\u6570\u636e&#xff0c;\u6240\u4ee5\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u53ef\u80fd\u5b58\u5728\u6570\u636e&#xff0c;\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u4e5f\u53ef\u80fd\u5b58\u5728\u6570\u636e\u6ca1\u6709\u53d1\u9001\u5b8c&#xff0c;\u6240\u4ee5\u5173\u95ed\u8fde\u63a5\u662f\u4e0d\u597d\u7684\u3002<\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">HandleRead<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">char<\/span> buf<span class=\"token punctuation\">[<\/span><span class=\"token number\">65535<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        ssize_t ret <span class=\"token operator\">&#061;<\/span> _socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">NonBlockRecv<\/span><span class=\"token punctuation\">(<\/span>buf<span class=\"token punctuation\">,<\/span> <span class=\"token number\">65535<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u4ecesocket\u4e2d\u8bfb\u53d6\u6570\u636e<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>ret <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ ret&lt;0\u8bf4\u660e\u8bfb\u53d6\u5931\u8d25&#xff0c;\u5c31\u8981\u5173\u95ed\u8fde\u63a5&#xff0c;\u4f46\u5173\u95ed\u4e4b\u524d\u8981\u5224\u65ad\u7f13\u51b2\u533a\u662f\u5426\u8fd8\u6709\u6570\u636e<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token function\">ShutdownInLoop<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ ret&gt;0\u8bf4\u660e\u8bfb\u53d6\u6210\u529f<\/span><br \/>\n        _in_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteAndPop<\/span><span class=\"token punctuation\">(<\/span>buf<span class=\"token punctuation\">,<\/span> ret<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5c06\u8bfb\u53d6\u7684\u6570\u636e\u653e\u5165\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d&#xff0c;\u5e76\u79fb\u52a8\u4f4d\u7f6e<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u8c03\u7528\u4e1a\u52a1\u5904\u7406\u51fd\u6570<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_in_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token function\">_message_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>_in_buffer<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>HandleWrite()<\/h5>\n<p>\u5f53\u4e1a\u52a1\u5904\u7406\u51fd\u6570\u5904\u7406\u5b8c\u6570\u636e\u4e4b\u540e&#xff0c;\u5c31\u4f1a\u8c03\u7528Send\u51fd\u6570\u5c06\u54cd\u5e94\u653e\u5165\u5230\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d&#xff0c;\u5e76\u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u4e00\u65e6\u5185\u6838\u53d1\u9001\u7f13\u51b2\u533a\u6709\u7a7a\u95f4&#xff0c;\u5c31\u4f1a\u89e6\u53d1\u5199\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u5c31\u4f1a\u8c03\u7528\u8be5\u63a5\u53e3\u3002 \u8be5\u63a5\u53e3\u4e3b\u8981\u662f\u5c06\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u901a\u8fc7socket\u53d1\u9001\u7ed9\u5bf9\u7aef\u3002\u800c\u56e0\u4e3a\u5199\u4e8b\u4ef6\u662f\u5e38\u5c31\u7eea\u7684&#xff0c;\u6211\u4eec\u9700\u8981\u6309\u9700\u8bbe\u7f6e\u5199\u76d1\u63a7&#xff0c;\u5f53\u5c06\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u5168\u90e8\u53d1\u9001\u51fa\u53bb\u540e&#xff0c;\u5c31\u5173\u95ed\u5199\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u9632\u6b62\u5b83\u6301\u7eed\u5c31\u7eea&#xff0c;\u7b49\u5f85\u4e0b\u6b21\u7528\u6237\u6001\u4e2d\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u6709\u6570\u636e\u65f6\u518d\u89e6\u53d1\u3002<\/p>\n<p>\u7ec6\u82821&#xff1a; \u5f53send\u53d1\u9001\u65f6\u51fa\u9519\u4e86\u5462&#xff0c;\u600e\u4e48\u529e&#xff1f; \u4e0d\u8fc7\u5982\u679c\u9519\u8bef\u662f\u56e0\u4e3a\u5bf9\u7aef\u5185\u6838\u53d1\u9001\u7f13\u51b2\u533a\u91cc\u8fb9\u5df2\u7ecf\u6ca1\u6709\u7a7a\u95f4\u7684\u653e\u8fdb\u53bb\u6570\u636e\u4e86&#xff0c;\u6216\u8005\u5b83\u88ab\u4fe1\u53f7\u6253\u65ad\u4e86\u3002\u6211\u4eec\u5c31\u8fd4\u56de\u4e00\u4e2a\u96f6\u4ee3\u8868\u4e00\u4e2a\u6570\u636e\u6570\u636e\u90fd\u6ca1\u53d1\u51fa\u53bb&#xff0c;\u8fd9\u662f\u53ef\u4ee5\u539f\u8c05\u7684\u3002 \u4f46\u662f\u5462&#xff1f;\u5c31\u662f\u8bf4&#xff0c;\u5982\u679c\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5c0f\u4e8e\u96f6\u662f\u4e00\u4e2a\u8d1f1&#xff0c;\u90a3\u5c31\u4ee3\u8868\u662f\u771f\u7684\u9519\u4e86&#xff0c;\u771f\u7684\u662f\u4e0d\u53ef\u539f\u8c05\u7684\u9519\u8bef\u3002\u90a3\u8fd9\u65f6\u5019&#xff0c;\u8fde\u63a5\u662f\u4e0d\u662f\u5c31\u8be5\u5173\u95ed\u4e86\u3002\u90a3\u8fde\u63a5\u80fd\u76f4\u63a5\u91ca\u653e\u5417&#xff1f; \u4e0d\u80fd&#xff01; \u6211\u4eec\u8fd8\u5f97\u8003\u8651\u4e00\u4e2a\u60c5\u51b5&#xff1a;\u53d1\u9001\u662f\u53d1\u9001\u4e0d\u8fc7\u53bb\u4e86&#xff0c;\u4f46\u662f\u7528\u6237\u6001\u7684\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u5982\u679c\u8fd8\u5b58\u5728\u6570\u636e\u5f85\u5904\u7406\u5462&#xff1f;\u8fd9\u4e0d\u5f71\u54cd\u5440&#xff0c;\u6240\u4ee5\u5728\u5173\u95ed\u4e4b\u524d\u6211\u4eec\u8fd8\u9700\u8981\u5224\u65ad\u4e00\u4e0b\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e&#xff0c;\u5982\u679c\u6709\u5219\u76f4\u63a5\u8c03\u7528\u4e1a\u52a1\u5904\u7406\u51fd\u6570&#xff0c;\u5904\u7406\u4e00\u4e0b\u3002\u7136\u540e\u76f4\u63a5\u771f\u6b63\u7684\u91ca\u653e\u8fde\u63a5\u3002 \u7ec6\u82822&#xff1a; \u53d1\u9001\u6570\u636e\u53ef\u80fd\u4e00\u6b21\u6ca1\u6709\u53d1\u9001\u5b8c&#xff0c;\u8fd9\u6837\u5c31\u4f1a\u53d1\u9001\u591a\u6b21&#xff0c;\u76f4\u5230\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u6ca1\u6709\u6570\u636e\u4e86\u624d\u4f1a\u505c\u6b62&#xff0c;\u5c06\u5199\u4e8b\u4ef6\u76d1\u63a7\u53d6\u6d88\u3002 \u89e6\u53d1\u8c03\u7528HandleWrite\u7684\u63a5\u53e3\u6709\u591a\u4e2a&#xff0c;\u4e00\u4e2a\u662f\u6b63\u5e38\u901a\u4fe1\u4e2d\u4e1a\u52a1\u5904\u7406\u5b8c\u4f1a\u8c03\u7528Send\u5c06\u6570\u636e\u653e\u5165\u53d1\u9001\u7f13\u51b2\u533a&#xff0c;\u7136\u540e\u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7\u3002 \u4e00\u4e2a\u662f\u8981\u7ec4\u4ef6\u4f7f\u7528\u8005\u4e3b\u52a8\u91ca\u653e\u8fde\u63a5\u65f6\u8c03\u7528Shutdown&#xff0c;\u5b83\u4f1a\u5224\u65ad\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u5f85\u53d1\u9001&#xff0c;\u6765\u51b3\u5b9a\u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u5f53\u8fd8\u6709\u6570\u636e\u65f6&#xff0c;\u5c31\u8981\u53d1\u9001&#xff0c;\u8fd9\u4e2a\u5df2\u7ecf\u662f\u76f8\u5f53\u4e8e\u8fd8\u5269\u4e0b\u6700\u540e\u4e00\u53e3\u6c14\u4e86&#xff0c;\u53d1\u9001\u5b8c\u5c31\u8981\u91ca\u653e\u8fde\u63a5\u4e86&#xff0c;\u4e0d\u80fd\u518d\u5e72\u5565\u4e86\u3002 \u6240\u4ee5\u5f53\u72b6\u6001\u4e3aDISCONNECTING\u5c31\u8868\u660e\u662f\u8c03\u7528Shutdown&#xff0c;\u89e6\u53d1\u7684&#xff0c;\u53d1\u9001\u5b8c\u6570\u636e\u5c31\u8981\u8c03\u7528Release\u91ca\u653e\u8fde\u63a5\u3002<\/p>\n<p> <span class=\"token comment\">\/\/ 9.\u5f53\u8fde\u63a5\u89e6\u53d1\u5199\u4e8b\u4ef6\u65f6\u8981\u8c03\u7528\u7684\u63a5\u53e3\u3002\u2460\u5c06\u53d1\u9001\u7f13\u51b2\u533a\u7684\u6570\u636e\u901a\u8fc7socket\u53d1\u9001\u51fa\u53bb<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">HandleWrite<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        ssize_t ret <span class=\"token operator\">&#061;<\/span> _socket<span class=\"token punctuation\">.<\/span><span class=\"token function\">NonBlockSend<\/span><span class=\"token punctuation\">(<\/span>_out_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">ReadPostion<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> _out_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>ret <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/\u5224\u65ad\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u5f85\u5904\u7406<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_in_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token function\">_message_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>_in_buffer<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token comment\">\/\/ ret&lt;0\u8bf4\u660e\u53d1\u9001\u5931\u8d25&#xff0c;\u540e\u9762\u518d\u53d1\u9001\u4e5f\u4f1a\u5931\u8d25&#xff0c;\u6240\u4ee5\u5173\u95ed\u8fde\u63a5\u4e4b\u524d\u53ea\u9700\u8981\u5173\u5fc3\u8f93\u5165\u7f13\u5b58\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u3002<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token function\">Release<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ ret&gt;0\u8bf4\u660e\u53d1\u9001\u6210\u529f&#xff0c;\u8981\u6ce8\u610f\u5c06\u8f93\u51fa\u7f13\u51b2\u533a\u7684\u8bfb\u4f4d\u7f6e\u79fb\u52a8<\/span><br \/>\n        _out_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">MoveRead<\/span><span class=\"token punctuation\">(<\/span>ret<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6709\u53ef\u80fdsocket\u7684\u7f13\u51b2\u533a\u7a7a\u95f4\u4e0d\u8db3&#xff0c;\u53d1\u9001\u4e00\u6b21\u540e_out_buffer\u4e2d\u8fd8\u6709\u6570\u636e&#xff0c;\u5c31\u4f1a\u518d\u6b21\u89e6\u53d1\u5199\u4e8b\u4ef6&#xff0c;\u76f4\u5230_out_buffer\u4e2d\u6ca1\u6709\u6570\u636e<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_out_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u8bf4\u660e\u8f93\u51fa\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u5df2\u7ecf\u5168\u90e8\u901a\u8fc7socket\u53d1\u9001\u7ed9\u5bf9\u7aef\u4e86,\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981\u5173\u95ed\u5199\u4e8b\u4ef6\u76d1\u63a7\u4e86<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u56e0\u4e3a\u5199\u4e8b\u4ef6\u76d1\u63a7\u603b\u662f\u5c31\u7eea\u7684&#xff0c;\u6240\u4ee5\u6309\u9700\u8981\u6765\u8bbe\u7f6e\u76d1\u63a7<\/span><br \/>\n            _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">DisableWrite<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>            <span class=\"token comment\">\/\/ \u80fd\u89e6\u53d1\u8c03\u7528HandleWrite\u7684\u63a5\u53e3\u6709\u597d\u51e0\u4e2a&#xff0c;\u6709Send,Shutdown,\u5f53\u8c03\u7528Shutdown\u63a5\u53e3\u65f6&#xff0c;\u4e5f\u4f1a\u542f\u52a8\u5199\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u6267\u884c\u5b8c\u540e\u5c31\u8981\u91ca\u653e\u8fde\u63a5<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_status <span class=\"token operator\">&#061;&#061;<\/span> DISCONNECTING<span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token keyword\">return<\/span> <span class=\"token function\">Release<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>HandleClose()<\/h5>\n<p>\u5f53\u5bf9\u7aef\u6302\u6389\u4e86&#xff0c;\u5c31\u4f1a\u89e6\u53d1\u8be5\u63a5\u53e3&#xff0c; \u5bf9\u65b9\u6302\u6389\u4e86&#xff0c;\u670d\u52a1\u5668\u80af\u5b9a\u65e0\u6cd5\u53d1\u9001\u4e86&#xff0c;\u4f46\u4e0d\u5f71\u54cd\u5b83\u63a5\u53d7\u7f13\u51b2\u533a\u4e2d\u53ef\u80fd\u8fd8\u6709\u6570\u636e\u5f85\u5904\u7406&#xff0c;\u6240\u4ee5\u5728\u5173\u95ed\u8fde\u63a5\u4e4b\u524d\u9700\u8981\u5224\u65ad\u4e00\u4e0b\u3002<\/p>\n<p><span class=\"token comment\">\/\/ 10.\u5f53\u8fde\u63a5\u89e6\u53d1\u5173\u95ed\u4e8b\u4ef6\u65f6\u8981\u8c03\u7528\u7684\u63a5\u53e3\u3002<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">HandleClose<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5bf9\u7aef\u5173\u95ed\u4e86&#xff0c;\u670d\u52a1\u5668\u5c31\u65e0\u6cd5\u518d\u53d1\u9001\u6570\u636e\u8fc7\u53bb&#xff0c;\u4f46\u662f\u8fd8\u53ef\u4ee5\u5904\u7406\u8f93\u5165\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_in_buffer<span class=\"token punctuation\">.<\/span><span class=\"token function\">AvailableReadSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token function\">_message_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>_in_buffer<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token function\">Release<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>HandleError()<\/h5>\n<p>\u540c\u4e0a<\/p>\n<p> <span class=\"token comment\">\/\/ 11.\u5f53\u8fde\u63a5\u89e6\u53d1\u9519\u8bef\u4e8b\u4ef6\u65f6\u8981\u8c03\u7528\u7684\u63a5\u53e3<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">HandleError<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token function\">HandleClose<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h5>HandleEvent()<\/h5>\n<p>\u4efb\u610f\u4e8b\u4ef6\u4e3b\u8981\u662f\u7528\u6765\u5237\u65b0\u8fde\u63a5\u65f6\u957f\u7684&#xff0c;\u4e5f\u5c31\u662f\u5ef6\u8fdf\u8fde\u63a5\u7684\u9500\u6bc1\u4efb\u52a1\u3002 \u4e0d\u8fc7\u8981\u6ce8\u610f&#xff0c;\u5237\u65b0\u7684\u524d\u63d0\u662f\u5df2\u7ecf\u6709\u4efb\u52a1&#xff0c;\u4efb\u52a1\u5df2\u7ecf\u542f\u52a8\u4e86\u624d\u53ef\u4ee5\u5bf9\u5b83\u5237\u65b0&#xff0c;\u6240\u4ee5\u6839\u636e\u6807\u5fd7\u4f4d\u6765\u786e\u5b9a\u662f\u5426\u542f\u52a8\u4e86\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1\u3002 \u6700\u540e\u8fd8\u8981\u6267\u884c\u4e00\u4e0b\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570&#xff0c;\u64cd\u4f5c\u4ec0\u4e48\u6839\u636e\u5916\u754c\u51b3\u5b9a\u3002<\/p>\n<p> <span class=\"token comment\">\/\/ 12.\u5f53\u8fde\u63a5\u89e6\u53d1\u4efb\u610f\u4e8b\u4ef6\u65f6\u8981\u8c03\u7528\u7684\u63a5\u53e3<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">HandleEvent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2460\u5237\u65b0\u8fde\u63a5\u65f6\u957f&#xff0c;\u4e5f\u5c31\u662f\u5ef6\u8fdf\u5b9a\u65f6\u4efb\u52a1\u7684\u6267\u884c \u2461\u6267\u884c\u7528\u6237\u7ea7\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5982\u679c\u5df2\u7ecf\u542f\u52a8\u4e86\u975e\u6d3b\u8dc3\u8d85\u65f6\u8fde\u63a5\u9500\u6bc1\u4efb\u52a1&#xff0c;\u5219\u6807\u5fd7\u4f4d\u4e00\u5b9a\u4e3atrue<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_inactive_release <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n            _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RefreshTaskE<\/span><span class=\"token punctuation\">(<\/span>_conn_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>_anyevent_callback<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n             <span class=\"token function\">_anyevent_callback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">shared_from_this<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h3>2.\u516c\u6709\u6210\u5458\u51fd\u6570(\u4e3a\u5916\u90e8\u63d0\u4f9b\u7684\u63a5\u53e3)<\/h3>\n<p>\u8fd9\u4e9b\u63a5\u53e3\u90fd\u662f\u5c06\u5bf9\u5e94\u771f\u6b63\u7684\u64cd\u4f5c\u5c01\u88c5\u4e00\u904d&#xff0c;\u538b\u5165\u5230\u5bf9\u5e94loop\u4e2d\u7684\u4efb\u52a1\u961f\u5217\u4e2d\u7684\u3002 \u800c\u4efb\u52a1\u961f\u5217\u4e2d\u7684\u64cd\u4f5c\u624d\u662f\u771f\u6b63\u7684\u64cd\u4f5c\u3002<\/p>\n<h4>2.1\u6784\u9020\u51fd\u6570<\/h4>\n<p>\u4e00\u4e2aConnection\u521b\u5efa\u65f6&#xff0c;\u9700\u8981\u4e00\u4e2a\u552f\u4e00\u7684\u8fde\u63a5ID&#xff0c;\u5bf9\u5e94\u7684\u901a\u4fe1\u5957\u63a5\u5b57&#xff0c;\u8fd8\u6709\u7ed1\u5b9a\u4e00\u4e2aeventloop\u7ebf\u7a0b\u3002 \u5728 \u6784\u9020\u51fd\u6570\u4e2d\u5b9e\u73b0\u8fde\u63a5\u7684\u4e00\u4e9b\u57fa\u672c\u8bbe\u7f6e&#xff0c;\u6bd4\u5982\u8bbe\u7f6e\u8fde\u63a5channel\u76845\u4e2a\u4e8b\u4ef6\u56de\u8c03\u3002\u4f46\u8981\u6ce8\u610f\u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u4e0d\u80fd\u653e\u5728\u6784\u9020\u51fd\u6570\u4e2d\u3002<\/p>\n<p>  <span class=\"token comment\">\/\/ \u6784\u9020\u51fd\u6570<\/span><br \/>\n    <span class=\"token function\">Connection<\/span><span class=\"token punctuation\">(<\/span>EventLoop <span class=\"token operator\">*<\/span>loop<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">uint64_t<\/span> conn_id<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> sockfd<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token function\">_conn_id<\/span><span class=\"token punctuation\">(<\/span>conn_id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                                                                <span class=\"token function\">_sockfd<\/span><span class=\"token punctuation\">(<\/span>sockfd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_socket<\/span><span class=\"token punctuation\">(<\/span>_sockfd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_channel<\/span><span class=\"token punctuation\">(<\/span>loop<span class=\"token punctuation\">,<\/span> _sockfd<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_status<\/span><span class=\"token punctuation\">(<\/span>CONNECTING<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                                                                <span class=\"token function\">_loop<\/span><span class=\"token punctuation\">(<\/span>loop<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_inactive_release<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u8fde\u63a5\u521a\u521b\u5efa\u65f6&#xff0c;\u5c31\u5c06channel\u76845\u4e2a\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570\u8bbe\u7f6e\u597d\u4e86<\/span><br \/>\n        _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetReadCallback<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>HandleRead<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetWriteCallback<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>HandleWrite<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetCloseCallback<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>HandleClose<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetErrorCallback<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>HandleError<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        _channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetEventCallback<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>HandleEvent<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u4e0d\u80fd\u653e\u5728\u6784\u9020\u51fd\u6570\u91cc\u9762\u8fdb\u884c&#xff0c;\u56e0\u4e3a\u6015\u4e00\u8bbe\u7f6e&#xff0c;\u5c31\u6709\u4e8b\u4ef6\u5c31\u7eea&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u8fd8\u6ca1\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u66f4\u65e0\u6cd5\u5237\u65b0\u5ef6\u8fdf\u4efb\u52a1\u4e86<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6240\u4ee5\u542f\u52a8\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u7684\u64cd\u4f5c\u4e00\u5b9a\u8981\u5728\u542f\u52a8\u975e\u6d3b\u8dc3\u9500\u6bc1\u4efb\u52a1\u4e4b\u540e\u8fdb\u884c<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h4>2.2\u5bf9\u8fde\u63a5\u64cd\u4f5c\u7684\u51fd\u6570<\/h4>\n<p>\u5bf9\u8fde\u63a5\u7684\u64cd\u4f5c\u5168\u90e8\u5c01\u88c5\u4e00\u904d&#xff0c;\u901a\u8fc7\u8c03\u7528runinloop\u5c06\u8fd9\u4e9b\u771f\u6b63\u5bf9\u8fde\u63a5\u7684\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\u6267\u884c\u3002<\/p>\n<p>\u4e0d\u8fc7\u6709\u4e00\u4e2a\u6ce8\u610f\u70b9&#xff0c;\u5c31\u662fSend()\u51fd\u6570&#xff0c;\u5c06\u670d\u52a1\u5668\u5904\u7406\u5b8c\u7684\u6570\u636e\u653e\u5165\u5230\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d&#xff0c;\u8fd9\u4e2a\u5916\u754c\u4f20\u5165\u7684data\u6570\u636e\u53ef\u80fd\u662f\u4e00\u4e2a\u4e34\u65f6\u7684\u6570\u636e&#xff0c;\u800cSend\u51fd\u6570\u53ea\u662f\u5c06\u53d1\u9001\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d&#xff0c;\u6709\u53ef\u80fd\u6ca1\u6709\u88ab\u7acb\u523b\u6267\u884c&#xff0c;\u6240\u4ee5\u5f53\u771f\u6b63\u6267\u884c\u65f6&#xff0c;\u5b58\u50a8\u8fd9\u4e2adata\u6570\u636e\u7684\u7a7a\u95f4\u5df2\u7ecf\u88ab\u91ca\u653e\u4e86&#xff0c;\u5c31\u65e0\u6cd5\u518d\u53bb\u8bbf\u95ee\u4e86&#xff0c;\u6240\u4ee5\u5728Send()\u51fd\u6570\u8fd8\u6ca1\u6709\u5c06\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\u65f6&#xff0c;\u5148\u5c06\u8fd9\u4e2a\u7a7a\u95f4\u7684\u6570\u636e\u62f7\u8d1d\u51fa\u6765&#xff0c;\u7528\u4e00\u4e2abuffer\u5bf9\u8c61\u5b58\u50a8&#xff0c;\u7136\u540e\u4f20\u5165\u4f20\u5165\u7ed9SendInLoop,SendInLoop\u8bbf\u95ee\u7684\u5c31\u662fbuffer\u4e00\u4e2a\u62f7\u8d1d\u5bf9\u8c61\u3002\u8fd9\u6837\u5c31\u4e0d\u6015data\u7a7a\u95f4\u91ca\u653e\u4e86\u3002<\/p>\n<p> <span class=\"token comment\">\/*\u5bf9\u8fde\u63a5\u7684\u64cd\u4f5c&#xff1a;*\/<\/span><br \/>\n    <span class=\"token comment\">\/\/ 1.\u5c06\u6570\u636e\u653e\u5165\u5230\u53d1\u9001\u7f13\u51b2\u533a\u4e2d<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5916\u754c\u4f20\u5165\u7684data\u53ef\u80fd\u662f\u4e00\u4e2a\u4e34\u65f6\u7684\u6570\u636e&#xff0c;\u800cSend\u4e5f\u53ea\u662f\u5c06\u53d1\u9001\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d&#xff0c;\u6709\u53ef\u80fd\u6ca1\u6709\u88ab\u7acb\u523b\u6267\u884c<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5f53\u6267\u884c\u53d1\u9001\u64cd\u4f5c\u65f6&#xff0c;\u5b58\u50a8\u6570\u636e\u7684\u7a7a\u95f4\u53ef\u80fd\u91ca\u653e\u4e86&#xff0c;\u5c31\u65e0\u6cd5\u8bbf\u95ee\u4e86&#xff0c;\u6240\u4ee5\u91cd\u65b0\u6784\u9020\u4e00\u4e2a\u5bb9\u5668\u53d8\u91cf\u5b58\u50a8\u8be5\u6570\u636e&#xff0c;\u8fd9\u6837\u8bbf\u95ee<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u8bbf\u95ee\u7684\u662f\u4e00\u4e2a\u62f7\u8d1d\u53d8\u91cf\u800c\u4e0d\u662f\u7a7a\u95f4\u5730\u5740&#xff0c;\u5c31\u4e0d\u6015\u4e86<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">Send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> <span class=\"token keyword\">char<\/span> <span class=\"token operator\">*<\/span>data<span class=\"token punctuation\">,<\/span> size_t len<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        Buffer buf<span class=\"token punctuation\">;<\/span><br \/>\n        buf<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteAndPop<\/span><span class=\"token punctuation\">(<\/span>data<span class=\"token punctuation\">,<\/span> len<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RunInLoop<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>SendInLoop<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">,<\/span> buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 2.\u7ed9\u7ec4\u4ef6\u4f7f\u7528\u8005\u4f7f\u7528\u7684\u5173\u95ed\u63a5\u53e3&#xff0c;\u5e76\u4e0d\u662f\u76f4\u63a5\u5173\u95ed&#xff0c;\u800c\u662f\u5148\u68c0\u6d4b\u5224\u65ad\u7f13\u51b2\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">Shutdown<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RunInLoop<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>ShutdownInLoop<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 3.\u542f\u52a8\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1&#xff0c;\u5f53\u8fde\u63a5\u8d85\u8fc7\u4e00\u5b9a\u65f6\u95f4\u540e\u6ca1\u6709\u64cd\u4f5c\u5c31\u91ca\u653e\u6389<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">EnableInactiveRelease<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> sec<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RunInLoop<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>EnableInactiveReleaseInLoop<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">,<\/span> sec<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 4.\u53d6\u6d88\u975e\u6d3b\u8dc3\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">CancelInactiveRelease<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RunInLoop<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>CancelInactiveReleaseInLoop<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 5.\u8fde\u63a5\u521b\u5efa\u540e\u8981\u5bf9\u5176\u8fdb\u884c\u540e\u7eed\u5c5e\u6027\u8bbe\u7f6e&#xff0c;channel\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570\u8bbe\u7f6e&#xff0c;\u8bfb\u4e8b\u4ef6\u76d1\u63a7\u542f\u52a8&#xff0c;\u8c03\u7528connected_callback\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">Established<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RunInLoop<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>EstablishedInLoop<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 6.\u91ca\u653e\u8fde\u63a5\u7684\u64cd\u4f5c\u662f\u5728\u8fd9\u91cc\u6267\u884c&#xff0c;\u4f46\u53c8\u4e0d\u662f\u76f4\u63a5\u5728\u8fd9\u91cc\u6267\u884c\u800c\u662f\u5728ReleaseInLoop\u4e2d\u6267\u884c<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">Release<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> _loop<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">RunInLoop<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>Connection<span class=\"token operator\">::<\/span>ReleaseInLoop<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 7.\u66f4\u65b0\u534f\u8bae&#xff0c;\u672c\u8d28\u5c31\u662f\u66ff\u6362\u8fde\u63a5\u7684\u4e0a\u4e0b\u6587\u4ee5\u53ca\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">Upgrade<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> Any <span class=\"token operator\">&amp;<\/span>context<span class=\"token punctuation\">,<\/span><br \/>\n                 <span class=\"token keyword\">const<\/span> ConnectedCallback <span class=\"token operator\">&amp;<\/span>cb1<span class=\"token punctuation\">,<\/span><br \/>\n                 <span class=\"token keyword\">const<\/span> MessageCallback <span class=\"token operator\">&amp;<\/span>cb2<span class=\"token punctuation\">,<\/span><br \/>\n                 <span class=\"token keyword\">const<\/span> ClosedCallback <span class=\"token operator\">&amp;<\/span>cb3<span class=\"token punctuation\">,<\/span><br \/>\n                 <span class=\"token keyword\">const<\/span> AnyEventCallback <span class=\"token operator\">&amp;<\/span>cb4<span class=\"token punctuation\">,<\/span><br \/>\n                 <span class=\"token keyword\">const<\/span> ClosedCallback <span class=\"token operator\">&amp;<\/span>cb5<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>2.3\u5bf9\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u8bbe\u7f6e\u7684\u51fd\u6570<\/h4>\n<p>\u5411\u5916\u63d0\u4f9b\u8fd8\u6709\u5c31\u662f\u8bbe\u7f6e\u8fde\u63a5\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u8bbe\u7f6e&#xff0c;\u8fd9\u4e9b\u8bbe\u7f6e\u51fd\u6570\u63d0\u4f9b\u51fa\u6765&#xff0c;\u7528\u4e0d\u7528\u7531\u7528\u6237\u51b3\u5b9a&#xff0c;\u5c31\u662f\u5c06\u4e0a\u5c42\u7528\u6237\u5b9a\u4e49\u7684\u51fd\u6570&#xff0c;\u8bbe\u7f6e\u8fdb\u53bb\u3002\u7b49\u5230\u5bf9\u5e94\u7684\u9636\u6bb5\u5c31\u4f1a\u53bb\u6267\u884c\u3002<\/p>\n<p> <span class=\"token comment\">\/*5\u4e2a\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570\u7684\u8bbe\u7f6e*\/<\/span><br \/>\n    <span class=\"token comment\">\/\/ 8.\u8bbe\u7f6e\u8fde\u63a5\u5b8c\u5168\u521b\u5efa\u65f6\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">SetConnectedCallback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> ConnectedCallback <span class=\"token operator\">&amp;<\/span>cb<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        _connected_callback <span class=\"token operator\">&#061;<\/span> cb<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 9.\u8bbe\u7f6e\u8fde\u63a5\u8f93\u5165\u7f13\u51b2\u533a\u4e2d\u6709\u6570\u636e\u65f6\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">SetMessageCallback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> MessageCallback <span class=\"token operator\">&amp;<\/span>cb<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        _message_callback <span class=\"token operator\">&#061;<\/span> cb<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 10.\u8bbe\u7f6e\u8fde\u63a5\u5173\u95ed\u65f6&#xff0c;\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">SetClosedCallback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> ClosedCallback <span class=\"token operator\">&amp;<\/span>cb<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        _closed_callback <span class=\"token operator\">&#061;<\/span> cb<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 11.\u8bbe\u7f6e\u8fde\u63a5\u4efb\u610f\u9636\u6bb5\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">SetAnyEventCallback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> AnyEventCallback <span class=\"token operator\">&amp;<\/span>cb<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        _anyevent_callback <span class=\"token operator\">&#061;<\/span> cb<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 12.\u8bbe\u7f6e\u670d\u52a1\u5668\u8981\u5173\u95ed\u8fde\u63a5\u65f6\u8981\u6267\u884c\u7684\u9636\u6bb5\u6027\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">SetSvrClosedCallback<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> ClosedCallback <span class=\"token operator\">&amp;<\/span>cb<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        _svr_closed_callback <span class=\"token operator\">&#061;<\/span> cb<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h4>2.4\u5bf9\u6210\u5458\u53d8\u91cf\u64cd\u4f5c\u7684\u51fd\u6570<\/h4>\n<p>  <span class=\"token comment\">\/*\u5bf9\u6210\u5458\u53d8\u91cf\u7684\u64cd\u4f5c*\/<\/span><br \/>\n    <span class=\"token comment\">\/\/ 13.\u83b7\u53d6\u8be5\u8fde\u63a5\u7684\u5957\u63a5\u5b57<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> <span class=\"token function\">Fd<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> _sockfd<span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 14.\u83b7\u53d6\u8be5\u8fde\u63a5\u7684\u552f\u4e00\u6807\u8bc6<\/span><br \/>\n    <span class=\"token keyword\">uint64_t<\/span> <span class=\"token function\">Id<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> _conn_id<span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 15.\u5224\u65ad\u5f53\u524d\u9636\u6bb5\u662f\u5426\u662f\u8fde\u63a5\u5b8c\u5168\u521b\u5efa\u6210\u529f&#xff0c;\u5373\u53ef\u6b63\u5e38\u901a\u4fe1\u9636\u6bb5<\/span><br \/>\n    <span class=\"token keyword\">bool<\/span> <span class=\"token function\">IsConnected<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> _status <span class=\"token operator\">&#061;&#061;<\/span> CONNECTED<span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ 16.\u8bbe\u7f6e\u4e0a\u4e0b\u6587<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">SetContext<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> Any <span class=\"token operator\">&amp;<\/span>context<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ 17\u83b7\u53d6\u4e0a\u4e0b\u6587<\/span><br \/>\n    Any <span class=\"token operator\">*<\/span><span class=\"token function\">GetContext<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb837\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u4e0d\u8fc7\u6709\u4e00\u4e2a\u6ce8\u610f\u70b9\uff0c\u5c31\u662fSend()\u51fd\u6570\uff0c\u5c06\u670d\u52a1\u5668\u5904\u7406\u5b8c\u7684\u6570\u636e\u653e\u5165\u5230\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\uff0c\u8fd9\u4e2a\u5916\u754c\u4f20\u5165\u7684data\u6570\u636e\u53ef\u80fd\u662f\u4e00\u4e2a\u4e34\u65f6\u7684\u6570\u636e\uff0c\u800cSend\u51fd\u6570\u53ea\u662f\u5c06\u53d1\u9001\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\uff0c\u6709\u53ef\u80fd\u6ca1\u6709\u88ab\u7acb\u523b\u6267\u884c\uff0c\u6240\u4ee5\u5f53\u771f\u6b63\u6267\u884c\u65f6\uff0c\u5b58\u50a8\u8fd9\u4e2adata\u6570\u636e\u7684\u7a7a\u95f4\u5df2\u7ecf\u88ab\u91ca\u653e\u4e86\uff0c\u5c31\u65e0\u6cd5\u518d\u53bb\u8bbf\u95ee\u4e86\uff0c\u6240\u4ee5\u5728Send()\u51fd\u6570\u8fd8\u6ca1\u6709\u5c06\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\u65f6\uff0c\u5148\u5c06\u8fd9\u4e2a\u7a7a\u95f4\u7684\u6570\u636e\u62f7\u8d1d\u51fa\u6765\uff0c\u7528\u4e00\u4e2abuffer\u5bf9\u8c61\u5b58\u50a8\uff0c\u7136\u540e\u4f20\u5165\u4f20\u5165\u7ed9SendInLoop,SendInLoop\u8bbf\u95ee\u7684\u5c31\u662fbuffer\u4e00\u4e2a\u62f7\u8d1d\u5bf9\u8c61\u3002\u7136\u540e\u76f4\u63a5\u771f\u6b63\u7684\u91ca\u653e\u8fde\u63a5\u3002<\/p>\n","protected":false},"author":2,"featured_media":48143,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[84,43,78,185],"topic":[],"class_list":["post-48144","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-android","tag-43","tag-78","tag-185"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/48144.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb837\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u4e0d\u8fc7\u6709\u4e00\u4e2a\u6ce8\u610f\u70b9\uff0c\u5c31\u662fSend()\u51fd\u6570\uff0c\u5c06\u670d\u52a1\u5668\u5904\u7406\u5b8c\u7684\u6570\u636e\u653e\u5165\u5230\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\uff0c\u8fd9\u4e2a\u5916\u754c\u4f20\u5165\u7684data\u6570\u636e\u53ef\u80fd\u662f\u4e00\u4e2a\u4e34\u65f6\u7684\u6570\u636e\uff0c\u800cSend\u51fd\u6570\u53ea\u662f\u5c06\u53d1\u9001\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\uff0c\u6709\u53ef\u80fd\u6ca1\u6709\u88ab\u7acb\u523b\u6267\u884c\uff0c\u6240\u4ee5\u5f53\u771f\u6b63\u6267\u884c\u65f6\uff0c\u5b58\u50a8\u8fd9\u4e2adata\u6570\u636e\u7684\u7a7a\u95f4\u5df2\u7ecf\u88ab\u91ca\u653e\u4e86\uff0c\u5c31\u65e0\u6cd5\u518d\u53bb\u8bbf\u95ee\u4e86\uff0c\u6240\u4ee5\u5728Send()\u51fd\u6570\u8fd8\u6ca1\u6709\u5c06\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\u65f6\uff0c\u5148\u5c06\u8fd9\u4e2a\u7a7a\u95f4\u7684\u6570\u636e\u62f7\u8d1d\u51fa\u6765\uff0c\u7528\u4e00\u4e2abuffer\u5bf9\u8c61\u5b58\u50a8\uff0c\u7136\u540e\u4f20\u5165\u4f20\u5165\u7ed9SendInLoop,SendInLoop\u8bbf\u95ee\u7684\u5c31\u662fbuffer\u4e00\u4e2a\u62f7\u8d1d\u5bf9\u8c61\u3002\u7136\u540e\u76f4\u63a5\u771f\u6b63\u7684\u91ca\u653e\u8fde\u63a5\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/48144.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T02:53:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730025343-68898937b5df1.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/48144.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/48144.html\",\"name\":\"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T02:53:55+00:00\",\"dateModified\":\"2025-07-30T02:53:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/48144.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/48144.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/48144.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/48144.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb837\u6b21\uff0c\u70b9\u8d5e9\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u4e0d\u8fc7\u6709\u4e00\u4e2a\u6ce8\u610f\u70b9\uff0c\u5c31\u662fSend()\u51fd\u6570\uff0c\u5c06\u670d\u52a1\u5668\u5904\u7406\u5b8c\u7684\u6570\u636e\u653e\u5165\u5230\u7528\u6237\u6001\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\uff0c\u8fd9\u4e2a\u5916\u754c\u4f20\u5165\u7684data\u6570\u636e\u53ef\u80fd\u662f\u4e00\u4e2a\u4e34\u65f6\u7684\u6570\u636e\uff0c\u800cSend\u51fd\u6570\u53ea\u662f\u5c06\u53d1\u9001\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\uff0c\u6709\u53ef\u80fd\u6ca1\u6709\u88ab\u7acb\u523b\u6267\u884c\uff0c\u6240\u4ee5\u5f53\u771f\u6b63\u6267\u884c\u65f6\uff0c\u5b58\u50a8\u8fd9\u4e2adata\u6570\u636e\u7684\u7a7a\u95f4\u5df2\u7ecf\u88ab\u91ca\u653e\u4e86\uff0c\u5c31\u65e0\u6cd5\u518d\u53bb\u8bbf\u95ee\u4e86\uff0c\u6240\u4ee5\u5728Send()\u51fd\u6570\u8fd8\u6ca1\u6709\u5c06\u64cd\u4f5c\u538b\u5165\u5230\u4efb\u52a1\u961f\u5217\u4e2d\u65f6\uff0c\u5148\u5c06\u8fd9\u4e2a\u7a7a\u95f4\u7684\u6570\u636e\u62f7\u8d1d\u51fa\u6765\uff0c\u7528\u4e00\u4e2abuffer\u5bf9\u8c61\u5b58\u50a8\uff0c\u7136\u540e\u4f20\u5165\u4f20\u5165\u7ed9SendInLoop,SendInLoop\u8bbf\u95ee\u7684\u5c31\u662fbuffer\u4e00\u4e2a\u62f7\u8d1d\u5bf9\u8c61\u3002\u7136\u540e\u76f4\u63a5\u771f\u6b63\u7684\u91ca\u653e\u8fde\u63a5\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/48144.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T02:53:55+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730025343-68898937b5df1.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/48144.html","url":"https:\/\/www.wsisp.com\/helps\/48144.html","name":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T02:53:55+00:00","dateModified":"2025-07-30T02:53:55+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/48144.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/48144.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/48144.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u4effmuduo\u5e93\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668\u3011Connection\u6a21\u5757"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/48144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=48144"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/48144\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/48143"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=48144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=48144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=48144"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=48144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}