{"id":8229,"date":"2025-04-18T16:29:21","date_gmt":"2025-04-18T08:29:21","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/8229.html"},"modified":"2025-04-18T16:29:21","modified_gmt":"2025-04-18T08:29:21","slug":"%e3%80%90%e9%a1%b9%e7%9b%ae%e6%97%a5%e8%ae%b0%e3%80%91%e9%ab%98%e5%b9%b6%e5%8f%91%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%a1%b9%e7%9b%ae%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/8229.html","title":{"rendered":"\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418082916-68020d5c49feb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p> <font color=\"#e27d60\" size=\"4\">\u751f\u6d3b\u603b\u662f\u8ba9\u6211\u4eec\u904d\u4f53\u9cde\u4f24&#xff0c; <\/font> <\/p>\n<p>  <font color=\"#e27d60\" size=\"4\">\u4f46\u5230\u540e\u6765&#xff0c; <\/font> <\/p>\n<p>   <font color=\"#e27d60\" size=\"4\">\u90a3\u4e9b\u53d7\u4f24\u7684\u5730\u65b9\u4e00\u5b9a\u4f1a\u53d8\u6210\u6211\u4eec\u6700\u5f3a\u58ee\u7684\u5730\u65b9\u3002 <\/font> <\/p>\n<p>    <font color=\"#e27d60\" size=\"4\"> &#8212; \u300a\u8001\u4eba\u4e0e\u6d77\u300b&#8211; <\/font> <\/p>\n<hr \/>\n<h4>\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3<\/h4>\n<ul>\n<li>\u6a21\u5757\u5173\u7cfb\u56fe<\/li>\n<li>\u9879\u76ee\u5de5\u5177\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>\u7f13\u51b2\u533a\u6a21\u5757<\/li>\n<li>\u901a\u7528\u7c7b\u578b\u6a21\u5757<\/li>\n<li>\u5957\u63a5\u5b57socket\u6a21\u5757<\/li>\n<li>\u4fe1\u9053Channel\u6a21\u5757<\/li>\n<li>\u591a\u8def\u8f6c\u63a5Poller\u6a21\u5757<\/li>\n<\/ul>\n<\/li>\n<li>Reactor\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>\u65f6\u95f4\u8f6eTimeWheel\u6a21\u5757<\/li>\n<\/ul>\n<\/li>\n<li>\u8fde\u63a5Connection\u6a21\u5757<\/li>\n<li>Accepter\u6a21\u5757<\/li>\n<li>TcpServer\u6a21\u5757<\/li>\n<\/ul>\n<h2>\u6a21\u5757\u5173\u7cfb\u56fe<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418082916-68020d5cd6e89.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u9879\u76ee\u5de5\u5177\u6a21\u5757<\/h2>\n<h3>\u7f13\u51b2\u533a\u6a21\u5757<\/h3>\n<p>\u5e95\u5c42\u4f7f\u7528\u5b57\u7b26\u5bb9\u5668\u50a8\u5b58\u6570\u636e&#xff0c;\u901a\u8fc7\u4e24\u4e2a\u6307\u9488&#xff1a;\u8bfb\u504f\u79fb\u548c\u5199\u504f\u79fb\u7ba1\u7406\u7a7a\u95f4&#xff1a;<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u5199\u5165&#xff1a;\u786e\u4fdd\u7a7a\u95f4\u8db3\u591f&#xff0c;\u5728\u5199\u504f\u79fb\u540e\u62f7\u8d1d\u6570\u636e&#xff0c;\u5199\u504f\u79fb\u5411\u540e\u79fb\u52a8<\/li>\n<li>\u5bf9\u4e8e\u8bfb\u53d6&#xff1a;\u786e\u4fdd\u53ef\u8bfb\u6570\u636e\u8db3\u591f&#xff0c;\u5728\u8bfb\u504f\u79fb\u540e\u8bfb\u53d6\u6570\u636e&#xff0c;\u8bfb\u504f\u79fb\u5411\u540e\u79fb\u52a8<\/li>\n<li>\u7a7a\u95f4\u4e0d\u8db3\u65f6\u53ca\u65f6\u6269\u5bb9<\/li>\n<\/ul>\n<h3>\u901a\u7528\u7c7b\u578b\u6a21\u5757<\/h3>\n<p>\u60f3\u8981\u5b9e\u73b0\u7684\u6548\u679c&#xff1a;<\/p>\n<p>Any a<span class=\"token punctuation\">;<\/span><br \/>\na <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">123<\/span><span class=\"token punctuation\">;<\/span><br \/>\na <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;123&#034;<\/span><br \/>\na <span class=\"token operator\">&#061;<\/span> vector<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">(<\/span>n <span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u79cd\u6548\u679c&#xff0c;\u9996\u5148Any\u7c7b\u80af\u5b9a\u4e0d\u80fd\u5e26\u6709\u6a21\u7248\u53c2\u6570&#xff0c;\u4e0d\u7136\u5c31\u4e0d\u80fd\u81ea\u7531\u8f6c\u6362\u4e86&#xff01;<\/p>\n<ul>\n<li>\u53ef\u4ee5\u5728\u5185\u90e8\u8bbe\u8ba1\u4e00\u4e2a\u5185\u90e8\u7c7bplaceholder&#xff08;\u7ee7\u627fholder\u7236\u7c7b&#xff09;&#xff0c;\u5b83\u662f\u4e00\u4e2a\u6a21\u677f\u7c7b&#xff0c;\u662f\u5b9e\u9645\u50a8\u5b58\u6570\u636e\u7684\u5bf9\u8c61&#xff1b;<\/li>\n<li>\u5f53\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2aAny\u5bf9\u8c61\u65f6&#xff0c;\u4f1a\u521b\u5efa\u4e00\u4e2a\u7236\u7c7b\u6307\u9488&#xff0c;\u7ba1\u7406placeholder\u5bf9\u8c61<\/li>\n<li>\u901a\u8fc7\u6a21\u7248\u51fd\u6570&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u5bf9placeholder\u5bf9\u8c61\u8d4b\u503c\u3002<\/li>\n<li>\u53ef\u4ee5\u901a\u8fc7\u4ea4\u6362placeholder\u5bf9\u8c61\u7ba1\u7406\u7684\u8d44\u6e90\u5b9e\u73b0\u81ea\u7531\u8d4b\u503c\u3002<\/li>\n<\/ul>\n<h3>\u5957\u63a5\u5b57socket\u6a21\u5757<\/h3>\n<p>\u8fd9\u4e2a\u6a21\u5757\u5bf9\u5916\u63d0\u4f9b\u4e00\u952e\u521b\u5efa\u670d\u52a1\u7aef\u5957\u63a5\u5b57\u548c\u5ba2\u6237\u7aef\u5957\u63a5\u5b57\u7684\u65b9\u6cd5&#xff08;\u662f\u5bf9\u5185\u90e8\u63a5\u53e3\u7684\u4e00\u4e2a\u5c01\u88c5&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa\u5957\u63a5\u5b57\u63a5\u53e3&#xff1a;\u4ee5\u6570\u636e\u6d41\u7684\u65b9\u5f0f\u521b\u5efa\u4e00\u4e2a\u5957\u63a5\u5b57\u6587\u4ef6<\/li>\n<li>\u7ed1\u5b9a\u7aef\u53e3\u4fe1\u606f<\/li>\n<li>\u8fdb\u5165\u76d1\u542c\u6a21\u5f0f<\/li>\n<li>\u53d1\u8d77\u8fde\u63a5&#xff1a;\u7ec4\u7ec7\u76ee\u6807\u7aef\u53e3\u4fe1\u606f&#xff0c;\u8fdb\u884c\u7533\u8bf7\u8fde\u63a5<\/li>\n<li>\u542f\u52a8\u5730\u5740\u91cd\u7528&#xff1a;\u53ef\u4ee5\u5feb\u901f\u91cd\u542f\u670d\u52a1&#xff0c;\u8df3\u8fc7\u7cfb\u7edf\u91ca\u653e\u7aef\u53e3\u7684\u65f6\u95f4&#xff1b;\u5141\u8bb8\u591a\u4e2a socket \u76d1\u542c\u76f8\u540c\u7684\u5730\u5740\u548c\u7aef\u53e3&#xff1b;\u907f\u514d\u5730\u5740\u5df2\u5728\u4f7f\u7528\u9519\u8bef\u3002<\/li>\n<li>\u8bbe\u7f6e\u975e\u963b\u585e\u8bfb\u53d6<\/li>\n<\/ul>\n<p>\u5bf9\u5916\u63d0\u4f9b\u7684\u63a5\u53e3<\/p>\n<li>\u6784\u5efa\u670d\u52a1\u7aef\u5957\u63a5\u5b57&#xff1a;\u521b\u5efa\u5957\u63a5\u5b57&#xff0c;\u8bbe\u7f6e\u4e3a\u975e\u963b\u585e&#xff0c;\u5c06\u5730\u5740\u4e0e\u7aef\u53e3\u8bbe\u7f6e\u4e3a\u53ef\u91cd\u7528&#xff0c;\u7ed1\u5b9a\u5730\u5740\u4fe1\u606f&#xff0c;\u8fdb\u884c\u76d1\u542c\u3002<\/li>\n<li>\u6784\u5efa\u5ba2\u6237\u7aef\u5957\u63a5\u5b57&#xff1a;\u521b\u5efa\u5957\u63a5\u5b57&#xff0c;\u8fde\u63a5\u670d\u52a1\u5668<\/li>\n<li>\u53d1\u9001\u6570\u636e<\/li>\n<li>\u63a5\u6536\u6570\u636e<\/li>\n<h3>\u4fe1\u9053Channel\u6a21\u5757<\/h3>\n<p>\u8be5\u6a21\u5757\u662f\u7528\u6765\u7ba1\u7406\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684&#xff0c;\u5bf9\u8be5\u63cf\u8ff0\u7b26\u7684\u4e8b\u4ef6\u8fdb\u884c\u76d1\u63a7&#xff0c;\u89e6\u53d1\u4e8b\u4ef6\u5c31\u8c03\u7528\u5bf9\u5e94\u7684\u56de\u8c03\u51fd\u6570&#xff1a;<\/p>\n<ul>\n<li>\u5f53\u524d\u9700\u8981\u76d1\u63a7\u7684\u4e8b\u4ef6\u96c6<\/li>\n<li>\u5f53\u524d\u8fde\u63a5\u89e6\u53d1\u7684\u4e8b\u4ef6\u96c6<\/li>\n<li>\u7ba1\u7406\u8be5\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684Reactor\u6a21\u578b(EventLoop)<\/li>\n<li>\u53ef\u8bfb\u4e8b\u4ef6\u89e6\u53d1\u7684\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u53ef\u5199\u4e8b\u4ef6\u89e6\u53d1\u7684\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u9519\u8bef\u4e8b\u4ef6\u89e6\u53d1\u7684\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u65ad\u5f00\u4e8b\u4ef6\u89e6\u53d1\u7684\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u4efb\u610f\u4e8b\u4ef6\u89e6\u53d1\u7684\u56de\u8c03\u51fd\u6570<\/li>\n<\/ul>\n<p>\u63d0\u4f9b\u4e00\u7cfb\u5217\u63a5\u53e3\u5e2e\u52a9\u6211\u4eec\u7ba1\u7406\u5bf9\u8be5\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u76d1\u63a7\u3002\u89e6\u53d1\u4e8b\u4ef6\u901a\u8fc7HandleEvent()\u51fd\u6570\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<h3>\u591a\u8def\u8f6c\u63a5Poller\u6a21\u5757<\/h3>\n<p>\u8be5\u6a21\u5757\u662f\u5bf9epoll\u63a5\u53e3\u7684\u4e8c\u6b21\u5c01\u88c5&#xff0c;\u7ba1\u7406\u4e00\u7cfb\u5217\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\u5185\u90e8\u50a8\u5b58\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0e\u5176\u5bf9\u5e94\u7684\u4fe1\u9053Channel&#xff1b; \u53ef\u4ee5\u901a\u8fc7\u4fe1\u9053\u5bf9epoll\u4e2d\u76d1\u63a7\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u66f4\u65b0\u76d1\u63a7\u4e8b\u4ef6\u96c6 \u63d0\u4f9b\u4e00\u4e2a\u5f00\u59cb\u76d1\u63a7\u63a5\u53e3Poll&#xff0c;\u8be5\u51fd\u6570\u4e2d\u963b\u585e\u5f0f\u7b49\u5f85\u4e8b\u4ef6\u5c31\u7eea\u3002\u5f97\u5230\u5c31\u7eea\u4e8b\u4ef6\u5c31\u8fdb\u884c\u5c06\u5c31\u7eea\u4e8b\u4ef6\u66f4\u65b0\u5230\u5bf9\u5e94\u7684\u4fe1\u9053\u4e2d&#xff0c;\u7136\u540e\u5c06\u4fe1\u9053\u653e\u5165\u6d3b\u8dc3\u961f\u5217\u4e2d\u7b49\u5f85\u4e0a\u5c42\u5904\u7406\u3002<\/p>\n<h2>Reactor\u6a21\u5757<\/h2>\n<h3>\u65f6\u95f4\u8f6eTimeWheel\u6a21\u5757<\/h3>\n<p>\u65f6\u95f4\u8f6e\u6a21\u5757\u662f\u7528\u6765\u6267\u884c\u5b9a\u65f6\u4efb\u52a1\u7684&#xff0c;\u9879\u76ee\u4e2d\u53ef\u4ee5\u7528\u6765\u7ba1\u7406\u8d85\u65f6\u8fde\u63a5&#xff0c;\u53ca\u65f6\u8fdb\u884c\u91ca\u653e\u64cd\u4f5c\u3002 \u4e3a\u4e86\u53ef\u4ee5\u5b9e\u73b0\u5b9a\u65f6\u6267\u884c\u4efb\u52a1&#xff0c;\u9996\u5148\u9700\u8981\u5bf9\u5c01\u88c5\u51fa\u4e00\u4e2a\u4efb\u52a1\u5bf9\u8c61Timer:<\/p>\n<ul>\n<li>\u4efb\u52a1ID uint64_t _id &#xff1a;\u7528\u6765\u6807\u8bc6\u4efb\u52a1<\/li>\n<li>\u8d85\u65f6\u65f6\u95f4 uint32_t _timeout;<\/li>\n<li>\u662f\u5426\u88ab\u53d6\u6d88&#xff1a;bool _canceled; \u8fd9\u6837\u53d6\u6d88\u4efb\u52a1\u65f6&#xff0c;\u901a\u8fc7\u54c8\u5e0c\u8868\u627e\u5230\u5bf9\u5e94\u4efb\u52a1&#xff0c;\u8bbe\u7f6e\u8be5\u6807\u5fd7\u4f4d\u5c31\u597d\u4e86&#xff0c;\u6548\u7387\u9ad8&#xff01;<\/li>\n<li>\u56de\u8c03\u4efb\u52a1 _task_cb void()\u7c7b\u578b<\/li>\n<li>\u91ca\u653e\u64cd\u4f5c\u51fd\u6570 _release &#xff1a;\u7528\u4e8e\u5220\u9664TimeWheel\u4fdd\u5b58\u7684\u5b9a\u65f6\u5668\u5bf9\u8c61\u4fe1\u606f<\/li>\n<li>\u4efb\u52a1\u91ca\u653e\u65f6\u6267\u884c\u56de\u8c03\u51fd\u6570<\/li>\n<\/ul>\n<p>\u65f6\u95f4\u8f6eTimeWheel\u7684\u672c\u8d28\u662f\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u4e00\u4e2a\u6307\u9488\u5b9a\u65f6\u79fb\u52a8&#xff0c;\u5230\u54ea\u91cc\u5c31\u91ca\u653e\u8be5\u4f4d\u7f6e\u7684\u6240\u6709\u4efb\u52a1Timer\u3002<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">TimeWheel<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> TaskPtr <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span>shared_ptr<span class=\"token operator\">&lt;<\/span>Timer<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> WeakPtr <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span>weak_ptr<span class=\"token operator\">&lt;<\/span>Timer<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8f85\u52a9shared_ptr \u4e0d\u4f1a\u589e\u52a0\u5f15\u7528\u8ba1\u6570<\/span><br \/>\n<span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _capacity<span class=\"token punctuation\">;<\/span>                                 <span class=\"token comment\">\/\/ \u6700\u5927\u5bb9\u91cf \u8868\u76d8\u6700\u5927\u6570\u91cf&#xff08;\u9ed8\u8ba460\u79d2&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _tick<span class=\"token punctuation\">;<\/span>                                     <span class=\"token comment\">\/\/ \u79fb\u52a8\u8868\u9488<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>TaskPtr<span class=\"token operator\">&gt;&gt;<\/span> _wheel<span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u65f6\u95f4\u8f6e<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>unordered_map<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">uint64_t<\/span><span class=\"token punctuation\">,<\/span> WeakPtr<span class=\"token operator\">&gt;<\/span> _timers<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5b9a\u65f6\u4efb\u52a1\u5bf9\u8c61\u54c8\u5e0c\u8868<\/span><\/p>\n<p>    <span class=\"token keyword\">int<\/span> _timerfd<span class=\"token punctuation\">;<\/span>                            <span class=\"token comment\">\/\/ \u5b9a\u65f6\u5668fd<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span>_loop<span class=\"token punctuation\">;<\/span>                        <span class=\"token comment\">\/\/ \u5bf9\u5e94\u7684Eventfd<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>unique_ptr<span class=\"token operator\">&lt;<\/span>Channel<span class=\"token operator\">&gt;<\/span> _timer_channel<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7ba1\u7406_timerfd\u7684channel\u7c7b&#xff01;<\/span><br \/>\n    <span class=\"token comment\">\/\/&#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd9\u91cc\u4f7f\u7528\u667a\u80fd\u6307\u9488\u8fdb\u884c\u7ba1\u7406&#xff0c;\u65b9\u4fbf\u64cd\u4f5c\u3002\u5f15\u7528\u8ba1\u6570\u5f52\u96f6\u65f6\u81ea\u52a8\u91ca\u653e\u3002\u8bbe\u7f6e\u4e00\u4e2atimefd&#xff0c;\u7cfb\u7edf\u6bcf1s\u90fd\u4f1a\u60f3\u5176\u4e2d\u5199\u5165\u4e00\u4e2a1\u3002\u8bfb\u53d6\u5230\u6570\u636e&#xff0c;\u5c31\u79fb\u52a8\u6307\u9488&#xff0c;\u91ca\u653e\u8be5\u65f6\u95f4\u7684\u5b9a\u65f6\u4efb\u52a1\u6307\u9488\u3002 EventLoop\u6a21\u5757 \u8be5\u6a21\u5757\u662f\u771f\u6b63\u7684Reactor\u6a21\u578b,\u7ba1\u7406\u4e00\u4e0b\u6570\u636e&#xff1a;<\/p>\n<p>    std<span class=\"token operator\">::<\/span>thread<span class=\"token operator\">::<\/span>id _event_id<span class=\"token punctuation\">;<\/span>               <span class=\"token comment\">\/\/ \u7ebf\u7a0bID<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _eventfd<span class=\"token punctuation\">;<\/span>                            <span class=\"token comment\">\/\/ eventfd \u7528\u4e8e\u901a\u77e5\u4e8b\u4ef6<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>unique_ptr<span class=\"token operator\">&lt;<\/span>Channel<span class=\"token operator\">&gt;<\/span> _event_channel<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7ba1\u7406Event\u4e8b\u4ef6\u7684Channel\u5bf9\u8c61<\/span><br \/>\n    Poller _poller<span class=\"token punctuation\">;<\/span>                          <span class=\"token comment\">\/\/ epoll\u6a21\u578b<\/span><\/p>\n<p>    std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>Functor<span class=\"token operator\">&gt;<\/span> _tasks<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u4efb\u52a1\u6c60<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>mutex _mtx<span class=\"token punctuation\">;<\/span>             <span class=\"token comment\">\/\/ \u4e92\u65a5\u9501\u4fdd\u62a4\u7ebf\u7a0b<\/span><\/p>\n<p>    TimeWheel _timer_wheel<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u65f6\u95f4\u8f6e<\/span><\/p>\n<p>\u8be5\u6a21\u5757\u7684\u6267\u884c\u903b\u8f91\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\u901a\u8fc7EventLoop\u6a21\u5757\u901a\u8fc7\u7684\u63a5\u53e3\u53ef\u4ee5\u6dfb\u52a0\u7ba1\u7406\u7684\u4fe1\u9053&#xff08;\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff09;<\/li>\n<li>\u542f\u52a8\u76d1\u63a7\u540e&#xff0c;\u5bf9epoll\u4e2d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7\u3002<\/li>\n<li>Poller\u6a21\u5757Poll\u51fd\u6570\u4e2d\u8fd4\u56de\u5c31\u7eea\u7684\u6d3b\u8dc3\u4fe1\u9053\u96c6\u3002<\/li>\n<li>\u5bf9\u6bcf\u4e2a\u6d3b\u8dc3\u4fe1\u9053\u6267\u884chandleEvent\u5904\u7406\u5c31\u7eea\u4e8b\u4ef6<\/li>\n<li>\u5bf9\u4e8e\u5916\u90e8\u8bbe\u7f6e\u7684\u4efb\u52a1&#xff0c;\u9700\u8981\u4fdd\u8bc1\u662f\u5728\u8be5eventloop\u6240\u5728\u7ebf\u7a0b\u5185\u90e8\u6267\u884c&#xff0c;\u5982\u679c\u4e0d\u662f\u653e\u5165\u4efb\u52a1\u6c60\u4e2d\u7b49\u5f85\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>EventLoop\u6a21\u5757\u4e0eTimeWheel\u6a21\u5757\u6574\u5408 Reactor\u6a21\u578b\u5185\u90e8\u52a0\u5165\u4e00\u4e2a\u65f6\u95f4\u8f6e&#xff0c;\u8d1f\u8d23\u6267\u884c\u8d85\u65f6\u8fde\u63a5\u9500\u6bc1\u4efb\u52a1&#xff0c;\u5bf9\u5916\u63d0\u4f9b\u63a5\u53e3&#xff1a;<\/p>\n<li>Void TimerAdd(uint64_t id, int delay, Task_t cb)&#xff1a;\u52a0\u5165\u5b9a\u65f6\u4efb\u52a1<\/li>\n<li>void TimerRefresh(uint64_t id)&#xff1a;\u5237\u65b0\u5b9a\u65f6\u4efb\u52a1<\/li>\n<li>void TimerCancel(uint64_t id)&#xff1a;\u53d6\u6d88\u5b9a\u65f6\u4efb\u52a1<\/li>\n<li>bool HasTimer(uint64_t id)&#xff1a;\u5224\u65ad\u662f\u5426\u6709\u8be5\u4efb\u52a1<\/li>\n<h2>\u8fde\u63a5Connection\u6a21\u5757<\/h2>\n<p>\u8fde\u63a5\u6a21\u5757\u662f\u5bf9\u4e0a\u9762\u6a21\u5757\u7684\u6574\u4f53\u6574\u5408&#xff0c;\u5177\u6709\u4ee5\u4e0b\u53c2\u6570&#xff1a;<\/p>\n<p>    <span class=\"token keyword\">uint64_t<\/span> _conn_id<span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ connection\u8fde\u63a5ID<\/span><br \/>\n    Socket _socket<span class=\"token punctuation\">;<\/span>              <span class=\"token comment\">\/\/ \u7ba1\u7406\u7684\u5957\u63a5\u5b57<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _sockfd<span class=\"token punctuation\">;<\/span>                 <span class=\"token comment\">\/\/ \u5957\u63a5\u5b57fd<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span>_loop<span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ connection\u8fde\u63a5\u5173\u8054\u7684EventLoop\u5bf9\u8c61<\/span><br \/>\n    Any _context<span class=\"token punctuation\">;<\/span>                <span class=\"token comment\">\/\/ \u4e0a\u4e0b\u6587\u6570\u636e<\/span><br \/>\n    Channel _channel<span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ \u7ba1\u7406\u8fde\u63a5\u4e8b\u4ef6<\/span><br \/>\n    Buffer _in_buffer<span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u8f93\u5165\u7f13\u51b2\u533a \u5b58\u653eSocket\u4e2d\u8bfb\u53d6\u7684\u6570\u636e<\/span><br \/>\n    Buffer _out_buffer<span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u8f93\u51fa\u7f13\u51b2\u533a \u5b58\u653e\u8981\u53d1\u9001\u7ed9\u5bf9\u7aef\u7684\u6570\u636e<\/span><br \/>\n    <span class=\"token keyword\">bool<\/span> _enable_active_release<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u662f\u5426\u5f00\u542f\u8d85\u65f6\u9500\u6bc1 \u9ed8\u8ba4\u662ffalse<\/span><br \/>\n    ConnStatu _statu<span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ Connection\u8fde\u63a5\u72b6\u6001<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 5 \u4e2a \u56de\u8c03\u51fd\u6570 &#8212; \u6ce8\u610f\u4f7f\u7528\u667a\u80fd\u6307\u9488 \u9632\u6b62\u5728\u6267\u884c\u4efb\u52a1\u4e4b\u524dConnection\u9500\u6bc1<\/span><\/p>\n<p>    <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> PtrConn <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u8fde\u63a5\u65f6\u8fdb\u884c\u7684\u56de\u8c03\u51fd\u6570<\/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> PtrConn <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> <span class=\"token comment\">\/\/ \u5904\u7406\u6570\u636e\u65f6\u7684\u56de\u8c03\u51fd\u6570<\/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> PtrConn <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ \u5173\u95ed\u8fde\u63a5\u65f6\u7684\u56de\u8c03\u51fd\u6570<\/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> PtrConn <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u5904\u7406\u4efb\u610f\u4e8b\u4ef6\u65f6\u7684\u56de\u8c03\u51fd\u6570<\/span><\/p>\n<p>    ConnectedCallBack _conn_cb<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8fde\u63a5\u56de\u8c03\u51fd\u6570\u7c7b\u578b<\/span><br \/>\n    MessageCallBack _message_cb<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5904\u7406\u65f6\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    ClosedCallBack _closed_cb<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u5173\u95ed\u9636\u6bb5\u7684\u56de\u8c03<\/span><br \/>\n    AnyEventCallBack _event_cb<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u4efb\u610f\u4e8b\u4ef6\u89e6\u53d1\u7684\u56de\u8c03<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u8fd8\u9700\u8981\u7ec4\u4ef6\u5185\u7684\u8fde\u63a5\u5173\u95ed\u56de\u8c03 \u56e0\u4e3a\u670d\u52a1\u5668\u7ec4\u4ef6\u5185\u4f1a\u628a\u6240\u6709\u7684\u8fde\u63a5\u7ba1\u7406\u8d77\u6765 \u4e00\u65e6\u67d0\u4e2a\u8fde\u63a5\u5173\u95ed \u5c31\u5e94\u8be5\u4ece\u7ba1\u7406\u7684\u5730\u65b9\u79fb\u9664\u81ea\u5df1\u7684\u4fe1\u606f&#xff01;<\/span><br \/>\n    ClosedCallBack _event_closed_cb<span class=\"token punctuation\">;<\/span><\/p>\n<ul>\n<li>\u8be5\u8fde\u63a5\u7ba1\u7406\u7684\u5e95\u5c42\u5957\u63a5\u5b57<\/li>\n<li>\u7ba1\u7406\u8be5\u5957\u63a5\u5b57\u7684\u4fe1\u9053&#xff1a;\u7528\u4e8e\u5904\u7406\u65b0\u8fde\u63a5\u4e8b\u4ef6<\/li>\n<li>\u8fde\u63a5\u5173\u8054\u7684EventLoop\u6a21\u5757&#xff0c;\u7528\u4e8e\u4e8b\u4ef6\u76d1\u63a7<\/li>\n<li>\u901a\u7528\u7c7b\u578b\u4e0a\u4e0b\u6587<\/li>\n<li>\u8f93\u5165\/\u8f93\u51fa\u7f13\u51b2\u533a<\/li>\n<li>\u65b0\u8fde\u63a5\/\u5904\u7406\u6d88\u606f\/\u5173\u95ed\u8fde\u63a5\/\u4efb\u610f\u4e8b\u4ef6 \u56de\u8c03\u51fd\u6570<\/li>\n<li>\u8fde\u63a5\u5185\u90e8\u8fde\u63a5\u5173\u95ed\u51fd\u6570<\/li>\n<\/ul>\n<p>\u5185\u90e8\u63d0\u4f9b\u7684\u51fd\u6570&#xff1a;<\/p>\n<li>\u9996\u5148\u662f\u8be5\u8fde\u63a5\u5185\u90e8\u9047\u5230\u4e8b\u4ef6\u7684\u51fd\u6570&#xff0c;\u4f5c\u4e3a\u4fe1\u9053\u7684\u56de\u8c03\u51fd\u6570\n<ul>\n<li>\u8bfb\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u5199\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570<\/li>\n<li>\u5173\u95ed\u4e8b\u4ef6\u56de\u8c03<\/li>\n<li>\u9519\u8bef\u4e8b\u4ef6\u56de\u8c03<\/li>\n<\/ul>\n<\/li>\n<li>\u7ebf\u7a0b\u5185\u53d1\u9001\u6570\u636e\u51fd\u6570<\/li>\n<li>\u7ebf\u7a0b\u5185\u5173\u95ed\u8fde\u63a5\u51fd\u6570<\/li>\n<li>\u7ebf\u7a0b\u5185\u542f\u52a8\u8d85\u65f6\u7ba1\u7406\u51fd\u6570&#xff1a;\u5c06\u8be5\u8fde\u63a5\u7684\u91ca\u653e\u51fd\u6570Release\u653e\u5165EventLoop\u7684\u65f6\u95f4\u8f6e\u4e2d<\/li>\n<li>\u7ebf\u7a0b\u5185\u53d6\u6d88\u8d85\u65f6\u7ba1\u7406\u51fd\u6570<\/li>\n<li>\u7ebf\u7a0b\u5185\u66f4\u65b0\u56de\u8c03\u51fd\u6570&#xff08;\u534f\u8bae&#xff09;<\/li>\n<li>\u7ebf\u7a0b\u5185\u91ca\u653e\u51fd\u6570ReleaseInLoop&#xff08;\u771f\u6b63\u7684\u91ca\u653e\u51fd\u6570&#xff09;&#xff1a;\u4fee\u6539\u8fde\u63a5\u72b6\u6001&#xff0c;\u53d6\u6d88\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u6267\u884c\u7528\u6237\u8bbe\u7f6e\u7684\u5173\u95ed\u8fde\u63a5\u56de\u8c03\u51fd\u6570&#xff0c;\u901a\u8fc7\u5185\u90e8\u91ca\u653e\u56de\u8c03\u51fd\u6570\u91ca\u653e\u5728\u8fde\u63a5\u5728\u670d\u52a1\u5668\u5185\u7684\u8d44\u6e90\u3002<\/li>\n<p>\u5bf9\u5916\u63d0\u4f9b\u7684\u63a5\u53e3&#xff1a;<\/p>\n<li>\u57fa\u7840\u63a5\u53e3&#xff1a;\u8fd4\u56de\u8fde\u63a5id,\u5957\u63a5\u5b57fd\u2026<\/li>\n<li>\u8bbe\u7f6e\u56de\u8c03\u51fd\u6570\u63a5\u53e3<\/li>\n<li>\u53d1\u9001\u6570\u636e\u63a5\u53e3&#xff1a;\u5728EventLoop\u4e2d\u52a0\u5165\u53d1\u9001\u4efb\u52a1<\/li>\n<li>\u5173\u95ed\u8fde\u63a5\u63a5\u53e3&#xff1a;\u5728EventLoop\u4e2d\u52a0\u5165\u5173\u95ed\u8fde\u63a5\u4efb\u52a1<\/li>\n<li>\u542f\u52a8\u8d85\u65f6\u9500\u6bc1\u63a5\u53e3&#xff1a;\u5728EventLoop\u4e2d\u52a0\u5165\u542f\u52a8\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1<\/li>\n<li>\u53d6\u6d88\u8d85\u65f6\u9500\u6bc1\u63a5\u53e3&#xff1a;\u5728EventLoop\u4e2d\u52a0\u5165\u53d6\u6d88\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1<\/li>\n<li>\u5207\u6362\u534f\u8bae\u63a5\u53e3&#xff1a;\u5728EventLoop\u4e2d\u52a0\u5165\u53d6\u6d88\u5207\u6362\u534f\u8bae\u4efb\u52a1<\/li>\n<h2>Accepter\u6a21\u5757<\/h2>\n<p>\u8be5\u6a21\u5757\u662f\u5bf9\u76d1\u542c\u5957\u63a5\u5b57\u8fdb\u884c\u7ba1\u7406\u7684&#xff1a;<\/p>\n<p>    Socket _socket<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u5957\u63a5\u5b57\u5bf9\u8c61<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span>_loop<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5bf9\u76d1\u542c\u5957\u63a5\u5b57\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7<\/span><br \/>\n    Channel _channel<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7528\u4e8e\u5bf9\u7ba1\u7406\u76d1\u542c\u5957\u63a5\u5b57\u7684\u4e8b\u4ef6<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> AcceptCallBack <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\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    AcceptCallBack _accept_callback<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4e0d\u540c\u4e8e\u4e0d\u540c\u7684\u5957\u63a5\u5b57\u6587\u4ef6&#xff0c;\u76d1\u542c\u5957\u63a5\u5b57\u53ea\u9700\u8981\u8bfb\u53d6\u4e8b\u4ef6\u7684\u56de\u8c03\u51fd\u6570&#xff0c;\u4ece\u76d1\u542c\u5957\u63a5\u5b57\u4e2d\u8bfb\u53d6\u51fa\u65b0\u8fde\u63a5\u7684fd&#xff0c;\u7136\u540e\u5bf9\u8be5fd\u6267\u884c\u83b7\u53d6\u8fde\u63a5\u7684\u56de\u8c03\u51fd\u6570\u3002<\/p>\n<p>\u7ebf\u7a0b\u6c60\u6a21\u5757 \u6211\u4eec\u5148\u5bf9\u7ebf\u7a0b\u8fdb\u884c\u5c01\u88c5&#xff0c;\u4f7f\u5176\u5305\u542bEventLoop\u6a21\u5757\u3002\u7ebf\u7a0b\u4e2d\u9700\u8981\u6267\u884c\u7684\u51fd\u6570\u5c31\u662f\u521b\u5efa\u4e00\u4e2aEventLoop&#xff0c;\u7136\u540e\u6267\u884cStart\u76d1\u63a7\u3002<\/p>\n<p>\u7ebf\u7a0b\u6c60\u5bf9\u82e5\u5e72\u4e2a\u7ebf\u7a0b\u8fdb\u884c\u7ba1\u7406&#xff1a;<\/p>\n<p>    <span class=\"token keyword\">int<\/span> _thread_size<span class=\"token punctuation\">;<\/span>                   <span class=\"token comment\">\/\/ \u4ece\u5c5e\u7ebf\u7a0b\u6570\u91cf<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _next_idx<span class=\"token punctuation\">;<\/span>                      <span class=\"token comment\">\/\/ \u7ebf\u7a0b\u7d22\u5f15<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>LoopThread <span class=\"token operator\">*<\/span><span class=\"token operator\">&gt;<\/span> _threads<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7ba1\u7406\u4ece\u5c5e\u7ebf\u7a0b<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>EventLoop <span class=\"token operator\">*<\/span><span class=\"token operator\">&gt;<\/span> _loops<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u7ba1\u7406\u4ece\u5c5eReactor<\/span><br \/>\n    EventLoop <span class=\"token operator\">*<\/span>_baseloop<span class=\"token punctuation\">;<\/span>               <span class=\"token comment\">\/\/ \u4e3bReactor<\/span><\/p>\n<p>\u6bcf\u6b21\u53d6\u51fa\u4e00\u4e2a\u7ebf\u7a0b\u5bf9\u5916\u63d0\u4f9b\u65f6&#xff0c;\u53ea\u9700\u63d0\u4f9b\u7ebf\u7a0b\u5bf9\u5e94\u7684EventLoop\u5373\u53ef<\/p>\n<h2>TcpServer\u6a21\u5757<\/h2>\n<p>\u8fd9\u4e2a\u6a21\u5757\u5c31\u662f\u6700\u7ec8\u7684\u670d\u52a1\u5668\u6a21\u5757\u3002\u4e3bReactor\u5bf9\u76d1\u542c\u5957\u63a5\u5b57\u7684\u8fdb\u884c\u7ba1\u7406&#xff0c;\u83b7\u53d6\u5230\u65b0\u8fde\u63a5\u540e\u5c31\u5c06\u8fde\u63a5\u4ea4\u7ed9\u4e00\u4e2a\u7ebf\u7a0b\u4e2d\u7684\u4ece\u5c5eReactor\u8fdb\u884c\u76d1\u63a7\u3002\u8fdb\u800c\u5b9e\u73b0\u9ad8\u5e76\u53d1\u7684\u670d\u52a1\u5668&#xff01;<\/p>\n<p>\u8be5\u6a21\u5757\u7ba1\u7406\u7684\u6210\u5458\u53d8\u91cf&#xff1a;<\/p>\n<p>    <span class=\"token keyword\">uint64_t<\/span> _conn_id<span class=\"token punctuation\">;<\/span>                            <span class=\"token comment\">\/\/ \u81ea\u589e\u957f\u7684\u8fde\u63a5ID;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _port<span class=\"token punctuation\">;<\/span>                                    <span class=\"token comment\">\/\/ \u7ed1\u5b9a\u7684\u7aef\u53e3\u53f7<\/span><br \/>\n    EventLoop _baseloop<span class=\"token punctuation\">;<\/span>                          <span class=\"token comment\">\/\/ \u4e3bReactor\u6a21\u578b<\/span><br \/>\n    Acceptor _acceptor<span class=\"token punctuation\">;<\/span>                           <span class=\"token comment\">\/\/ \u76d1\u542c\u5957\u63a5\u5b57<\/span><br \/>\n    LoopThreadPool _pool<span class=\"token punctuation\">;<\/span>                         <span class=\"token comment\">\/\/ \u4ece\u5c5e\u7ebf\u7a0b\u6c60<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>unordered_map<span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">uint64_t<\/span><span class=\"token punctuation\">,<\/span> PtrConn<span class=\"token operator\">&gt;<\/span> _conns<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u7ba1\u7406\u8fde\u63a5\u7684\u54c8\u5e0c\u8868<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> _timeout<span class=\"token punctuation\">;<\/span>                                 <span class=\"token comment\">\/\/ \u8d85\u65f6\u65f6\u95f4<\/span><br \/>\n    <span class=\"token keyword\">bool<\/span> _enable_active_release<span class=\"token punctuation\">;<\/span>                  <span class=\"token comment\">\/\/ \u662f\u5426\u5f00\u542f\u8d85\u65f6\u9500\u6bc1 \u9ed8\u8ba4\u662ffalse<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 4\u79cd \u56de\u8c03\u51fd\u6570 &#8212; \u6ce8\u610f\u4f7f\u7528\u667a\u80fd\u6307\u9488 \u9632\u6b62\u5728\u6267\u884c\u4efb\u52a1\u4e4b\u524dConnection\u9500\u6bc1<\/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> PtrConn <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u8fde\u63a5\u65f6\u8fdb\u884c\u7684\u56de\u8c03\u51fd\u6570<\/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> PtrConn <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> <span class=\"token comment\">\/\/ \u5904\u7406\u6570\u636e\u65f6\u7684\u56de\u8c03\u51fd\u6570<\/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> PtrConn <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ \u5173\u95ed\u8fde\u63a5\u65f6\u7684\u56de\u8c03\u51fd\u6570<\/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> PtrConn <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u5904\u7406\u4efb\u610f\u4e8b\u4ef6\u65f6\u7684\u56de\u8c03\u51fd\u6570<\/span><\/p>\n<p>    ConnectedCallBack _conn_cb<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8fde\u63a5\u56de\u8c03\u51fd\u6570\u7c7b\u578b<\/span><br \/>\n    MessageCallBack _message_cb<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5904\u7406\u65f6\u56de\u8c03\u51fd\u6570<\/span><br \/>\n    ClosedCallBack _closed_cb<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u5173\u95ed\u9636\u6bb5\u7684\u56de\u8c03<\/span><br \/>\n    AnyEventCallBack _event_cb<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u4efb\u610f\u4e8b\u4ef6\u89e6\u53d1\u7684\u56de\u8c03<\/span><\/p>\n<li>\u63d0\u4f9b\u7ed9Accepterd\u7684\u56de\u8c03\u51fd\u6570NewConnection&#xff0c;\u5728\u8be5\u51fd\u6570\u4e2d\u5bf9\u8fde\u63a5\u8d4b\u4e88\u4e00\u4e2aid,\u5e76\u8bbe\u7f6e\u8fde\u63a5\u7684\u56de\u8c03\u51fd\u6570&#xff0c;\u5c06\u8be5\u8fde\u63a5\u4ea4\u7ed9\u7ebf\u7a0b\u6c60\u4e2d\u7684\u4e00\u4e2a\u7ebf\u7a0b\u8fdb\u884c\u76d1\u7ba1&#xff0c;\u542f\u52a8\u5bf9\u5e94\u7684\u8d85\u65f6\u9500\u6bc1\u4efb\u52a1\u3002<\/li>\n<li>\u63d0\u4f9b\u8fde\u63a5\u7684\u5185\u90e8\u91ca\u653e\u51fd\u6570RemoveConnection&#xff0c;\u9500\u6bc1\u8fde\u63a5\u5728\u670d\u52a1\u5668\u4e2d\u7684\u8d44\u6e90<\/li>\n<li>\u63d0\u4f9b\u7ed9\u4e0a\u5c42\u7684\u8bbe\u7f6e\u56de\u8c03\u51fd\u6570\u63a5\u53e3<\/li>\n<li>\u670d\u52a1\u5668\u5f00\u59cb\u8fd0\u884c&#xff1a;\u542f\u52a8\u670d\u52a1\u5668\u5957\u63a5\u5b57\u7684\u76d1\u542c&#xff0c;\u521b\u5efa\u7ebf\u7a0b\u6c60&#xff0c;\u5f00\u542f\u4e3bReactor\u7684\u76d1\u63a7\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.7k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u52a0\u6cb9\u52a0\u6cb9 \uff0c \u53ca\u65f6\u603b\u7ed3\u9879\u76ee! \u52aa\u529b\u5411\u524d\uff0c\u6211\u8981\u6210\u4e3a\u8d85\u5f3a\u7684\u7a0b\u5e8f\u5458\uff01<\/p>\n","protected":false},"author":2,"featured_media":8227,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[84,83,43,44],"topic":[],"class_list":["post-8229","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-android","tag-83","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3 - \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\/8229.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.7k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u52a0\u6cb9\u52a0\u6cb9 \uff0c \u53ca\u65f6\u603b\u7ed3\u9879\u76ee! \u52aa\u529b\u5411\u524d\uff0c\u6211\u8981\u6210\u4e3a\u8d85\u5f3a\u7684\u7a0b\u5e8f\u5458\uff01\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/8229.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T08:29:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418082916-68020d5c49feb.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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/8229.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/8229.html\",\"name\":\"\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T08:29:21+00:00\",\"dateModified\":\"2025-04-18T08:29:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/8229.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/8229.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/8229.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3\"}]},{\"@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\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3 - \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\/8229.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.7k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf30\u6b21\u3002\u52a0\u6cb9\u52a0\u6cb9 \uff0c \u53ca\u65f6\u603b\u7ed3\u9879\u76ee! \u52aa\u529b\u5411\u524d\uff0c\u6211\u8981\u6210\u4e3a\u8d85\u5f3a\u7684\u7a0b\u5e8f\u5458\uff01","og_url":"https:\/\/www.wsisp.com\/helps\/8229.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T08:29:21+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418082916-68020d5c49feb.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/8229.html","url":"https:\/\/www.wsisp.com\/helps\/8229.html","name":"\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T08:29:21+00:00","dateModified":"2025-04-18T08:29:21+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/8229.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/8229.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/8229.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u9879\u76ee\u65e5\u8bb0\u3011\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9879\u76ee\u603b\u7ed3"}]},{"@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\/8229","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=8229"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/8229\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/8227"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=8229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=8229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=8229"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=8229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}