{"id":38702,"date":"2025-05-21T07:41:57","date_gmt":"2025-05-20T23:41:57","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38702.html"},"modified":"2025-05-21T07:41:57","modified_gmt":"2025-05-20T23:41:57","slug":"%e3%80%90c-%e4%bb%bfmudou%e5%ba%93one-thread-one-loop%e5%bc%8f%e9%ab%98%e5%b9%b6%e5%8f%91%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%9e%e7%8e%b0%e3%80%91","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38702.html","title":{"rendered":"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u9879\u76ee\u4ecb\u7ecd<\/li>\n<li>\u9879\u76ee\u6a21\u5757\u548c\u670d\u52a1\u5668\u4e3b\u8981\u8bbe\u8ba1\u6a21\u5f0f<\/li>\n<li>\u9879\u76ee\u4e3b\u8981\u6d41\u7a0b<\/li>\n<li>\u524d\u7f6e\u77e5\u8bc6<\/li>\n<li>\n<ul>\n<li>1.bind\u51fd\u6570<\/li>\n<li>2.\u5b9a\u65f6\u5668\u4efb\u52a1TimerTask\u548c\u65f6\u95f4\u8f6e\u601d\u60f3TimerWheel<\/li>\n<li>3.\u6b63\u5219\u8868\u8fbe\u5f0f<\/li>\n<li>4.\u901a\u7528\u578b\u5bb9\u5668Any\u7c7b<\/li>\n<\/ul>\n<\/li>\n<li>\u670d\u52a1\u5668\u8bbe\u8ba1\u6a21\u5f0f<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>1&#xff09;\u5355Reactor\u5355\u7ebf\u7a0b\u6a21\u5f0f<\/li>\n<li>2&#xff09;\u5355Reactor\u591a\u7ebf\u7a0b\u6a21\u5f0f<\/li>\n<li>3&#xff09;\u591aReactor\u591a\u7ebf\u7a0b\u6a21\u5f0f&#xff08;\u672c\u6b21\u9879\u76ee\u4e3b\u8981\u501f\u9274\u7684\u6a21\u5f0f&#xff09;<\/li>\n<li>\u9879\u76ee\u5b9e\u73b0\u76ee\u6807\u6846\u67b6<\/li>\n<\/ul>\n<\/li>\n<li>\u4e00\u3001Server\u670d\u52a1\u5668\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>1&#xff09;Buffer\u6a21\u5757<\/li>\n<li>2&#xff09;Socket\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>\u77e5\u8bc6\u70b9&#xff1a;\u5f00\u542f\u5730\u5740\u91cd\u7528<\/li>\n<\/ul>\n<\/li>\n<li>3&#xff09;Channel\u6a21\u5757<\/li>\n<li>4&#xff09;Poller\u6a21\u5757<\/li>\n<li>5&#xff09;EventLoop\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>\u7cfb\u7edf\u63a5\u53e3eventfd\u2014\u2014\u7ebf\u7a0b\u95f4\u7684\u4e8b\u4ef6\u901a\u77e5<\/li>\n<\/ul>\n<\/li>\n<li>6&#xff09;TimerTask\u548cTimerWheel\u6a21\u5757<\/li>\n<li>7&#xff09; Connection\u6a21\u5757<\/li>\n<li>8&#xff09;Acceptor\u6a21\u5757<\/li>\n<li>9&#xff09;LoopThread\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>\u7ebf\u7a0b\u95f4\u7684\u540c\u6b65\u548c\u4e92\u65a5\u77e5\u8bc6\u70b9<\/li>\n<\/ul>\n<\/li>\n<li>10&#xff09;LoopThreadPool\u6a21\u5757<\/li>\n<\/ul>\n<\/li>\n<li>\u4e8c\u3001HTTP\u534f\u8bae\u6a21\u5757<\/li>\n<li>\n<ul>\n<li>\u8bbe\u8ba1\u601d\u60f3<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u5e94\u7528\u5c42\u534f\u8bae&#xff1a;Http\u670d\u52a1\u5668\u8bbe\u8ba1<\/li>\n<li>\n<ul>\n<li>2)HttpRequest\u6a21\u5757<\/li>\n<li>3)HttpResponse\u6a21\u5757<\/li>\n<li>4)HttpContext\u5bf9Http\u8bf7\u6c42\u8fdb\u884c\u89e3\u6790\u6a21\u5757<\/li>\n<li>HttpServer\u6a21\u5757&#xff1a;\u5bf9\u524d\u9762\u51e0\u4e2a\u6a21\u5757\u7684\u529f\u80fd\u6574\u5408<\/li>\n<\/ul>\n<\/li>\n<li>\u9047\u5230\u7684\u95ee\u9898<\/li>\n<li>\n<ul>\n<li>1.vector\u5b9a\u4e49\u5728_capacity\u4e4b\u540e&#xff0c;\u5bfc\u81f4vector\u5728\u4f7f\u7528\u65f6\u6ca1\u6709\u5f00\u7a7a\u95f4\u800c\u76f4\u63a5\u4f7f\u7528[]\u8bbf\u95ee\u5bfc\u81f4\u7a7a\u95f4\u4f7f\u7528\u9519\u8bef\u95ee\u9898\u3002<\/li>\n<li>2.\u518d\u8c03\u8bd5Buffer\u7c7b\u7684\u63a5\u53e3\u51fd\u6570\u65f6&#xff0c;\u9884\u671f\u7ed3\u679c\u662f\u4ecei &#061; 1\u6253\u5370\u5230i &#061; 300<\/li>\n<li>3.<\/li>\n<li>4.\u5bf9Connection\u8054\u5408\u8c03\u8bd5\u65f6&#xff0c;\u672a\u5bf9_socket\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u5bfc\u81f4\u540e\u7eed\u65e0\u6cd5recv<\/li>\n<li>5. \u8bf7\u6c42\u65b9\u6cd5\u5fc5\u987b\u662fGet\/Head\u65b9\u6cd5<\/li>\n<\/ul>\n<\/li>\n<li>\u9879\u76ee\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9<\/li>\n<li>\n<ul>\n<li>md5sum &#043; \u6587\u4ef6\u540d<\/li>\n<li>\u4e0a\u4f20\u5927\u6587\u4ef6<\/li>\n<li>\u591a\u6001<\/li>\n<\/ul>\n<\/li>\n<li>\u7ed9\u670d\u52a1\u5668\u4e0a\u5f3a\u5ea6<\/li>\n<li>\n<ul>\n<li>1.\u957f\u94fe\u63a5\u8bf7\u6c42\u6d4b\u8bd5<\/li>\n<li>2.\u8d85\u65f6\u94fe\u63a5\u91ca\u653e\u6d4b\u8bd5<\/li>\n<li>3.\u6570\u636e\u4e2d\u591a\u6761\u8bf7\u6c42\u5904\u7406\u6d4b\u8bd5<\/li>\n<li>4.\u901a\u8fc7Put\u65b9\u6cd5\u4e0a\u4f20\u5927\u6587\u4ef6\u6d4b\u8bd5<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>\u9879\u76ee\u4ecb\u7ecd<\/h2>\n<p>\u901a\u8fc7\u591aReactor\u591a\u7ebf\u7a0b&#xff1a;\u591aI\/O\u591a\u8def\u590d\u7528&#043;\u7ebf\u7a0b\u6c60&#xff08;\u4e1a\u52a1\u5904\u7406&#xff09;\u7684\u5904\u7406\u6a21\u5f0f&#xff0c;\u642d\u5efa\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u7ec4\u4ef6\u3002<\/p>\n<p>\u4e3bReactor\u7ebf\u7a0b\u76d1\u63a7\u76d1\u542c\u63cf\u8ff0\u7b26&#xff0c;\u83b7\u53d6\u65b0\u5efa\u8fde\u63a5&#xff0c;\u968f\u540e\u5206\u53d1\u7ed9\u4ece\u5c5eReactor\u8fdb\u884c\u901a\u4fe1\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u4eceReactor\u76d1\u63a7\u5404\u81ea\u63cf\u8ff0\u7b26\u7684\u8bfb\u5199\u4e8b\u4ef6&#xff0c;\u4e00\u65e6\u4e8b\u4ef6\u89e6\u53d1&#xff0c;\u5219\u63a5\u6536\u6570\u636e\u5206\u53d1\u7ed9Work\u7ebf\u7a0b\u6c60&#xff0c;Work\u7ebf\u7a0b\u6c60\u5206\u914d\u72ec\u7acb\u7684\u7ebf\u7a0b\u8fdb\u884c\u4e1a\u52a1\u5904\u7406&#xff0c;\u5904\u7406\u5b8c\u6bd5\u540e&#xff0c;\u5c06\u54cd\u5e94\u4ea4\u7ed9\u5b50Reactor\u7ebf\u7a0b\u8fdb\u884c\u6570\u636e\u54cd\u5e94\u3002<\/p>\n<p>\u5229\u7528CPU\u591a\u6838\u8d44\u6e90\u8fbe\u5230\u5e76\u53d1\u4e1a\u52a1\u5904\u7406\u7684\u76ee\u7684\u3002<\/p>\n<h2>\u9879\u76ee\u6a21\u5757\u548c\u670d\u52a1\u5668\u4e3b\u8981\u8bbe\u8ba1\u6a21\u5f0f<\/h2>\n<p>\u5173\u4e8e\u6574\u4e2a\u9879\u76ee&#xff0c;\u5206\u4e3a\u4e24\u5927\u6a21\u5757<\/p>\n<p>\u4e00\u3001Server\u670d\u52a1\u5668\u6a21\u5757<\/p>\n<p>\u4e8c\u3001\u5e94\u7528\u5c42\u534f\u8bae\u652f\u6301\u7684\u7684\u534f\u8bae\u6a21\u5757\u3002<\/p>\n<h2>\u9879\u76ee\u4e3b\u8981\u6d41\u7a0b<\/h2>\n<p>\u9879\u2f6c\u7684\u4e3b\u8981\u6d41\u7a0b&#xff1a;<\/p>\n<li>\u5728\u5b9e\u4f8b\u5316TcpServer\u5bf9\u8c61\u8fc7\u7a0b\u4e2d&#xff0c;\u5b8c\u6210BaseLoop\u7684\u8bbe\u7f6e&#xff0c;Acceptor\u5bf9\u8c61\u7684\u5b9e\u4f8b\u5316&#xff0c;\u4ee5\u53caEventLoop\u7ebf\u7a0b\u6c60\u7684\u5b9e\u4f8b\u5316&#xff0c;\u4ee5\u53castd::shared_ptr\u7684hash\u8868\u7684\u5b9e\u4f8b\u5316\u3002<\/li>\n<li>\u4e3aAcceptor\u5bf9\u8c61\u8bbe\u7f6e\u56de\u8c03\u51fd\u6570&#xff1a;\u83b7\u53d6\u5230\u65b0\u8fde\u63a5\u540e&#xff0c;\u4e3a\u65b0\u8fde\u63a5\u6784\u5efaConnection\u5bf9\u8c61&#xff0c;\u8bbe\u7f6e Connection\u7684\u5404\u9879\u56de\u8c03&#xff0c;\u5e76\u4f7f\u2f64shared_ptr\u8fdb\u2f8f\u7ba1\u7406&#xff0c;\u5e76\u6dfb\u52a0\u5230hash\u8868\u4e2d\u8fdb\u2f8f\u7ba1\u7406&#xff0c;\u5e76\u4e3a Connection\u9009\u62e9\u2f00\u4e2aEventLoop\u7ebf\u7a0b&#xff0c;\u4e3aConnection\u6dfb\u52a0\u2f00\u4e2a\u5b9a\u65f6\u9500\u6bc1\u4efb\u52a1&#xff0c;\u4e3aConnection\u6dfb\u52a0 \u4e8b\u4ef6\u76d1\u63a7<\/li>\n<li>\u542f\u52a8BaseLoop\u3002<\/li>\n<li>\u901a\u8fc7Poller\u6a21\u5757\u5bf9\u5f53\u524d\u6a21\u5757\u7ba1\u7406\u5185\u7684\u6240\u6709\u63cf\u8ff0\u7b26\u8fdb\u2f8fIO\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u6709\u63cf\u8ff0\u7b26\u4e8b\u4ef6\u5c31\u7eea\u540e&#xff0c;\u901a\u8fc7\u63cf\u8ff0\u7b26\u5bf9\u5e94\u7684Channel\u8fdb\u2f8f\u4e8b\u4ef6\u5904\u7406\u3002<\/li>\n<li>\u6240\u6709\u5c31\u7eea\u7684\u63cf\u8ff0\u7b26IO\u4e8b\u4ef6\u5904\u7406\u5b8c\u6bd5\u540e&#xff0c;\u5bf9\u4efb\u52a1\u961f\u5217\u4e2d\u7684\u6240\u6709\u64cd\u4f5c\u987a\u5e8f\u8fdb\u2f8f\u6267\u2f8f\u3002<\/li>\n<li>\u7531\u4e8eepoll\u7684\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u6709\u53ef\u80fd\u4f1a\u56e0\u4e3a\u6ca1\u6709\u4e8b\u4ef6\u5230\u6765\u2f7d\u6301\u7eed\u963b\u585e&#xff0c;\u5bfc\u81f4\u4efb\u52a1\u961f\u5217\u4e2d\u7684\u4efb\u52a1\u4e0d\u80fd\u53ca\u65f6\u5f97\u5230\u6267\u2f8f&#xff0c;\u56e0\u6b64\u521b\u5efa\u4e86eventfd&#xff0c;\u6dfb\u52a0\u5230Poller\u7684\u4e8b\u4ef6\u76d1\u63a7\u4e2d&#xff0c;\u2f64\u4e8e\u5b9e\u73b0\u6bcf\u6b21\u5411\u4efb\u52a1\u961f\u5217\u6dfb\u52a0\u4efb\u52a1\u7684\u65f6\u5019&#xff0c;\u901a\u8fc7\u5411eventfd\u5199\u2f0a\u6570\u636e\u6765\u5524\u9192epoll\u7684\u963b\u585e\u3002<\/li>\n<li>\u5b9e\u73b0\u5411Channel\u63d0\u4f9b\u53ef\u8bfb&#xff0c;\u53ef\u5199&#xff0c;\u9519\u8bef\u7b49\u4e0d\u540c\u4e8b\u4ef6\u7684IO\u4e8b\u4ef6\u56de\u8c03\u51fd\u6570&#xff0c;\u7136\u540e\u5c06Channel\u548c\u5bf9\u5e94\u7684\u63cf\u8ff0\u7b26\u6dfb\u52a0\u5230Poller\u4e8b\u4ef6\u76d1\u63a7\u4e2d\u3002<\/li>\n<li>\u5f53\u63cf\u8ff0\u7b26\u5728Poller\u6a21\u5757\u4e2d\u5c31\u7eea\u4e86IO\u53ef\u8bfb\u4e8b\u4ef6&#xff0c;\u5219\u8c03\u2f64\u63cf\u8ff0\u7b26\u5bf9\u5e94Channel\u4e2d\u4fdd\u5b58\u7684\u8bfb\u4e8b\u4ef6\u5904\u7406\u51fd \u6570&#xff0c;\u8fdb\u2f8f\u6570\u636e\u8bfb\u53d6&#xff0c;\u5c06socket\u63a5\u6536\u7f13\u51b2\u533a\u5168\u90e8\u8bfb\u53d6\u5230Connection\u7ba1\u7406\u7684\u2f64\u2f3e\u6001\u63a5\u6536\u7f13\u51b2\u533a\u4e2d\u3002\u7136 \u540e\u8c03\u2f64\u7531\u7ec4\u4ef6\u4f7f\u2f64\u8005\u4f20\u2f0a\u7684\u65b0\u6570\u636e\u5230\u6765\u56de\u8c03\u51fd\u6570\u8fdb\u2f8f\u5904\u7406\u3002<\/li>\n<li>\u7ec4\u4ef6\u4f7f\u2f64\u8005\u8fdb\u2f8f\u6570\u636e\u7684\u4e1a\u52a1\u5904\u7406\u5b8c\u6bd5\u540e&#xff0c;\u901a\u8fc7Connection\u5411\u4f7f\u2f64\u8005\u63d0\u4f9b\u7684\u6570\u636e\u53d1\u9001\u63a5\u2f1d&#xff0c;\u5c06\u6570\u636e \u5199\u2f0aConnection\u7684\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u3002<\/li>\n<li>\u542f\u52a8\u63cf\u8ff0\u7b26\u5728Poll\u6a21\u5757\u4e2d\u7684IO\u5199\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u5c31\u7eea\u540e&#xff0c;\u8c03\u2f64Channel\u4e2d\u4fdd\u5b58\u7684\u5199\u4e8b\u4ef6\u5904\u7406\u51fd\u6570&#xff0c;\u5c06\u53d1\u9001\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u901a\u8fc7Socket\u8fdb\u2f8f\u2faf\u5411\u7cfb\u7edf\u7684\u5b9e\u9645\u6570\u636e\u53d1\u9001\u3002<\/li>\n<h2>\u524d\u7f6e\u77e5\u8bc6<\/h2>\n<h3>1.bind\u51fd\u6570<\/h3>\n<p>bind\u51fd\u6570\u4e00\u822c\u7528\u6765\u7ed1\u5b9a\u4e00\u4e9b\u56de\u8c03\u51fd\u6570\u3002 \u4e00\u822c\u5728\u5404\u4e2a\u6a21\u5757\u4e2d&#xff0c;\u6bd4\u5982\u8be5\u9879\u76ee\u4e0b\u7684Channel\u6a21\u5757&#xff0c;EventLoop\u6a21\u5757&#xff0c;Connection\u6a21\u5757\u7b49\u3002 \u90fd\u9700\u8981\u76d1\u542c\u83b7\u53d6\u5230\u65b0\u94fe\u63a5&#xff0c;\u5e76\u5bf9\u94fe\u63a5\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7\u7ba1\u7406&#xff0c;\u4e00\u65e6\u89e6\u53d1\u65b0\u4e8b\u4ef6&#xff0c;\u5c31\u8981\u5bf9\u4e8b\u4ef6\u8fdb\u884c\u5177\u4f53\u7684\u5904\u7406&#xff0c;\u5982\u6570\u636e\u63a5\u6536\u53d1\u9001\u89e3\u6790\u5904\u7406\u7b49&#xff0c;\u4e1a\u52a1\u5904\u7406\u7b49\u3002<\/p>\n<p>\u4e3a\u4e86\u8ba9\u5404\u4e2a\u6a21\u5757\u66f4\u6e05\u6670\u660e\u786e\u5730\u5b8c\u6210\u8fd9\u4e9b\u6a21\u5757\u7684\u4efb\u52a1&#xff0c;\u5c31\u628a\u5177\u4f53\u7684\u6570\u636e\u5904\u7406&#xff0c;\u4e8b\u4ef6\u5904\u7406\u7684\u5177\u4f53\u64cd\u4f5c\u7528\u5177\u4f53\u7684\u63a5\u53e3\u5b8c\u6210&#xff0c;\u5728\u8fd9\u4e9b\u6a21\u5757\u4e2d\u53ea\u9700\u8981\u7ed1\u5b9a\u5177\u4f53\u7684\u63a5\u53e3\u5373\u53ef\u5b8c\u6210\u6570\u636e\u5904\u7406\u3002<\/p>\n<p>\u8fd9\u6837\u5c31\u964d\u4f4e\u4e86\u4ee3\u7801\u76f4\u63a5\u7684\u8026\u5408&#xff0c;\u8ba9\u5404\u4e2a\u6a21\u5757\u76f4\u63a5\u7684\u529f\u80fd\u66f4\u52a0\u6e05\u6670\u3002<\/p>\n<p>bind\u51fd\u6570\u4f7f\u7528\u6848\u4f8b<\/p>\n<p><span class=\"token comment\">\/\/  function&lt;\u8fd4\u56de\u503c\u7c7b\u578b(\u53c2\u6570\u4e00\u7c7b\u578b,\u53c2\u6570\u4e8c\u7c7b\u578b,&#8230;)&gt; \u51fd\u6570\u540d &#061; [\u9009\u62e9\u503c\u4f20\u9012&#xff0c;\u5f15\u7528\u4f20\u9012\u7b49](\u53c2\u6570\u7c7b\u578b  \u5f62\u53c2\u540d,\u53c2\u6570\u7c7b\u578b \u5f62\u53c2\u540d, &#8230;) -&gt; \u8fd4\u56de\u503c\u7c7b\u578b{<\/span><br \/>\n<span class=\"token comment\">\/\/            &#8230; <\/span><br \/>\n<span class=\"token comment\">\/\/   };<\/span><br \/>\n<span class=\"token comment\">\/\/\u53c2\u65701&#xff1a;\u7ed1\u5b9a\u4e00\u4e2a\u51fd\u6570&#xff0c;\u53c2\u65702&#xff1a;\u4f20\u9012\u8be5\u51fd\u6570\u7684\u53c2\u6570&#xff0c;std::placeholders::_1 \u53ef\u4ee5\u7528\u6765\u4f20\u9012\u66f4\u591a\u53c2\u6570(\u4f46\u53ea\u80fd\u662fint\u7c7b\u578b)<\/span><br \/>\n<span class=\"token comment\">\/\/bind (Fn&amp;&amp; fn, Arge&amp; args,..)        <\/span><\/p>\n<p><span class=\"token comment\">\/\/\u4f7f\u7528\u6848\u4f8b<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> std<span class=\"token operator\">::<\/span>string<span class=\"token operator\">&amp;<\/span> str<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> num<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> str <span class=\"token operator\">&lt;&lt;<\/span> num <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">using<\/span> Task <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 punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span> <\/p>\n<p>    std<span class=\"token operator\">::<\/span>vector<span class=\"token operator\">&lt;<\/span>Task<span class=\"token operator\">&gt;<\/span> array<span class=\"token punctuation\">;<\/span><\/p>\n<p>    array<span class=\"token punctuation\">.<\/span><span class=\"token function\">push_back<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span>print<span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;hello&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    array<span class=\"token punctuation\">.<\/span><span class=\"token function\">push_back<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span>print<span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;hello world&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    array<span class=\"token punctuation\">.<\/span><span class=\"token function\">push_back<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span>print<span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;nihao&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    array<span class=\"token punctuation\">.<\/span><span class=\"token function\">push_back<\/span><span class=\"token punctuation\">(<\/span>std<span class=\"token operator\">::<\/span><span class=\"token function\">bind<\/span><span class=\"token punctuation\">(<\/span>print<span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;bite&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">for<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">auto<\/span> <span class=\"token operator\">&amp;<\/span> func <span class=\"token operator\">:<\/span> array<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">func<\/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 number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>2.\u5b9a\u65f6\u5668\u4efb\u52a1TimerTask\u548c\u65f6\u95f4\u8f6e\u601d\u60f3TimerWheel<\/h3>\n<p>\u5728\u5f53\u524d\u7684\u5e76\u53d1\u670d\u52a1\u5668\u4e2d&#xff0c;\u5fc5\u987b\u8981\u91cd\u89c6\u4e00\u4e2a\u95ee\u9898&#xff1a;\u5ba2\u6237\u7aef\u8fde\u63a5\u4e0a\u670d\u52a1\u5668\u540e&#xff0c;\u957f\u65f6\u95f4\u4e0d\u8fdb\u884c\u6570\u636e\u901a\u4fe1&#xff0c;\u4f46\u662f\u4e5f\u4e0d\u5173\u95ed&#xff0c;\u5c31\u4f1a\u9020\u6210\u8d44\u6e90\u7a7a\u8017\u3002 \u6240\u4ee5\u5c31\u9700\u8981\u8bbe\u7f6e\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u5b9a\u65f6\u5c06\u8d85\u65f6\u7684\u8fde\u63a5\u8fdb\u884c\u91ca\u653e\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234147-682d133bf011b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u4e0b\u9762\u662f\u5b9a\u65f6\u4efb\u52a1\u5bf9\u8c61TimerTask\u7c7b&#xff0c;\u7528\u4e8e\u5c01\u88c5\u5b9a\u65f6\u4efb\u52a1\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234148-682d133c83dd6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u65f6\u95f4\u8f6e\u601d\u60f3&#xff1a; \u5355\u72ec\u521b\u5efa\u4e00\u4e2a\u5b9a\u65f6\u5668&#xff0c;\u5e76\u7ed9\u8be5\u5b9a\u65f6\u5668\u8bbe\u7f6e\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4&#xff0c;\u65f6\u95f4\u5230\u4e86\u4e4b\u540e\u8be5\u5b9a\u65f6\u5668\u4f1a\u53bb\u904d\u5386\u670d\u52a1\u5668\u7684\u6240\u6709\u94fe\u63a5&#xff0c;\u68c0\u6d4b\u54ea\u4e9b\u8fde\u63a5\u662f\u8d85\u65f6\u7684&#xff0c;\u4f46\u662f\u5982\u679c\u6709\u4e0a\u4e07\u4e2a\u94fe\u63a5&#xff0c;\u8fd9\u6837\u65e0\u7591\u6548\u7387\u975e\u5e38\u4f4e\u3002<\/p>\n<p>\u6240\u4ee5\u5c31\u5f15\u8fdb\u65f6\u95f4\u8f6e\u7684\u7b97\u6cd5\u6765\u4f18\u5316&#xff0c;\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<p>\u5b9a\u4e49\u2f00\u4e2a\u6570\u7ec4&#xff0c;\u5e76\u4e14\u6709\u2f00\u4e2a\u6307\u9488&#xff0c;\u6307\u5411\u6570\u7ec4\u8d77\u59cb\u4f4d\u7f6e&#xff0c;\u8fd9\u4e2a\u6307\u9488\u6bcf\u79d2\u949f\u5411\u540e\u2f9b\u52a8\u2f00\u6b65&#xff0c;\u2f9b\u5230\u54ea\u2fa5&#xff0c;\u5219\u4ee3\u8868\u54ea\u2fa5\u7684\u4efb\u52a1\u8be5\u88ab\u6267\u2f8f\u4e86&#xff0c;\u90a3\u4e48\u5982\u679c\u6211\u4eec\u60f3\u8981\u5b9a\u2f00\u4e2a3s\u540e\u7684\u4efb\u52a1&#xff0c;\u5219\u53ea\u9700\u8981\u5c06\u4efb\u52a1\u6dfb\u52a0\u5230tick&#043;3\u4f4d\u7f6e&#xff0c;\u5219\u6bcf\u79d2\u4e2d\u2f9b\u2f00\u6b65&#xff0c;\u4e09\u79d2\u949f\u540etick\u2f9b\u5230\u5bf9\u5e94\u4f4d\u7f6e&#xff0c;\u8fd9\u65f6\u5019\u6267\u2f8f\u5bf9\u5e94\u4f4d\u7f6e\u7684\u4efb\u52a1\u5373\u53ef\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234148-682d133caf4b8.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u4e0a\u8ff0\u64cd\u4f5c\u4e5f\u6709\u2f00\u4e9b\u7f3a\u9677&#xff0c;\u2f50\u5982\u6211\u4eec\u5982\u679c\u8981\u5b9a\u4e49\u2f00\u4e2a60s\u540e\u7684\u4efb\u52a1&#xff0c;\u5219\u9700\u8981\u5c06\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u8bbe\u7f6e \u4e3a60\u624d\u53ef\u4ee5&#xff0c;\u5982\u679c\u8bbe\u7f6e\u2f00\u2f29\u65f6\u540e\u7684\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u5219\u9700\u8981\u5b9a\u4e493600\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\u3002 \u56e0\u6b64&#xff0c;\u53ef\u4ee5\u91c7\u2f64\u591a\u5c42\u7ea7\u7684\u65f6\u95f4\u8f6e&#xff0c;\u6709\u79d2\u9488\u8f6e&#xff0c;\u5206\u9488\u8f6e&#xff0c;\u65f6\u9488\u8f6e&#xff0c; 60&lt;time&lt;3600\u5219time\/60\u5c31\u662f\u5206\u9488\u8f6e \u5bf9\u5e94\u5b58\u50a8\u7684\u4f4d\u7f6e&#xff0c;\u5f53tick\/3600\u7b49\u4e8e\u5bf9\u5e94\u4f4d\u7f6e\u7684\u65f6\u5019&#xff0c;\u5c06\u5176\u4f4d\u7f6e\u7684\u4efb\u52a1\u5411\u5206\u9488&#xff0c;\u79d2\u9488\u8f6e\u8fdb\u2f8f\u79fb\u52a8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234148-682d133cc5821.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u590d\u6742\u601d\u8003&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234148-682d133cf333f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u5177\u4f53\u4e00\u4e2atask\u4efb\u52a1\u653e\u5230\u5b9a\u65f6\u5668\u4e2d\u7684\u5b9e\u4f8b\u56fe&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234149-682d133d2807c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u4f46\u662f\u7f16\u5199\u65f6\u95f4\u8f6e\u6a21\u5757\u7c7b\u8fd8\u9700\u8981\u6ce8\u610f\u4e00\u4e2a\u95ee\u9898&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234149-682d133d5b825.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> TimerTask\u5b9a\u65f6\u4efb\u52a1\u5bf9\u8c61\u548cTimerWheel\u65f6\u95f4\u8f6e\u7684\u8054\u5408\u8be6\u7ec6\u89e3\u6790\u56fe&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234149-682d133d9efe3.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>3.\u6b63\u5219\u8868\u8fbe\u5f0f<\/h3>\n<p>\u4f7f\u7528\u793a\u4f8b<\/p>\n<p><span class=\"token function\">regex_match<\/span><span class=\"token punctuation\">(<\/span>src<span class=\"token punctuation\">,<\/span>matches<span class=\"token punctuation\">,<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nsrc&#xff1a;\u6e90\u5b57\u7b26\u4e32<br \/>\nmatches&#xff1a;\u5bb9\u5668<br \/>\ne&#xff1a;\u5339\u914d\u89c4\u5219<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;iostream&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;string&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;regex&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>string src <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\/abcd\/1234&#034;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/\u5339\u914d\u89c4\u5219<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>regex <span class=\"token function\">e<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/abcd\/(\\\\\\\\d&#043;)&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/\u5339\u914d\u4ee5 \/abcd\/ \u5f00\u59cb&#xff0c;\u540e\u9762\u8ddf\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u5b57\u5b57\u7b26\u7684\u5b57\u7b26\u4e32&#xff0c;\u5e76\u5728\u5339\u914d\u8fc7\u7a0b\u4e2d\u63d0\u53d6\u8fd9\u4e2a\u5b57\u7b26\u4e32<\/span><br \/>\n    <span class=\"token comment\">\/\/ &#034;\\\\\\\\&#034;\u8868\u793a\u8f6c\u4e49\u5b57\u7b26&#xff0c;\u5982\u679c\u662f &#034;\\\\d&#043;&#034;&#xff0c;\u8fd9\u6837&#039;\\\\d&#039;\u5c31\u662f\u8f6c\u4e49\u5b57\u7b26\u4e86<\/span><br \/>\n    <span class=\"token comment\">\/\/ d \u8868\u793a\u540e\u9762\u5339\u914d\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26&#xff0c;d&#043;\u5339\u914d\u7684\u662f\u591a\u4e2a\u6570\u5b57\u5b57\u7b26&#xff0c;\u76f4\u5230\u5339\u914d\u5230\u7b2c\u4e00\u4e2a\u975e\u6570\u5b57\u5b57\u7b26\u4e3a\u6b62<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>smatch matches<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/\u5b58\u653e\u5339\u914d\u6210\u529f\u7684\u5b57\u7b26\u4e32\u7684\u5bb9\u5668<\/span><br \/>\n    <span class=\"token comment\">\/\/\u7b2c\u4e00\u4e2a\u662fsrc\u5b57\u7b26\u4e32\u672c\u8eab&#xff0c;\u540e\u9762\u5c31\u662f\u5339\u914d\u6210\u529f\u7684\u5b57\u7b26\u4e32\u3002<\/span><\/p>\n<p>    <span class=\"token keyword\">bool<\/span> ret <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span><span class=\"token function\">regex_match<\/span><span class=\"token punctuation\">(<\/span>src<span class=\"token punctuation\">,<\/span>matches<span class=\"token punctuation\">,<\/span>e<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\">&#061;&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">auto<\/span> <span class=\"token operator\">&amp;<\/span>s<span class=\"token operator\">:<\/span> matches<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> s <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9HTTP\u8fdb\u884c\u8bf7\u6c42<\/p>\n<ul>\n<li>1.\u63d0\u53d6\u5339\u914d\u65b9\u6cd5&#xff0c;GET|HEAD|PUSH|PUT|DELETE \u7b49\u7b49<\/li>\n<li>2.\u63d0\u53d6HTTP\u8d44\u6e90\u8def\u5f84\u3002\u4ece\u8bf7\u6c42\u65b9\u6cd5\u4e4b\u540e\u7684&#034;\u7a7a\u683c&#034;\u5f00\u59cb\u76f4\u5230\u9047\u5230&#034;&#xff1f;&#034;\u7ed3\u675f&#xff0c;\u8fd9\u6bb5\u5b57\u7b26\u4e32\u5c31\u662f\u8d44\u6e90\u8def\u5f84\u3002<\/li>\n<li>3.\u63d0\u53d6\u67e5\u8be2\u5b57\u7b26\u4e32\u3002\u4e5f\u5c31\u662f\u63d0\u53d6&#034;&#xff1f;\u201c\u4e4b\u540e\u7684\u5b57\u7b26\u4e32&#xff0c;\u76f4\u5230\u7a7a\u683c\u622a\u6b62&#xff08;\u4e0d\u8981\u201d?&#034;)<\/li>\n<li>4.\u63d0\u53d6\u534f\u8bae\u7248\u672c<\/li>\n<\/ul>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ HTTP\u8bf7\u6c42\u884c\u683c\u5f0f &#034;GET \/bitejiuyeke\/login?user&#061;xiaoming&amp;pass&#061;123123 HTTP\/1.1\\\\r\\\\n&#034;<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>string str <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;GET \/bitejiuyeke\/login?user&#061;xiaoming&amp;pass&#061;123123 HTTP\/1.1&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>smatch matches<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/\u5b58\u50a8\u5bb9\u5668<\/span><br \/>\n    <span class=\"token comment\">\/\/\u8bf7\u6c42\u65b9\u6cd5\u7684\u5339\u914d&#xff1a; GET HEAD POST PUT DELETE ..<\/span><br \/>\n    std<span class=\"token operator\">::<\/span>regex <span class=\"token function\">e<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;(GET|HEAD|POST|PUT|DELETE) ([^?]*)\\\\\\\\?(.*) (\\\\\\\\HTTP\/1\\\\\\\\.[01])&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ &#034;.&#034;\u5339\u914d\u4efb\u610f\u975e\\\\r\\\\n\u7684\u5355\u4e2a\u5b57\u7b26,&#034;*&#034;\u8868\u793a\u80fd\u5339\u914d\u524d\u9762\u7684&#034;.&#034;0\u6b21\u6216\u591a\u6b21<\/span><br \/>\n    <span class=\"token comment\">\/\/\u5f88\u660e\u663e&#xff0c;\u8fd9\u91cc\u5c31\u662f\u5339\u914d\u9664\u4e86GET\u4e4b\u540e\u7684\u6240\u6709\u5b57\u7b26<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ [^?] :\u5339\u914d\u975e&#034;?&#034;\u5b57\u7b26&#xff0c;*\u8868\u793a\u5339\u914d0\u6b21\u6216\u591a\u6b21<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \\\\\\\\?(.*) \u5339\u914d\u4e00\u4e2a\u4ee5&#034;?&#034;\u5f00\u59cb\u7684\u5b57\u7b26(\u4e0d\u8981\u8fd9\u4e2a\u95ee\u53f7&#xff09;\u5e76\u6301\u7eed\u5339\u914d\u76f4\u5230\u9047\u5230\u7a7a\u683c&#xff0c;\u6ce8\u610f\u6709\u4e00\u4e2a\u7a7a\u683c <\/span><br \/>\n    <span class=\"token comment\">\/\/ \\\\\\\\?(.*)\u4e0e (\\\\\\\\?.*)\u4e0d\u540c&#xff0c;\u7b2c\u4e00\u4e2a\u4e0d\u8981&#034;?&#034;\u4e86&#xff0c;\u7b2c\u4e8c\u4e2a\u5374\u8981&#034;?&#034;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ (\\\\\\\\HTTP\/1\\\\\\\\.[01]): \u5339\u914dHTTP\/1. [01]:\u8868\u793a\u5339\u914d0\u6216\u80051 &#xff0c; &#034;.&#034;\u8868\u793a\u5339\u914d\u4efb\u610f\u975e\\\\r\\\\n\u7684\u5355\u4e2a\u5b57\u7b26&#xff0c;\u4f46\u662f\u8fd9\u91cc\u6211\u4eec\u60f3\u8981\u7684\u662f\u771f\u6b63\u7684&#034;.&#034;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u90a3\u5c31\u8981\u4f7f\u7528 &#034;\\\\\\\\.&#034;\u8f6c\u4e49\u6210\u5355\u4e2a&#034;.&#034;<\/span><br \/>\n    <span class=\"token keyword\">bool<\/span> ret <span class=\"token operator\">&#061;<\/span> std<span class=\"token operator\">::<\/span><span class=\"token function\">regex_match<\/span><span class=\"token punctuation\">(<\/span>str<span class=\"token punctuation\">,<\/span>matches<span class=\"token punctuation\">,<\/span>e<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\">&#061;&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">for<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">auto<\/span> <span class=\"token operator\">&amp;<\/span>s <span class=\"token operator\">:<\/span> matches<span class=\"token punctuation\">)<\/span><br \/>\n        std<span class=\"token operator\">::<\/span>cout <span class=\"token operator\">&lt;&lt;<\/span> s <span class=\"token operator\">&lt;&lt;<\/span> std<span class=\"token operator\">::<\/span>endl<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>4.\u901a\u7528\u578b\u5bb9\u5668Any\u7c7b<\/h3>\n<p>\u5728Connection\u5bf9\u94fe\u63a5\u8fdb\u884c\u7ba1\u7406\u65f6&#xff0c;\u4e0d\u53ef\u907f\u514d\u5730\u4f1a\u6d89\u53ca\u5230\u83b7\u53d6\u5e94\u7528\u5c42\u534f\u8bae\u4fe1\u606f&#xff0c;\u5e76\u8fdb\u884c\u89e3\u6790\u548c\u5904\u7406\u3002d\u4f46\u662f\u5e94\u7528\u5c42\u534f\u8bae\u6709\u90a3\u4e48\u591a\u79cd&#xff0c;\u6211\u4eec\u4e0d\u80fd\u53ea\u5355\u72ec\u5b9e\u73b0\u9488\u5bf9\u4e00\u4e2a\u534f\u8bae\u7684\u4ee3\u7801&#xff0c;\u53ea\u80fd\u5b9e\u73b0\u4e00\u4e2a\u901a\u7528\u7c7b\u578b\u7684\u5bb9\u5668\u6765\u4fdd\u5b58\u8be5\u8fd9\u4e9b\u5e94\u7528\u5c42\u534f\u8bae\u7684\u8bf7\u6c42\u548c\u89e3\u6790\u3002<\/p>\n<p>\u8fd9\u4e2a\u5bb9\u5668\u5fc5\u987b\u80fd\u4fdd\u5b58\u5404\u79cd\u4e0d\u540c\u7c7b\u578b\u7ed3\u6784\u7684\u6570\u636e\u3002 \u8bbe\u8ba1\u601d\u60f3&#xff1a;<\/p>\n<ul>\n<li>1.\u8bbe\u8ba1\u4e00\u4e2a\u6a21\u677f\u7c7b&#xff0c;\u4f46\u662f\u901a\u8fc7\u8be5\u7c7b\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684\u65f6\u5019\u8981\u4f20\u9012\u6a21\u677f\u53c2\u6570&#xff0c;\u5982&#xff1a;Any&lt; int &gt; a &#061; 10\u2026<\/li>\n<li>\u6211\u5c31\u662f\u56e0\u4e3a\u4e0d\u77e5\u9053\u6570\u636e\u7c7b\u578b\u83dc\u8bbe\u8ba1\u7684Any\u7c7b&#xff0c;\u663e\u7136\u8fd9\u79cd\u65b9\u6cd5\u884c\u4e0d\u901a\u3002<\/li>\n<\/ul>\n<li>\u540c\u6837\u8bbe\u8ba1\u4e00\u4e2a\u7c7b&#xff0c;\u53ea\u662f\u8fd9\u4e2a\u7c7b\u4e2d\u518d\u8bbe\u8ba1\u4e00\u4e2a\u6a21\u677f\u7c7b&#xff0c;\u8ba9\u8fd9\u4e2a\u6a21\u677f\u7c7b\u5b58\u50a8\u6570\u636e<\/li>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Any<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">template<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">T<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">placeholder<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n        T _val<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4f46\u662f\u8fd9\u6837\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684\u65f6\u5019&#xff0c;\u540c\u6837\u8981\u4f20\u9012\u6a21\u677f\u53c2\u6570\u3002 \u6240\u4ee5&#xff0c;\u8fd8\u5e94\u8be5\u8bbe\u8ba1\u4e00\u4e2a\u7236\u7c7bholder&#xff0c;\u8ba9placeholder\u7ee7\u627f\u8be5\u7c7b&#xff0c;\u901a\u8fc7holder\u7c7b\u7684\u6307\u9488\u6216\u8005\u5f15\u7528&#xff0c;\u5373\u53ef\u8bbf\u95eeplaceholder\u7c7b\u7684\u6210\u5458\u51fd\u6570\u3002\u5373\u53ef\u5b9e\u73b0Any\u7c7b\u53ea\u5b58\u50a8\u4e00\u4e2aholder\u7c7b\u7684\u6307\u9488&#xff0c;\u5c31\u80fd\u8bbf\u95ee\u5230\u5b58\u50a8\u7684\u6570\u636e\u3002<\/p>\n<p>Any\u7c7b\u7684\u8bbe\u8ba1\u601d\u60f3&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234150-682d133e724e3.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u5177\u4f53\u5b9e\u73b0&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Any<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">holder<\/span>       <span class=\"token comment\">\/\/\u7236\u7c7b&#xff0c;\u7528\u6765\u88ab\u7ee7\u627f\u7684<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n        <span class=\"token keyword\">virtual<\/span> <span class=\"token operator\">~<\/span><span class=\"token function\">holder<\/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\">virtual<\/span> <span class=\"token keyword\">const<\/span> std<span class=\"token operator\">::<\/span>type_info<span class=\"token operator\">&amp;<\/span> <span class=\"token function\">type<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">virtual<\/span> holder<span class=\"token operator\">*<\/span> <span class=\"token function\">clone<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span> <span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/\u5b50\u7c7b\u624d\u662f\u7528\u6765\u4fdd\u5b58\u6570\u636e\u7684<\/span><br \/>\n    <span class=\"token keyword\">template<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">T<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">placeholder<\/span> <span class=\"token operator\">:<\/span> <span class=\"token base-clause\"><span class=\"token keyword\">public<\/span> <span class=\"token class-name\">holder<\/span>      <span class=\"token comment\">\/\/\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b<\/span><\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n        <span class=\"token function\">placeholder<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> T<span class=\"token operator\">&amp;<\/span> val<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token function\">_val<\/span><span class=\"token punctuation\">(<\/span>val<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span>  <span class=\"token comment\">\/\/\u5185\u7f6e\u7c7b\u578b\u4e0d\u505a\u5904\u7406&#xff0c;\u81ea\u5b9a\u4e49\u7c7b\u578bT\u4f1a\u8c03\u7528\u5b83\u7684\u62f7\u8d1d\u6784\u9020<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u83b7\u53d6\u5b50\u7c7b\u5bf9\u8c61\u7684\u6570\u636e\u7c7b\u578b<\/span><br \/>\n        <span class=\"token keyword\">virtual<\/span> <span class=\"token keyword\">const<\/span> std<span class=\"token operator\">::<\/span>type_info<span class=\"token operator\">&amp;<\/span> <span class=\"token function\">type<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">typeid<\/span><span class=\"token punctuation\">(<\/span>T<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u9488\u5bf9\u5f53\u524d\u5b50\u7c7b\u5bf9\u8c61\u81ea\u8eab&#xff0c;\u514b\u9686\u4e00\u4e2a\u65b0\u7684\u5b50\u7c7b\u5bf9\u8c61<\/span><br \/>\n        <span class=\"token keyword\">virtual<\/span> holder<span class=\"token operator\">*<\/span> <span class=\"token function\">clone<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token function\">placeholder<\/span><span class=\"token punctuation\">(<\/span>_val<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n        T _val<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    holder<span class=\"token operator\">*<\/span> _content<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n    <span class=\"token function\">Any<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span><span class=\"token function\">_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">template<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">T<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n    <span class=\"token function\">Any<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> T<span class=\"token operator\">&amp;<\/span> val<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token function\">_content<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> placeholder<span class=\"token operator\">&lt;<\/span>T<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">(<\/span>val<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span>               <span class=\"token comment\">\/\/\u6839\u636e\u6570\u636e\u7c7b\u578b\u6784\u9020\u4e00\u4e2aAny\u5bf9\u8c61<\/span><br \/>\n    <span class=\"token function\">Any<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> Any<span class=\"token operator\">&amp;<\/span> other<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token function\">_content<\/span><span class=\"token punctuation\">(<\/span>other<span class=\"token punctuation\">.<\/span>_content <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">nullptr<\/span> <span class=\"token operator\">?<\/span> <span class=\"token keyword\">nullptr<\/span> <span class=\"token operator\">:<\/span> other<span class=\"token punctuation\">.<\/span>_content<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">clone<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span>     <span class=\"token comment\">\/\/\u62f7\u8d1d\u6784\u9020<\/span><br \/>\n    <span class=\"token comment\">\/\/\u8fd9\u91cc\u7684\u62f7\u8d1d\u6784\u9020\u4e0d\u80fd\u76f4\u63a5\u590d\u5236\u4e00\u4e2aother\u5730\u5740&#xff0c;\u800c\u662f\u8981\u590d\u5236other\u5bf9\u8c61\u5185\u7684\u7236\u7c7b\u6307\u9488\u6307\u5411\u7684\u5b50\u7c7b\u5bf9\u8c61(placeholder)\u7684\u5730\u5740<\/span><br \/>\n    <span class=\"token operator\">~<\/span><span class=\"token function\">Any<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token keyword\">delete<\/span> _content<span class=\"token punctuation\">;<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>    Any<span class=\"token operator\">&amp;<\/span> <span class=\"token function\">swap<\/span><span class=\"token punctuation\">(<\/span>Any<span class=\"token operator\">&amp;<\/span> other<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/\u52a0\u4e86const\u540e&#xff0c;other\u7684_content\u662fconst\u4fee\u9970\u7684&#xff0c;\u800c\u539f\u672c\u7684_content\u662f\u53ef\u4fee\u6539\u7684<\/span><br \/>\n                  <span class=\"token comment\">\/\/\u8fd9\u6837\u5c31\u4f1a\u51fa\u73b0\u6743\u9650\u653e\u5927\u7684\u60c5\u51b5<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        std<span class=\"token operator\">::<\/span><span class=\"token function\">swap<\/span><span class=\"token punctuation\">(<\/span>_content<span class=\"token punctuation\">,<\/span> other<span class=\"token punctuation\">.<\/span>_content<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token operator\">*<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/\u8fd4\u56de\u5bf9\u8c61\u672c\u8eab\u662f\u4e3a\u4e86\u652f\u6301\u8fde\u7eedswap\u64cd\u4f5c\/\u8d4b\u503c\u64cd\u4f5c<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">template<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">T<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n    T<span class=\"token operator\">*<\/span> <span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>                       <span class=\"token comment\">\/\/\u8fd4\u56de\u5b50\u7c7b\u5bf9\u8c61\u4fdd\u5b58\u7684\u6570\u636e\u7684\u6307\u9488<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/\u6211\u5f53\u524d\u4fdd\u5b58\u7684\u6570\u636e\u7c7b\u578b\u4e0e\u60f3\u8981\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d<\/span><br \/>\n        <span class=\"token function\">assert<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">typeid<\/span><span class=\"token punctuation\">(<\/span>T<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> _content<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">type<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/\u6761\u4ef6\u6210\u7acb\u7ee7\u7eed&#xff0c;\u4e0d\u6210\u7acb\u62a5\u9519<\/span><\/p>\n<p>        <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&amp;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>placeholder<span class=\"token operator\">&lt;<\/span>T<span class=\"token operator\">&gt;<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span>_content<span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span>_val<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ _content\u662f\u4e00\u4e2a\u7236\u7c7b\u6307\u9488&#xff0c;\u5148\u8f6c\u5316\u6210\u5b50\u7c7b.<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">template<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">T<\/span><span class=\"token operator\">&gt;<\/span><br \/>\n    Any<span class=\"token operator\">&amp;<\/span> <span class=\"token keyword\">operator<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> T<span class=\"token operator\">&amp;<\/span> val<span class=\"token punctuation\">)<\/span>    <span class=\"token comment\">\/\/\u8d4b\u503c\u8fd0\u7b97\u7b26\u91cd\u8f7d<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">Any<\/span><span class=\"token punctuation\">(<\/span>val<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">swap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/\u4e3aval\u6784\u9020\u4e00\u4e2a\u4e34\u65f6Any\u901a\u7528\u5bb9\u5668\u5bf9\u8c61&#xff0c;\u7136\u540e\u4e0e\u81ea\u8eabAny\u5bb9\u5668\u7684_content\u6307\u9488\u4ea4\u6362<\/span><br \/>\n        <span class=\"token comment\">\/\/\u4ea4\u6362\u540e\u4e0d\u4f1a\u518d\u5173\u5fc3\u81ea\u8eab\u5bb9\u5668\u7684_content\u4e86&#xff0c;\u56e0\u4e3a\u4ea4\u6362\u4e4b\u540e&#xff0c;\u4e34\u65f6\u5bf9\u8c61\u51fa\u4e86\u4f5c\u7528\u57df\u4f1a\u8c03\u7528\u6790\u6784\u51fd\u6570\u8fdb\u884c\u9500\u6bc1<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/\u6b64\u65f6\u4fdd\u7559\u7684\u5c31\u662fval\u6784\u9020\u51fa\u6765\u7684_content;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token operator\">*<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u4e3a\u4e86\u652f\u6301\u8fde\u7eed\u8d4b\u503c<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    Any<span class=\"token operator\">&amp;<\/span> <span class=\"token keyword\">operator<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> Any<span class=\"token operator\">&amp;<\/span> other<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">Any<\/span><span class=\"token punctuation\">(<\/span>other<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">swap<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/\u8c03\u7528\u62f7\u8d1d\u6784\u9020\u4e3aother\u5bf9\u8c61\u6784\u9020\u4e00\u4e2a\u65b0\u7684\u4e34\u65f6Any\u5bf9\u8c61&#xff0c;\u7528\u8be5\u5bf9\u8c61\u4e0e\u6211\u81ea\u8eab\u7684_content\u6307\u9488\u4ea4\u6362&#xff0c;\u4ea4\u6362\u540e<\/span><br \/>\n        <span class=\"token comment\">\/\/\u539f\u6765_content\u6307\u9488\u4fdd\u5b58\u7684\u6570\u636e\u5c31\u8ddf\u968f\u4e34\u65f6\u5bf9\u8c61\u8c03\u7528\u6790\u6784\u9500\u6bc1\u4e86<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/\u8fd9\u6837\u65e2\u4e0d\u5f71\u54cd\u5230other&#xff0c;\u53c8\u80fd\u9500\u6bc1\u539f\u6307\u9488\u6307\u5411\u7684\u6570\u636e\u3002<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token operator\">*<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/\u652f\u6301\u8fde\u7eed\u7684\u8d4b\u503c\u91cd\u8f7d<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<h2>\u670d\u52a1\u5668\u8bbe\u8ba1\u6a21\u5f0f<\/h2>\n<p>\u670d\u52a1\u5668\u4f7f\u7528Reactor\u7684\u4e8b\u4ef6\u76d1\u542c\u548c\u5206\u53d1\u5904\u7406\u5206\u79bb\u7684\u8bbe\u8ba1\u6a21\u5f0f\u3002<\/p>\n<p>\u7b80\u5355\u89e3\u91ca\u5c31\u662f&#xff1a;\u8c01\u89e6\u53d1\u4e86\u6211\u7684\u4e8b\u4ef6&#xff0c;\u6211\u5c31\u5904\u7406\u8c01\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234151-682d133f4f78f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u4e0b\u9762\u6709\u4e09\u79cd\u6a21\u5f0f\u4ecb\u7ecd&#xff0c;\u4f46\u672c\u6b21\u9879\u76ee\u6700\u4e3b\u8981\u91c7\u7528\u7684\u662f\u7b2c\u4e09\u79cd\u6a21\u5f0f&#xff1a;\u591aReactor\u591a\u7ebf\u7a0b\u6a21\u5f0f\u3002<\/p>\n<h4>1&#xff09;\u5355Reactor\u5355\u7ebf\u7a0b\u6a21\u5f0f<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234151-682d133f78dfb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4f18\u70b9&#xff1a;\u6240\u6709\u64cd\u4f5c\u5747\u5728\u5355\u4e00\u7ebf\u7a0b\u5b8c\u6210&#xff0c;\u5b9e\u73b0\u8f83\u4e3a\u7b80\u5355&#xff0c;\u6ca1\u6709\u7ebf\u7a0b\u95f4\u7ade\u4e89\u95ee\u9898\u3002 \u7f3a\u70b9&#xff1a;\u65e0\u6cd5\u6709\u6548\u5229\u7528CPU\u591a\u6838\u8d44\u6e90&#xff0c;\u5bb9\u6613\u8fbe\u5230\u6027\u80fd\u74f6\u9888\u3002<\/p>\n<h4>2&#xff09;\u5355Reactor\u591a\u7ebf\u7a0b\u6a21\u5f0f<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234151-682d133fb94e4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4f18\u70b9&#xff1a;\u5229\u7528\u4e86CPU\u591a\u6838\u7684\u4f18\u52bf&#xff0c;\u63d0\u9ad8\u4e86\u6027\u80fd&#xff0c;\u5c06\u4e1a\u52a1\u5904\u7406\u548cIO\u8fc7\u7a0b\u5206\u79bb&#xff0c;\u964d\u4f4e\u4e86\u4ee3\u7801\u7684\u8026\u5408\u5ea6\u3002 \u7f3a\u70b9&#xff1a;\u5355Reactor\u7ebf\u7a0b\u5305\u542b\u4e86\u5bf9\u5ba2\u6237\u7aef\u8fdb\u884c\u76d1\u542c\u548c\u54cd\u5e94&#xff0c;\u5728\u9ad8\u5e76\u53d1\u60c5\u51b5\u4e0b&#xff0c;\u4ecd\u7136\u662f\u4e00\u4e2a\u4e32\u884c\u5316\u8fc7\u7a0b&#xff0c;\u4e5f\u5c31\u662f\u5728\u6bcf\u4e00\u65f6\u523b\u90fd\u6709\u591a\u4e2a\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42&#xff0c;\u5355Reactor\u7ebf\u7a0b\u9700\u8981\u5904\u7406\u5b8c\u4e0a\u4e00\u4e2a\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u624d\u80fd\u5904\u7406\u4e0b\u4e2a\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42&#xff0c;\u53ea\u6709\u5904\u7406\u5b8c\u8bf7\u6c42\u65f6&#xff0c;\u624d\u80fd\u5904\u7406\u4e0b\u4e00\u6ce2\u5ba2\u6237\u7aef\u7684\u65b0\u8fde\u63a5&#xff0c;\u5bb9\u6613\u8fbe\u5230\u6027\u80fd\u74f6\u9888\u3002<\/p>\n<h4>3&#xff09;\u591aReactor\u591a\u7ebf\u7a0b\u6a21\u5f0f&#xff08;\u672c\u6b21\u9879\u76ee\u4e3b\u8981\u501f\u9274\u7684\u6a21\u5f0f&#xff09;<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234152-682d13403ab07.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4f18\u70b9&#xff1a;\u5145\u5206\u5229\u7528CPU\u591a\u6838\u8d44\u6e90&#xff0c;\u4e3b\u4eceReactor\u5404\u53f8\u5176\u804c\u3002 \u7f3a\u70b9&#xff1a;\u6267\u884c\u6d41\u4e0d\u662f\u8d8a\u591a\u8d8a\u597d&#xff0c;\u5982\u679c\u6267\u884c\u6d41\u8fc7\u591a&#xff0c;\u53cd\u800c\u4f1a\u589e\u52a0CPU\u5bf9\u7ebf\u7a0b\u5207\u6362\u8c03\u5ea6\u7684\u6210\u672c\u3002<\/p>\n<h4>\u9879\u76ee\u5b9e\u73b0\u76ee\u6807\u6846\u67b6<\/h4>\n<p>\u8be5\u9879\u76ee\u8981\u5b9e\u73b0\u7684\u662f\u4e00\u4e2a\u57fa\u4e8eReactor\u6a21\u5f0f\u4e0b\u7684 one thread one loop\u5f0f\u7684\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u3002\u7b80\u5355\u7406\u89e3\u5c31\u662f\u4e00\u4e2aReactor\u4ece\u5c5e\u7ebf\u7a0b\u5904\u7406&#xff1a;<\/p>\n<ul>\n<li>1.IO\u4e8b\u4ef6\u76d1\u63a7<\/li>\n<li>2.IO\u4e8b\u4ef6\u5904\u7406<\/li>\n<li>3.\u4e1a\u52a1\u5904\u7406<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234152-682d1340de3b8.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u4e5f\u5c31\u662f\u5728\u591aReactor\u591a\u7ebf\u7a0b\u7684\u57fa\u7840\u4e0a&#xff0c;\u5220\u6389\u4e13\u95e8\u8fdb\u884c\u4e1a\u52a1\u5904\u7406\u7684\u7ebf\u7a0b\u6c60&#xff0c;\u5c06IO\u4e8b\u4ef6\u7684\u76d1\u542c&#xff0c;\u5904\u7406\u4ee5\u53ca\u4e1a\u52a1\u5904\u7406\u96c6\u4e3a\u4e00\u4f53&#xff0c;\u7531\u4ece\u5c5eReactor\u7ebf\u7a0b\u4e00\u5e76\u5904\u7406\u3002<\/p>\n<p>\u4e0b\u9762\u6765\u4ecb\u7ecdServer\u670d\u52a1\u5668\u6a21\u5757\u7684\u5404\u4e2a\u5b50\u529f\u80fd\u6a21\u5757\u3002<\/p>\n<h3>\u4e00\u3001Server\u670d\u52a1\u5668\u6a21\u5757<\/h3>\n<p>\u8be5\u6a21\u5757\u5c31\u662f\u5bf9\u6240\u6709\u8fde\u63a5\u548c\u7ebf\u7a0b\u8fdb\u884c\u7ba1\u7406\u3002 \u5177\u4f53\u5206\u4e3a&#xff1a;<\/p>\n<ul>\n<li>1.\u76d1\u542c\u8fde\u63a5\u7ba1\u7406<\/li>\n<li>2.\u901a\u4fe1\u8fde\u63a5\u7ba1\u7406<\/li>\n<li>3.\u8d85\u65f6\u8fde\u63a5\u7ba1\u7406<\/li>\n<\/ul>\n<h4>1&#xff09;Buffer\u6a21\u5757<\/h4>\n<p>\u4e0b\u9762\u662fBuffer\u6a21\u5757\u7684\u8bbe\u8ba1\u601d\u8def&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234153-682d13416445f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>2&#xff09;Socket\u6a21\u5757<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234153-682d1341e5e6a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> Socket\u6a21\u5757\u662f\u5bf9socket\u5957\u63a5\u5b57\u7684\u5c01\u88c5&#xff0c;\u8be5\u6a21\u5757\u5b9e\u73b0\u4e86socket\u5957\u63a5\u5b57\u7684\u5404\u9879\u64cd\u4f5c\u3002<\/p>\n<h5>\u77e5\u8bc6\u70b9&#xff1a;\u5f00\u542f\u5730\u5740\u91cd\u7528<\/h5>\n<p>\u7aef\u53e3\u91cd\u7528\u9009\u9879&#xff08;SO_REUSEADDR&#xff09;\u5141\u8bb8\u5728\u540c\u4e00\u5730\u5740\u548c\u7aef\u53e3\u4e0a\u7ed1\u5b9a\u591a\u4e2a\u5957\u63a5\u5b57&#xff0c;\u5e38\u7528\u4e8e\u591a\u7ebf\u7a0b\u670d\u52a1\u5668\u548c\u5feb\u901f\u91cd\u542f\u670d\u52a1\u5668\u7a0b\u5e8f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234154-682d134239d5f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\">\/* int setsockopt(int socket,int level,<br \/>\n       int opt_name,void* opt_val,socklen_t opt_len);<br \/>\n*\/<\/span><br \/>\n <span class=\"token keyword\">void<\/span> <span class=\"token function\">ReuseAddress<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n <span class=\"token punctuation\">{<\/span><br \/>\n     <span class=\"token keyword\">int<\/span> val <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n                                 <span class=\"token comment\">\/\/SOL_SOCKET\u662f\u5bf9\u5957\u63a5\u5b57\u64cd\u4f5c\u7ea7\u522b<\/span><br \/>\n     <span class=\"token keyword\">int<\/span> ret <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">setsockopt<\/span><span class=\"token punctuation\">(<\/span>_sockfd<span class=\"token punctuation\">,<\/span> SOL_SOCKET<span class=\"token punctuation\">,<\/span> SO_REUSEADDR<span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">void<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&amp;<\/span>val<span class=\"token punctuation\">,<\/span><span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>val<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n     val <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n     <span class=\"token keyword\">int<\/span> ret1 <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">setsockopt<\/span><span class=\"token punctuation\">(<\/span>_sockfd<span class=\"token punctuation\">,<\/span> SOL_SOCKET<span class=\"token punctuation\">,<\/span> SO_REUSEPORT<span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">void<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&amp;<\/span>val<span class=\"token punctuation\">,<\/span><span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>val<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p> <span class=\"token punctuation\">}<\/span><\/p>\n<h4>3&#xff09;Channel\u6a21\u5757<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234155-682d13430d8d0.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> Channel\u6a21\u5757\u76f8\u5f53\u4e8e\u662f\u4e3asocket\u76d1\u63a7\u5230\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u800c\u751f\u7684\u3002<\/p>\n<p>Channel\u6a21\u5757\u7c7b\u8bbe\u8ba1\u601d\u60f3 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234155-682d134374b08.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff1a;Channel\u6a21\u5757\u5e76\u4e0d\u662f\u72ec\u7acb\u7684&#xff0c;\u7531\u4e8e\u8981\u5bf9\u6587\u4ef6\u63cf\u8ff0\u7b26\u5bf9\u5e94\u7684\u8fde\u63a5\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u6240\u4ee5\u8981\u8c03\u7528Poller\u6a21\u5757\u7684\u529f\u80fd\u8fdb\u884c\u5177\u4f53\u7684\u4e8b\u4ef6\u76d1\u63a7\u3002<\/p>\n<h4>4&#xff09;Poller\u6a21\u5757<\/h4>\n<p>Poller\u662f\u7528\u6765\u76d1\u542c\u7ba1\u7406Channel\u7684&#xff0c;\u76f8\u5f53\u4e8e\u6240\u6709\u4e00\u5bf9\u4e00\u670d\u52a1\u5458\u7684\u603b\u7ecf\u7406\u3002<\/p>\n<p>\u76d1\u63a7IO\u4e8b\u4ef6&#xff0c;\u76f8\u5f53\u4e8e\u628a\u6240\u6709IO\u4e8b\u4ef6\u6587\u4ef6\u63cf\u8ff0\u7b26\u90fd\u653e\u5230\u4e00\u4e2a\u5177\u4f53\u7684\u5bb9\u5668\u4e2d\u7ba1\u7406\u8d77\u6765\u3002 Poller\u6a21\u5757\u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u5c31\u662f\u4f7f\u7528\u7ea2\u9ed1\u6811\u5c06\u4e00\u4e2a\u4e2a\u8981\u76d1\u63a7\u7684\u65f6\u95f4\u6dfb\u52a0\u8fdb\u7ea2\u9ed1\u6811\u7684\u8282\u70b9\u4e2d\u3002 Poller\u6a21\u5757\u8bbe\u8ba1\u601d\u8def&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234155-682d1343bbada.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> <img decoding=\"async\" src=\"2025-05-21jojaux3p0ow.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>5&#xff09;EventLoop\u6a21\u5757<\/h4>\n<h5>\u7cfb\u7edf\u63a5\u53e3eventfd\u2014\u2014\u7ebf\u7a0b\u95f4\u7684\u4e8b\u4ef6\u901a\u77e5<\/h5>\n<p><img decoding=\"async\" src=\"2025-05-21oqgwqxelakj.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u603b\u7ed3&#xff1a; \u5411eventfd\u8fd4\u56de\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5199\u5165\u6570\u636e\u65f6&#xff0c;\u4f1a\u89e6\u53d1\u4e8b\u4ef6\u901a\u77e5&#xff0c;\u5982\u679c\u5176\u4ed6\u8fdb\u7a0b\u6216\u7ebf\u7a0b\u6b63\u5728\u7b49\u5f85&#xff08;\u4f8b\u5982\u901a\u8fc7 poll()\u3001select() \u6216 epoll() \u76d1\u542c\u8be5\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff09;&#xff0c;\u5b83\u4eec\u4f1a\u88ab\u5524\u9192\u3002 \u8bfb\u53d6eventfd\u8fd4\u56de\u7684\u6587\u4ef6\u7b26\u7684\u6570\u636e\u65f6&#xff0c;\u4f1a\u6d88\u8d39\u4e8b\u4ef6\u3002<\/p>\n<hr \/>\n<p>EventLoop\u6a21\u5757\u53ef\u4ee5\u7406\u89e3\u6210\u4e0a\u8fb9\u6240\u8bf4\u7684Reactor\u6a21\u5757&#xff0c;\u5b83\u662f\u5bf9Poller\u6a21\u5757&#xff0c;TimerQueue\u6a21\u5757&#xff0c; Socket\u6a21\u5757\u7684\u2f00\u4e2a\u6574\u4f53\u5c01\u88c5&#xff0c;\u8fdb\u2f8f\u6240\u6709\u63cf\u8ff0\u7b26\u7684\u4e8b\u4ef6\u76d1\u63a7\u3002 \u540c\u65f6&#xff0c;EventLoop\u6a21\u5757\u4e00\u5b9a\u662f\u4e00\u4e2aEventLoop\u5bf9\u5e94\u4e00\u4e2aConnection\u8fde\u63a5\u3002<\/p>\n<p>Eventoop\u6a21\u5757\u4e3a\u4e86\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168&#xff0c;\u56e0\u6b64\u5fc5\u987b\u4fdd\u8bc1\u6574\u4e2aConnection\u8fde\u63a5\u7684\u6240\u6709\u64cd\u4f5c\u90fd\u8981\u5728\u540c\u4e00\u7ebf\u7a0b\u4e0b\u6267\u884c\u3002<\/p>\n<p>\u7531\u4e8eEventLoop\u6a21\u5757\u76d1\u63a7\u4e86\u6240\u6709\u4e8b\u4ef6&#xff0c;\u4e14\u6dfb\u52a0\u4e86\u4e0a\u9762\u7684TimerWheel\u65f6\u95f4\u8f6e&#xff0c;\u6240\u4ee5\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u94fe\u63a5\u90fd\u8bbe\u7f6e\u4e00\u4e2a\u975e\u6d3b\u8dc3\u94fe\u63a5\u5b9a\u65f6\u9500\u6bc1\u4efb\u52a1&#xff0c;\u53ea\u8981\u94fe\u63a5\u5728\u89c4\u5b9a\u65f6\u95f4\u5185\u6ca1\u6709\u8fdb\u884c\u901a\u4fe1&#xff0c;\u5c31\u91ca\u653e\u8be5\u94fe\u63a5&#xff0c;\u907f\u514d\u94fe\u63a5\u7a7a\u8017\u8d44\u6e90\u3002<\/p>\n<p>\u5982\u4f55\u4fdd\u8bc1\u4e00\u4e2aConnection\u8fde\u63a5\u7684\u6240\u6709\u64cd\u4f5c\u90fd\u653e\u5728\u540c\u4e00\u4e2a\u7ebf\u7a0b\u4e2d\u6267\u884c&#xff1f; \u5c06\u8be5\u94fe\u63a5\u7684\u6240\u6709\u64cd\u4f5c\u90fd\u653e\u5165\u5230\u4e00\u4e2aQueueTask\u4efb\u52a1\u961f\u5217\u4e2d&#xff0c;\u7531EventLoop\u8fdb\u884c\u7ba1\u7406\u3002 \u5f53\u4e8b\u4ef6\u5904\u7406\u5b8c\u6210\u540e&#xff0c;\u518d\u5728EventLoop\u5bf9\u5e94\u7684\u7ebf\u7a0b\u4e2d\u6267\u884c\u4efb\u52a1\u961f\u5217\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u4f46\u662f&#xff0c;\u56e0\u4e3aEventLoop\u7684\u6240\u6709\u4e8b\u4ef6\u76d1\u63a7\u90fd\u4ea4\u7ed9\u4e86Poller\u6a21\u5757\u4e2d\u7684epoll\u76d1\u63a7&#xff0c;\u5982\u679c\u6ca1\u6709\u4e8b\u4ef6\u5c31\u7eea&#xff0c;epoll\u5c31\u4f1a\u963b\u585e\u4f4f&#xff0c;\u5219\u4efb\u52a1\u961f\u5217\u4e2d\u7684\u4efb\u52a1\u5c31\u4e0d\u80fd\u6267\u884c\u3002 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;eventfd\u7684\u4f5c\u7528\u5c31\u51fa\u73b0\u4e86&#xff1a;\u5f53\u5411\u4efb\u52a1\u961f\u5217\u4e2d\u6dfb\u52a0\u4efb\u52a1\u65f6&#xff0c;\u5c31\u53ef\u4ee5\u901a\u8fc7\u5411eventfd\u4e2d\u5199\u5165\u6570\u636e\u6765\u5524\u9192\u6b63\u5728\u963b\u585e\u7684epoll&#xff0c;\u4ece\u800c\u8ba9\u4efb\u52a1\u6c60\u7684\u64cd\u4f5c\u80fd\u591f\u6267\u884c\u3002<\/p>\n<p>EventLoop\u5177\u4f53\u64cd\u4f5c\u6d41\u7a0b&#xff1a;<\/p>\n<ul>\n<li>EventLoop\u7684Poller\u6a21\u5757\u5bf9\u5f53\u524d\u7ba1\u7406\u7684\u6240\u6709\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u5f53\u6709\u4e8b\u4ef6\u5230\u6765\u65f6&#xff0c;\u5c06\u4e8b\u4ef6\u5206\u53d1\u7ed9\u6587\u4ef6\u63cf\u8ff0\u7b26\u5bf9\u5e94\u7684Channel\u8fdb\u884c\u4e8b\u4ef6\u5904\u7406\u3002<\/li>\n<li>\u5f53\u6240\u6709\u7684\u5c31\u7eea\u4e8b\u4ef6\u90fd\u5904\u7406\u5b8c\u6bd5\u540e&#xff0c;\u5bf9\u4efb\u52a1\u961f\u5217QueueTask\u4e2d\u7684\u6240\u6709\u4efb\u52a1\u8fdb\u884c\u6267\u884c\u3002<\/li>\n<li>\u7531\u4e8eepoll\u7684\u4e8b\u4ef6\u76d1\u63a7&#xff0c;\u6709\u53ef\u80fd\u56e0\u4e3a\u6ca1\u6709\u4e8b\u4ef6\u5230\u6765\u800c\u963b\u585e&#xff0c;\u5bfc\u81f4\u4efb\u52a1\u4e0d\u80fd\u6709\u6548\u6267\u884c\u3002\u6240\u4ee5\u521b\u5efa\u4e86eventfd&#xff0c;\u6dfb\u52a0\u5230Poller\u7684\u4e8b\u4ef6\u76d1\u63a7\u4e2d&#xff0c;\u6bcf\u6b21\u5411\u4efb\u52a1\u961f\u5217\u4e2d\u6dfb\u52a0\u4efb\u52a1\u65f6&#xff0c;\u901a\u8fc7\u5411eventfd\u5199\u5165\u6570\u636e&#xff0c;\u6765\u5524\u9192\u963b\u585e\u7684epoll\u3002<\/li>\n<li><\/li>\n<\/ul>\n<p>EventLoop\u8054\u5408\u5176\u4ed6\u6a21\u5757\u7684\u601d\u60f3\u6d41\u7a0b\u56fe&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"2025-05-21gvz5fvzrpnp.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"2025-05-21emt3eqvyekg.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>6&#xff09;TimerTask\u548cTimerWheel\u6a21\u5757<\/h4>\n<h4>7&#xff09; Connection\u6a21\u5757<\/h4>\n<p>Connection\u6a21\u5757\u662f\u5bf9Buffer&#xff0c;Socket&#xff0c;Channel\u6a21\u5757\u8fdb\u884c\u6574\u5408\u5e76\u5c01\u88c5&#xff0c;\u5b9e\u73b0\u6574\u4f53\u5bf9\u5957\u63a5\u5b57\u7684\u7ba1\u7406\u3002 Connection\u6a21\u5757\u4e3a\u6bcf\u4e00\u4e2a\u670d\u52a1\u5668Accept\u5230\u7684\u65b0\u94fe\u63a5\u90fd\u8bbe\u7f6e\u4e00\u4e2aConnection\u5bf9\u8c61\u8fdb\u884c\u7ba1\u7406\u3002 \u5bf9\u94fe\u63a5\u7684\u6240\u6709\u5177\u4f53\u64cd\u4f5c&#xff0c;\u90fd\u662f\u901a\u8fc7\u8fd9\u4e2a\u6a21\u5757\u63d0\u4f9b\u7684\u529f\u80fd\u5b8c\u6210\u3002<\/p>\n<p>\u5728Connection\u4e2d\u7ba1\u7406\u7684\u51e0\u4e2a\u90e8\u5206&#xff1a;<\/p>\n<ul>\n<li>1.\u5957\u63a5\u5b57\u7ba1\u7406<\/li>\n<li>2.\u8fde\u63a5\u7684\u4e8b\u4ef6\u7ba1\u7406<\/li>\n<li>3.\u7f13\u51b2\u533a\u7ba1\u7406&#xff0c;\u5c06Socket\u6a21\u5757\u63a5\u6536\u5230\u7684\u6570\u636e\u62ff\u8fc7\u6765\u653e\u5230\u6211\u5f53\u4e0b\u7684\u7f13\u51b2\u533a\u6a21\u5757\u4e2d\u3002<\/li>\n<li>4.\u534f\u8bae\u4e0a\u4e0b\u6587\u7684\u7ba1\u7406&#xff08;Any\u7c7b&#xff09;&#xff08;\u6709\u53ef\u80fd\u8bf7\u6c42\u8fd8\u4e0d\u5b8c\u6574&#xff0c;\u6216\u8005\u8bf7\u6c42\u7684\u6b63\u6587\u8fd8\u6ca1\u6709\u53d1\u9001\u5b8c&#xff0c;\u5219\u5c06\u6570\u636e\u4fdd\u5b58\u5230Any\u7c7b\u4e2d&#xff0c;\u7b49\u5f85\u4e0b\u6b21\u8bf7\u6c42\u53d1\u9001\u5b8c\u6210\u540e\u518d\u53d6\u51fa\u6765\u8fdb\u884c\u89e3\u6790\u3002<\/li>\n<li>5.\u56de\u8c03\u51fd\u6570\u7684\u7ba1\u7406&#xff0c;\u8bbe\u7f6e\u5404\u79cd\u56de\u8c03\u51fd\u6570&#xff0c;\u7136\u540e\u4ea4\u7ed9Channel\u6a21\u5757\u5177\u4f53\u6267\u884c\u3002<\/li>\n<\/ul>\n<p>Connection\u6a21\u5757\u8bbe\u8ba1\u601d\u60f3&#xff1a; <img decoding=\"async\" src=\"2025-05-21czs5vodgxst.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u5c06Conenction\u6a21\u5757\u4ea4\u7ed9shared_ptr\u8fdb\u884c\u7ba1\u7406\u5462&#xff1f; \u56e0\u4e3a\u4e00\u65e6\u8981\u5bf9Connection\u94fe\u63a5\u8fdb\u884c\u64cd\u4f5c&#xff0c;\u800cConnection\u94fe\u63a5\u5df2\u7ecf\u91ca\u653e&#xff0c;\u5176\u4ed6\u5730\u65b9\u5e76\u4e0d\u77e5\u9053Connection\u91ca\u653e\u4e86&#xff0c;\u8fd9\u5c31\u5bfc\u81f4\u5185\u5b58\u9519\u8bef\u8bbf\u95ee\u3002 \u4f7f\u7528shared_ptr\u5bf9Connection\u8fdb\u884c\u64cd\u4f5c\u7684\u65f6\u5019&#xff0c;\u4fdd\u5b58\u4e86\u4e00\u4efdshared_ptr&#xff0c;\u56e0\u6b64\u5c31\u7b97\u5176\u4ed6\u5730\u65b9\u8fdb\u884c\u4e86\u91ca\u653e\u64cd\u4f5c&#xff0c;\u4e5f\u53ea\u662f\u5bf9shared_ptr\u7684\u8ba1\u6570\u5668-1.\u5e76\u4e0d\u4f1a\u5bfc\u81f4Connection\u91ca\u653e\u3002<\/p>\n<p>\u5b9e\u73b0\u64cd\u4f5c&#xff1a;\u8ba9Connection\u7ee7\u627fstd::enable_shared_from_this&lt;Connection&gt; &#xff0c;\u8fd9\u6837\u5728\u5bf9Connection\u64cd\u4f5c\u65f6&#xff0c;\u5c31\u53ef\u4ee5\u5b89\u5168\u5730\u4f20\u9012\u4e00\u4efdshared_ptr&lt;Connection&gt;\u3002<\/p>\n<p>Connection\u6a21\u5757\u8054\u5408\u5176\u4ed6\u6a21\u5757\u7684\u529f\u80fd\u5173\u7cfb\u6d41\u7a0b\u56fe&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"2025-05-21cewcguao2y5.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u6ce8\u610f&#xff0c;Connection\u6a21\u5757\u4e5f\u4e0d\u662f\u72ec\u7acb\u7684\u6a21\u5757&#xff0c;\u5b83\u4e0d\u4ec5\u4ec5\u5bf9\u4e0a\u8ff0\u6a21\u5757\u6574\u5408&#xff0c;\u7531\u4e8e\u8be5\u670d\u52a1\u5668\u662f\u591aReactor\u591a\u7ebf\u7a0b\u6a21\u5f0f&#xff0c;\u6709\u591a\u7ebf\u7a0b\u5c31\u6d89\u53ca\u5230\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898&#xff0c;\u6240\u4ee5\u6709\u4e9b\u64cd\u4f5c\u5fc5\u987b\u53ea\u80fd\u5728\u7ebf\u7a0b\u5185\u6267\u884c&#xff0c;\u6240\u4ee5\u5c31\u5173\u8054\u5230EventLoop\u6a21\u5757\u3002<\/p>\n<h4>8&#xff09;Acceptor\u6a21\u5757<\/h4>\n<p>\u8bbe\u8ba1\u601d\u60f3&#xff1a; <img decoding=\"async\" src=\"2025-05-213m3dzqjf55u.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>9&#xff09;LoopThread\u6a21\u5757<\/h4>\n<h5>\u7ebf\u7a0b\u95f4\u7684\u540c\u6b65\u548c\u4e92\u65a5\u77e5\u8bc6\u70b9<\/h5>\n<p>\u7ebf\u7a0b\u7684\u540c\u6b65\u5c31\u662f\u5f53\u591a\u4e2a\u7ebf\u7a0b\u83b7\u53d6\u540c\u4e00\u4e2a\u5171\u4eab\u8d44\u6e90\u65f6&#xff0c;\u9700\u8981\u8fdb\u884c\u6392\u961f&#xff0c;\u4e0d\u80fd\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u5e76\u53d1\u83b7\u53d6\u540c\u4e00\u4e2a\u5171\u4eab\u8d44\u6e90\u3002\u6240\u4ee5\u7ebf\u7a0b\u7684\u540c\u6b65\u5c31\u662f\u7ebf\u7a0b\u6392\u961f\u83b7\u53d6\u5171\u4eab\u8d44\u6e90\u3002<\/p>\n<p>\u7ebf\u7a0b\u95f4\u7684\u4e92\u65a5&#xff0c;\u5f53\u6211\u8fd9\u4e2a\u7ebf\u7a0b\u5728\u7533\u8bf7\u5171\u4eab\u8d44\u6e90\u65f6&#xff0c;\u4f60\u7684\u7ebf\u7a0b\u5c31\u4e0d\u80fd\u7533\u8bf7\u5171\u4eab\u8d44\u6e90\u3002 \u8fd9\u6837\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5171\u4eab\u8d44\u6e90&#xff08;\u4e34\u754c\u8d44\u6e90&#xff09;\u53ea\u80fd\u540c\u65f6\u6709\u4e00\u4e2a\u7ebf\u7a0b\u7533\u8bf7\u3002\u8fd9\u5c31\u662f\u7ebf\u7a0b\u95f4\u7684\u4e92\u65a5\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;\u7ebf\u7a0b\u540c\u6b65\u548c\u4e92\u65a5\u662f\u540c\u65f6\u5b58\u5728\u7684\u3002<\/p>\n<p><img decoding=\"async\" src=\"2025-05-21gafajbbtq01.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>10&#xff09;LoopThreadPool\u6a21\u5757<\/h4>\n<p>\u8bbe\u8ba1\u601d\u60f3&#xff1a; <img decoding=\"async\" src=\"2025-05-21r3bkr4h0crd.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>\u4e8c\u3001HTTP\u534f\u8bae\u6a21\u5757<\/h3>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662fHTTP\u534f\u8bae\u662f\u2f00\u4e2a\u8fd0\u2f8f\u5728TCP\u534f\u8bae\u4e4b\u4e0a\u7684\u5e94\u2f64\u5c42\u534f\u8bae&#xff0c;\u8fd9\u2f00\u70b9\u672c\u8d28\u4e0a\u662f\u544a\u8bc9\u6211\u4eec&#xff0c;HTTP\u670d\u52a1\u5668\u5176\u5b9e\u5c31\u662f\u4e2aTCP\u670d\u52a1\u5668&#xff0c;\u53ea\u4e0d\u8fc7\u5728\u5e94\u2f64\u5c42\u57fa\u4e8eHTTP\u534f\u8bae\u683c\u5f0f\u8fdb\u2f8f\u6570\u636e\u7684\u7ec4\u7ec7\u548c\u89e3\u6790\u6765\u660e\u786e\u5ba2\u2f3e\u7aef\u7684\u8bf7\u6c42\u5e76\u5b8c\u6210\u4e1a\u52a1\u5904\u7406\u3002<\/p>\n<p>\u56e0\u6b64\u5b9e\u73b0HTTP\u670d\u52a1\u5668\u7b80\u5355\u7406\u89e3&#xff0c;\u53ea\u9700\u8981\u4ee5\u4e0b\u2f0f\u6b65\u5373\u53ef<\/p>\n<li>\u642d\u5efa\u2f00\u4e2aTCP\u670d\u52a1\u5668&#xff0c;\u63a5\u6536\u5ba2\u6237\u7aef\u8bf7\u6c42\u3002<\/li>\n<li>\u4ee5HTTP\u534f\u8bae\u683c\u5f0f\u8fdb\u2f8f\u89e3\u6790\u8bf7\u6c42\u6570\u636e&#xff0c;\u660e\u786e\u5ba2\u6237\u7aef\u2f6c\u7684\u3002<\/li>\n<li>\u660e\u786e\u5ba2\u6237\u7aef\u8bf7\u6c42\u2f6c\u7684\u540e\u63d0\u4f9b\u5bf9\u5e94\u670d\u52a1\u3002<\/li>\n<li>\u5c06\u670d\u52a1\u7ed3\u679c\u2f00HTTP\u534f\u8bae\u683c\u5f0f\u8fdb\u2f8f\u7ec4\u7ec7&#xff0c;\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef<\/li>\n<h4>\u8bbe\u8ba1\u601d\u60f3<\/h4>\n<p><img decoding=\"async\" src=\"2025-05-21nmvc52marc2.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u5e94\u7528\u5c42\u534f\u8bae&#xff1a;Http\u670d\u52a1\u5668\u8bbe\u8ba1<\/h2>\n<h3>2)HttpRequest\u6a21\u5757<\/h3>\n<p><img decoding=\"async\" src=\"2025-05-21324tkus0v4b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>3)HttpResponse\u6a21\u5757<\/h3>\n<p><img decoding=\"async\" src=\"2025-05-21acmbj5jzkpa.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>4)HttpContext\u5bf9Http\u8bf7\u6c42\u8fdb\u884c\u89e3\u6790\u6a21\u5757<\/h3>\n<p>\u8fd9\u4e2a\u6a21\u5757\u662f\u2f00\u4e2aHTTP\u8bf7\u6c42\u63a5\u6536\u7684\u4e0a\u4e0b\u2f42\u6a21\u5757&#xff0c;\u4e3b\u8981\u662f\u4e3a\u4e86\u9632\u2f4c\u5728\u2f00\u6b21\u63a5\u6536\u7684\u6570\u636e\u4e2d&#xff0c;\u4e0d\u662f\u2f00\u4e2a\u5b8c\u6574\u7684HTTP\u8bf7\u6c42&#xff0c;\u5219\u89e3\u6790\u8fc7\u7a0b\u5e76\u672a\u5b8c\u6210&#xff0c;\u2f46\u6cd5\u8fdb\u2f8f\u5b8c\u6574\u7684\u8bf7\u6c42\u5904\u7406&#xff0c;\u9700\u8981\u5728\u4e0b\u6b21\u63a5\u6536\u5230\u65b0\u6570\u636e\u540e\u7ee7\u7eed\u6839\u636e\u4e0a\u4e0b\u2f42\u8fdb\u2f8f\u89e3\u6790&#xff0c;\u6700\u7ec8\u5f97\u5230\u2f00\u4e2aHttpRequest\u8bf7\u6c42\u4fe1\u606f\u5bf9\u8c61&#xff0c;\u56e0\u6b64\u5728\u8bf7\u6c42\u6570\u636e\u7684\u63a5\u6536\u4ee5\u53ca\u89e3\u6790\u90e8\u5206\u9700\u8981\u2f00\u4e2a\u4e0a\u4e0b\u2f42\u6765\u8fdb\u2f8f\u63a7\u5236\u63a5\u6536\u548c\u5904\u7406\u8282\u594f\u3002<\/p>\n<p><img decoding=\"async\" src=\"2025-05-21g050d1qowca.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>HttpServer\u6a21\u5757&#xff1a;\u5bf9\u524d\u9762\u51e0\u4e2a\u6a21\u5757\u7684\u529f\u80fd\u6574\u5408<\/h3>\n<p><img decoding=\"async\" src=\"2025-05-21bvxheangojv.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u9047\u5230\u7684\u95ee\u9898<\/h2>\n<h3>1.vector\u5b9a\u4e49\u5728_capacity\u4e4b\u540e&#xff0c;\u5bfc\u81f4vector\u5728\u4f7f\u7528\u65f6\u6ca1\u6709\u5f00\u7a7a\u95f4\u800c\u76f4\u63a5\u4f7f\u7528[]\u8bbf\u95ee\u5bfc\u81f4\u7a7a\u95f4\u4f7f\u7528\u9519\u8bef\u95ee\u9898\u3002<\/h3>\n<p><img decoding=\"async\" src=\"2025-05-215s0aninftqc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>2.\u518d\u8c03\u8bd5Buffer\u7c7b\u7684\u63a5\u53e3\u51fd\u6570\u65f6&#xff0c;\u9884\u671f\u7ed3\u679c\u662f\u4ecei &#061; 1\u6253\u5370\u5230i &#061; 300<\/h3>\n<p><img decoding=\"async\" src=\"2025-05-21z1vox31dftx.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u7136\u800c\u5374\u51fa\u73b0\u4e86\u65ad\u5c42\u73b0\u8c61\u3002 \u7ecf\u8fc7\u8c03\u8bd5\u53d1\u73b0&#xff0c;<img decoding=\"async\" src=\"2025-05-214mbx4ba421a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u5728\u83b7\u53d6write\u524d\u6cbf\u7a7a\u95f4\u5927\u5c0f\u65f6&#xff0c;\u4ee3\u7801\u5199\u9519\u4e86&#xff0c;\u5e94\u8be5\u7528size\u7684\u3002<\/p>\n<p>\u6b64\u65f6\u6df7\u6dc6\u4e86capacity()\u548csize()\u51fd\u6570\u7684\u533a\u522b \u4ee5\u53ca\u5fd8\u8bb0\u4e86reserve&#xff08;&#xff09;\u548cresize&#xff08;&#xff09;\u51fd\u6570\u7684\u5177\u4f53\u7528\u6cd5\u3002 \u9042\u7acb\u5373\u590d\u4e60\u3002<\/p>\n<h3>3.<\/h3>\n<p><img decoding=\"async\" src=\"2025-05-21tljqidun5dz.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"2025-05-21j5fd43vhp4f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>4.\u5bf9Connection\u8054\u5408\u8c03\u8bd5\u65f6&#xff0c;\u672a\u5bf9_socket\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u5bfc\u81f4\u540e\u7eed\u65e0\u6cd5recv<\/h3>\n<p>\u77e5\u8bc6\u590d\u4e60&#xff1a;\u5728\u7c7b\u7684\u6210\u5458\u51fd\u6570\u540e\u9762\u52a0\u4e0aconst&#xff0c;\u8868\u793a\u544a\u8bc9\u7f16\u8bd1\u5668\u6211\u4e0d\u4f1a\u5728\u51fd\u6570\u5185\u90e8\u5bf9this\u6307\u9488\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<h3>5. \u8bf7\u6c42\u65b9\u6cd5\u5fc5\u987b\u662fGet\/Head\u65b9\u6cd5<\/h3>\n<p>\u5728\u5bf9http\u670d\u52a1\u5668\u8fdb\u884c\u6d4b\u8bd5\u65f6\u3002 \u5728\u5224\u65ad\u4e00\u4e2a\u8d44\u6e90\u662f\u5426\u662f\u9759\u6001\u8d44\u6e90\u7684\u65f6\u5019&#xff0c;\u8bf7\u6c42\u7684\u65b9\u6cd5\u5e94\u8be5\u5fc5\u987b\u662fGET\u65b9\u6cd5\u6216\u8005\u662fHEAD\u65b9\u6cd5\u3002 \u6240\u4ee5\u5728\u903b\u8f91\u5224\u65ad\u65f6&#xff1a;<\/p>\n<p>if(req._method !&#061; \u201cGET\u201d &amp;&amp; req._method !&#061; \u201cHEAD\u201d) \u5982\u679c\u8bf7\u6c42\u65b9\u6cd5\u4e0d\u662fGET\u65b9\u6cd5\u4e14\u4e0d\u662fHEAD\u65b9\u6cd5&#xff0c;\u5219\u5224\u65ad\u9519\u8bef&#xff0c;return false&#xff1b;<\/p>\n<p>\u800c\u6211\u7684\u4ee3\u7801\u5199\u6210\u4e86<\/p>\n<p>if(req._method !&#061; \u201cGET\u201d || req._method !&#061; \u201cHEAD\u201d) \u610f\u5473\u7740\u5c31\u7b97\u8be5\u65b9\u6cd5\u662fGET\u65b9\u6cd5&#xff0c;\u540c\u6837\u6ee1\u8db3req._method !&#061; &#034;HEAD&#034;\u8fd9\u4e2a\u5224\u65ad\u6761\u4ef6&#xff0c;\u4e5f\u4f1a\u9000\u51fa\u3002<\/p>\n<p>\u540c\u65f6\u8fd8\u5b66\u5230\u4e86\u5982\u4f55\u8fdb\u884c\u8c03\u8bd5&#xff0c;\u5148\u6839\u636e\u6b63\u5e38\u7684HTTP\u8bbf\u95ee\u7684\u6d41\u7a0b&#xff0c;\u5ba2\u6237\u7aef\u5bf9\u670d\u52a1\u5668\u8bbf\u95ee\u53d1\u9001\u6570\u636e\u65f6&#xff0c;\u670d\u52a1\u5668\u80af\u5b9a\u4f1a\u5bf9\u5230\u6765\u7684\u65b0\u94fe\u63a5\u8bbe\u7f6e\u56de\u8c03\u5904\u7406&#xff0c;\u7136\u540e\u5bf9HTTP\u8bf7\u6c42\u8fdb\u884c\u89e3\u6790&#xff0c;\u7136\u540e\u54cd\u5e94\u7ed9\u5ba2\u6237\u7aef\u3002 \u6839\u636e\u8fd9\u4e2a\u6d41\u7a0b\u770b\u8c03\u7528\u4e86\u54ea\u4e9b\u51fd\u6570&#xff0c;\u5206\u522b\u8fdb\u5165\u4e86\u54ea\u4e9b\u51fd\u6570&#xff0c;\u7136\u540e\u5c31\u6253\u5370\u4e00\u4e9b\u8c03\u8bd5\u4fe1\u606f\u4e00\u4e2a\u4e2a\u51fd\u6570\u5730\u67e5\u770b\u662f\u54ea\u4e2a\u51fd\u6570\u7684\u903b\u8f91\u51fa\u73b0\u4e86\u95ee\u9898&#xff01;&#xff01;<\/p>\n<h2>\u9879\u76ee\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9<\/h2>\n<h3>md5sum &#043; \u6587\u4ef6\u540d<\/h3>\n<p>\u5bf9\u4e00\u4e2a\u6587\u4ef6\u8fdb\u884c\u5927\u91cf\u7b97\u6cd5\u8ba1\u7b97&#xff0c;\u6700\u540e\u5f97\u51fa\u4e00\u4e2a\u6807\u51c6\u5b57\u7b26\u4e32md5&#xff0c;\u5982\u679c\u4e24\u4e2a\u6587\u4ef6\u7684md5\u503c\u662f\u4e00\u6837\u7684&#xff0c;\u5219\u8bf4\u660e\u8fd9\u4e24\u4e2a\u6587\u4ef6\u7684\u5185\u5bb9\u4e00\u6a21\u4e00\u6837&#xff0c;\u53ea\u8981\u4e24\u4e2a\u6587\u4ef6\u5185\u5bb9\u6709\u4e00\u70b9\u70b9\u70b9\u4e0d\u4e00\u6837&#xff0c;\u5219\u5f97\u51fa\u7684md5\u503c\u4e5f\u4f1a\u5927\u6709\u4e0d\u540c\u3002<\/p>\n<h3>\u4e0a\u4f20\u5927\u6587\u4ef6<\/h3>\n<p>dd if&#061;\/dev\/zero of&#061;.\/hello.txt bs&#061;1G count&#061;1<\/p>\n<h3>\u591a\u6001<\/h3>\n<p>\u901a\u7528\u7c7b\u578b\u5bb9\u5668Any\u7c7b&#xff0c;\u4fdd\u5b58\u7684\u662fholder\u7c7b\u7684\u6307\u9488&#xff08;\u5f15\u7528\u4e5f\u53ef\u4ee5&#xff09;&#xff0c;\u800cholder\u7c7b\u88abplaceholder\u7c7b\u7ee7\u627f&#xff0c;\u6240\u4ee5holder\u7c7b\u7684\u6307\u9488\u53ef\u4ee5\u8bbf\u95ee\u5230placeholder\u7c7b\u7684\u6210\u5458\u51fd\u6570&#xff0c;\u800c\u8ba9placeholder\u7c7b\u901a\u8fc7\u5b9e\u4f8b\u5316\u5bf9\u8c61\u4e13\u95e8\u7528\u6765\u4fdd\u5b58\u4efb\u610f\u7c7b\u578b\u7684\u6570\u636e\u3002<\/p>\n<h2>\u7ed9\u670d\u52a1\u5668\u4e0a\u5f3a\u5ea6<\/h2>\n<h3>1.\u957f\u94fe\u63a5\u8bf7\u6c42\u6d4b\u8bd5<\/h3>\n<h3>2.\u8d85\u65f6\u94fe\u63a5\u91ca\u653e\u6d4b\u8bd5<\/h3>\n<h3>3.\u6570\u636e\u4e2d\u591a\u6761\u8bf7\u6c42\u5904\u7406\u6d4b\u8bd5<\/h3>\n<h3>4.\u901a\u8fc7Put\u65b9\u6cd5\u4e0a\u4f20\u5927\u6587\u4ef6\u6d4b\u8bd5<\/h3>\n<p>\u6027\u80fd\u6d4b\u8bd5\u91c7\u2f64webbench\u8fdb\u2f8f\u670d\u52a1\u5668\u6027\u80fd\u6d4b\u8bd5\u3002Webbench\u662f\u77e5\u540d\u7684\u2f79\u7ad9\u538b\u2f12\u6d4b\u8bd5\u2f2f\u5177&#xff0c;webbench\u7684 \u6807\u51c6\u6d4b\u8bd5\u53ef\u4ee5\u5411\u6211\u4eec\u5c55\u2f70\u670d\u52a1\u5668\u7684\u4e24\u9879\u5185\u5bb9&#xff1a; \u6bcf\u79d2\u949f\u76f8\u5e94\u8bf7\u6c42\u6570 \u548c \u6bcf\u79d2\u949f\u4f20\u8f93\u6570\u636e\u91cf &#xff0c;\u5373QPS\u548c\u541e \u5410\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb789\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e00\u4e2a\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u7ec4\u4ef6\u7684\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\uff0c\u91c7\u7528\u591aReactor\u591a\u7ebf\u7a0b\u6a21\u5f0f\uff0c\u7ed3\u5408\u591aI\/O\u591a\u8def\u590d\u7528\u548c\u7ebf\u7a0b\u6c60\u6280\u672f\uff0c\u5145\u5206\u5229\u7528CPU\u591a\u6838\u8d44\u6e90\u8fdb\u884c\u5e76\u53d1\u4e1a\u52a1\u5904\u7406\u3002\u9879\u76ee\u5206\u4e3a\u670d\u52a1\u5668\u6a21\u5757\u548c\u534f\u8bae\u6a21\u5757\uff0c\u4e3b\u8981\u6d41\u7a0b\u5305\u62ecTcpServer\u5bf9\u8c61\u7684\u5b9e\u4f8b\u5316\u3001Acceptor\u5bf9\u8c61\u7684\u56de\u8c03\u8bbe\u7f6e\u3001BaseLoop\u7684\u542f\u52a8\u3001Poller\u6a21\u5757\u7684IO\u4e8b\u4ef6\u76d1\u63a7\u3001\u4efb\u52a1\u961f\u5217\u7684\u6267\u884c\u7b49\u3002\u6587\u7ae0\u8fd8\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u524d\u7f6e\u77e5\u8bc6\uff0c\u5982bind\u51fd\u6570\u7684\u4f7f\u7528\u3001\u5b9a\u65f6\u5668\u4efb\u52a1\u548c\u65f6\u95f4\u8f6e\u601d\u60f3\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\u7b49\uff0c\u7279\u522b\u662f\u5982\u4f55\u901a\u8fc7\u65f6\u95f4\u8f6e\u7b97\u6cd5\u4f18\u5316\u5b9a\u65f6\u4efb\u52a1\u7684\u6267\u884c\u6548\u7387\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u89e3\u6790HTTP\u8bf7\u6c42\u3002\u901a<\/p>\n","protected":false},"author":2,"featured_media":38682,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,3432,1084,190,43,3431,3433,3434],"topic":[],"class_list":["post-38702","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-eventfd","tag-linux","tag-190","tag-43","tag-3431","tag-3433","tag-3434"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011 - \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\/38702.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb789\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e00\u4e2a\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u7ec4\u4ef6\u7684\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\uff0c\u91c7\u7528\u591aReactor\u591a\u7ebf\u7a0b\u6a21\u5f0f\uff0c\u7ed3\u5408\u591aI\/O\u591a\u8def\u590d\u7528\u548c\u7ebf\u7a0b\u6c60\u6280\u672f\uff0c\u5145\u5206\u5229\u7528CPU\u591a\u6838\u8d44\u6e90\u8fdb\u884c\u5e76\u53d1\u4e1a\u52a1\u5904\u7406\u3002\u9879\u76ee\u5206\u4e3a\u670d\u52a1\u5668\u6a21\u5757\u548c\u534f\u8bae\u6a21\u5757\uff0c\u4e3b\u8981\u6d41\u7a0b\u5305\u62ecTcpServer\u5bf9\u8c61\u7684\u5b9e\u4f8b\u5316\u3001Acceptor\u5bf9\u8c61\u7684\u56de\u8c03\u8bbe\u7f6e\u3001BaseLoop\u7684\u542f\u52a8\u3001Poller\u6a21\u5757\u7684IO\u4e8b\u4ef6\u76d1\u63a7\u3001\u4efb\u52a1\u961f\u5217\u7684\u6267\u884c\u7b49\u3002\u6587\u7ae0\u8fd8\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u524d\u7f6e\u77e5\u8bc6\uff0c\u5982bind\u51fd\u6570\u7684\u4f7f\u7528\u3001\u5b9a\u65f6\u5668\u4efb\u52a1\u548c\u65f6\u95f4\u8f6e\u601d\u60f3\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\u7b49\uff0c\u7279\u522b\u662f\u5982\u4f55\u901a\u8fc7\u65f6\u95f4\u8f6e\u7b97\u6cd5\u4f18\u5316\u5b9a\u65f6\u4efb\u52a1\u7684\u6267\u884c\u6548\u7387\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u89e3\u6790HTTP\u8bf7\u6c42\u3002\u901a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38702.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-20T23:41:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234147-682d133bf011b.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=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38702.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38702.html\",\"name\":\"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-20T23:41:57+00:00\",\"dateModified\":\"2025-05-20T23:41:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38702.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38702.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38702.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011\"}]},{\"@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":"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011 - \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\/38702.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb789\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf27\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e00\u4e2a\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u7ec4\u4ef6\u7684\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\uff0c\u91c7\u7528\u591aReactor\u591a\u7ebf\u7a0b\u6a21\u5f0f\uff0c\u7ed3\u5408\u591aI\/O\u591a\u8def\u590d\u7528\u548c\u7ebf\u7a0b\u6c60\u6280\u672f\uff0c\u5145\u5206\u5229\u7528CPU\u591a\u6838\u8d44\u6e90\u8fdb\u884c\u5e76\u53d1\u4e1a\u52a1\u5904\u7406\u3002\u9879\u76ee\u5206\u4e3a\u670d\u52a1\u5668\u6a21\u5757\u548c\u534f\u8bae\u6a21\u5757\uff0c\u4e3b\u8981\u6d41\u7a0b\u5305\u62ecTcpServer\u5bf9\u8c61\u7684\u5b9e\u4f8b\u5316\u3001Acceptor\u5bf9\u8c61\u7684\u56de\u8c03\u8bbe\u7f6e\u3001BaseLoop\u7684\u542f\u52a8\u3001Poller\u6a21\u5757\u7684IO\u4e8b\u4ef6\u76d1\u63a7\u3001\u4efb\u52a1\u961f\u5217\u7684\u6267\u884c\u7b49\u3002\u6587\u7ae0\u8fd8\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u524d\u7f6e\u77e5\u8bc6\uff0c\u5982bind\u51fd\u6570\u7684\u4f7f\u7528\u3001\u5b9a\u65f6\u5668\u4efb\u52a1\u548c\u65f6\u95f4\u8f6e\u601d\u60f3\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5e94\u7528\u7b49\uff0c\u7279\u522b\u662f\u5982\u4f55\u901a\u8fc7\u65f6\u95f4\u8f6e\u7b97\u6cd5\u4f18\u5316\u5b9a\u65f6\u4efb\u52a1\u7684\u6267\u884c\u6548\u7387\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u89e3\u6790HTTP\u8bf7\u6c42\u3002\u901a","og_url":"https:\/\/www.wsisp.com\/helps\/38702.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-20T23:41:57+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520234147-682d133bf011b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38702.html","url":"https:\/\/www.wsisp.com\/helps\/38702.html","name":"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-20T23:41:57+00:00","dateModified":"2025-05-20T23:41:57+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38702.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38702.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38702.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++ - \u4effmudou\u5e93one thread one loop\u5f0f\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u5b9e\u73b0\u3011"}]},{"@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\/38702","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=38702"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38702\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38682"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38702"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}