{"id":32862,"date":"2025-04-26T01:45:22","date_gmt":"2025-04-25T17:45:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/32862.html"},"modified":"2025-04-26T01:45:22","modified_gmt":"2025-04-25T17:45:22","slug":"epoll%e5%ae%9e%e6%88%98%ef%bc%9a%e6%89%8b%e6%90%93epoll%e6%9c%ba%e5%88%b6%e5%ae%a2%e6%88%b7%e7%ab%af-%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%80%9a%e4%bf%a1%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/32862.html","title":{"rendered":"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf"},"content":{"rendered":"<h2 id=\"m6t0v\">\u6839\u636e\u524d\u6587Epoll\u539f\u7406\u53ef\u77e5&#xff0c;\u5229\u7528Epoll\u673a\u5236\u5b9e\u73b0IO\u591a\u8def\u590d\u7528\u7684\u5173\u952e\u662f\u4e09\u5927\u7ec4\u4ef6&#xff1a;<\/h2>\n<ul>\n<li>\n<ul>\n<li id=\"u1eb9ec66\">\u5229\u7528epoll_create\u521b\u5efaepoll\u5b9e\u4f8b&#xff0c;\u7ba1\u7406\u6587\u4ef6\u63cf\u8ff0\u7b26\u4ee5\u53ca\u4e8b\u4ef6&#xff1b;<\/li>\n<li id=\"udfb448bc\">\u5229\u7528epoll_ctl\u5c06\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff08;\u76d1\u542c\u63cf\u8ff0\u7b26\u548c\u6570\u636e\u4f20\u8f93\u63cf\u8ff0\u7b26&#xff09;\u4ee5\u53ca\u611f\u5174\u8da3\u4e8b\u4ef6\u6dfb\u52a0\u5230epoll\u5b9e\u4f8b\u4e2d<\/li>\n<li id=\"u8c2b2e80\">\u5229\u7528epoll_wait\u83b7\u53d6\u5404\u6587\u4ef6\u63cf\u8ff0\u7b26\u5b9e\u9645\u53d1\u751f\u7684\u4e8b\u4ef6\u5e76\u8fdb\u884c\u60f3\u7528\u7684\u8bfb\u5199\u64cd\u4f5c<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p id=\"u8882ed26\">\u672c\u7cfb\u7edf\u670d\u52a1\u7aef\u5c06\u4ee5\u4e0a\u9762\u7684\u903b\u8f91\u4f5c\u4e3a\u5de5\u4f5c\u4e3b\u7ebf&#xff0c;\u7ed3\u5408\u591a\u7ebf\u7a0b\u7f16\u7a0b\u601d\u60f3\u5b9e\u73b0\u76d1\u542c&#xff08;\u4e3b\u5faa\u73af&#xff09;\u548cIO\u64cd\u4f5c\u89e3\u8026\u64cd\u4f5c&#xff0c;\u4ee5\u9002\u5e94\u9ad8\u5e76\u53d1\u8fde\u63a5\u4e0b\u7684\u6570\u636e\u4f20\u8f93\u64cd\u4f5c\u3002<\/p>\n<hr id=\"dlkpw\" \/>\n<p id=\"u6ed674e3\">\u5f00\u59cb\u4e4b\u524d&#xff0c;\u9996\u5148\u8bb2\u89e3\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u601d\u60f3&#xff0c;\u5b8c\u6210\u670d\u52a1\u5668\u7684\u6846\u67b6\u6784\u5efa\u3002<\/p>\n<p id=\"u9a957c3d\">\u5728\u591a\u7ebf\u7a0b\u7f16\u7a0b\u4e2d&#xff0c;\u5e38\u5e38\u6d89\u53ca\u5230\u7ebf\u7a0b\u5e76\u53d1&#xff0c;\u5e38\u89c1\u7684\u4e24\u79cd\u95ee\u9898\u5982\u4e0b&#xff1a;<\/p>\n<li>\n<li id=\"u6ef0871f\">\u591a\u4e2a\u7ebf\u7a0b\u8bbf\u95ee\u540c\u4e00\u4e2a\u5171\u4eab\u8d44\u6e90&#xff0c;\u53ef\u4ee5\u91c7\u7528\u4e92\u65a5\u91cf\u8fdb\u884c\u89e3\u51b3&#xff1b;<\/li>\n<li id=\"u901241e2\">\u67d0\u4e9b\u7ebf\u7a0b\u8fd0\u884c\u540e&#xff0c;\u6709\u65f6\u9700\u8981\u7b49\u5f85\u4e00\u5b9a\u7684\u6761\u4ef6\u624d\u4f1a\u7ee7\u7eed\u6267\u884c&#xff0c;\u5982\u679c\u6761\u4ef6\u4e0d\u6ee1\u8db3\u5c31\u4f1a\u7b49\u5f85&#xff0c;\u800c\u6761\u4ef6\u7684\u8fbe\u6210&#xff0c; \u5f88\u53ef\u80fd\u53d6\u51b3\u4e8e\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u3002\u53ef\u4ee5\u91c7\u7528\u6761\u4ef6\u53d8\u91cf\u6765\u89e3\u51b3\u3002<\/li>\n<\/li>\n<p id=\"u86eaf0e5\">\u5728\u672c\u7cfb\u7edf\u4e2d&#xff0c;\u4e3b\u5faa\u73af\u8d1f\u8d23\u76d1\u542c\u8fde\u63a5\u4ee5\u53caIO\u64cd\u4f5c\u8bf7\u6c42&#xff0c;\u5de5\u4f5c\u7ebf\u7a0b\u8d1f\u8d23\u5b9e\u73b0\u5177\u4f53\u7684IO\u64cd\u4f5c&#xff0c;\u5f88\u660e\u663e&#xff0c;\u4e24\u8005\u5b58\u5728\u4f9d\u8d56\u5173\u7cfb&#xff0c;\u56e0\u6b64\u5229\u7528\u6761\u4ef6\u53d8\u91cf\u8fdb\u884c\u89e3\u51b3\u3002<\/p>\n<p id=\"u8edd5722\">\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf&#xff1f;<\/p>\n<p id=\"ud8ca8c9a\">\u56e0\u4e3a\u5982\u679c\u4e0d\u4f7f\u7528\u6761\u4ef6\u53d8\u91cf&#xff0c;\u7ebf\u7a0b\u5c31\u9700\u8981 \u8f6e\u8be2&#043;\u4f11\u7720 \u6765\u67e5\u770b\u662f\u5426\u6ee1\u8db3\u6761\u4ef6&#xff0c;\u8fd9\u6837\u4e25\u91cd\u5f71\u54cd\u6548\u7387\u3002<\/p>\n<h3 id=\"syGwc\">5.1 \u6761\u4ef6\u53d8\u91cf\u7684\u539f\u7406<\/h3>\n<p id=\"uca9646a3\">\u6761\u4ef6\u53d8\u91cf\u603b\u662f\u9700\u8981\u4e0e\u4e92\u65a5\u91cf\u7ed3\u5408\u4f7f\u7528&#xff0c;\u4e92\u65a5\u91cf\u80fd\u9650\u5236\u4e00\u4e2a\u7ebf\u7a0b\u80fd\u591f\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90&#xff0c;\u6761\u4ef6\u53d8\u91cf\u662f\u5728\u5171\u4eab\u53d8\u91cf\u72b6\u6001\u6539\u53d8\u65f6\u53d1\u51fa\u901a\u77e5\u3002<\/p>\n<p id=\"uf447dfbd\">\u5178\u578b\u7684\u6a21\u578b\u5c31\u662f\u751f\u4ea7\u8005-\u6d88\u8d39\u8005\u6a21\u578b&#xff1a;<\/p>\n<p id=\"u97564742\">\u751f\u4ea7\u8005&#xff1a;\u751f\u4ea7\u6570\u636e\u7684\u7ebf\u7a0b\u6216\u8005\u8fdb\u7a0b<\/p>\n<p id=\"uae21c182\">\u6d88\u8d39\u8005&#xff1a;\u6d88\u8d39\u6570\u636e\u7684\u7ebf\u7a0b\u6216\u8005\u8fdb\u7a0b<\/p>\n<p id=\"u681514d8\">\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u5f7c\u6b64\u4e0d\u901a\u4fe1&#xff0c;\u751f\u4ea7\u8005\u4e0d\u9700\u8981\u7b49\u5f85\u6d88\u8d39\u8005\u662f\u5426\u6d88\u8d39\u8005\u5904\u7406&#xff0c;\u751f\u4ea7\u8005\u76f4\u63a5\u5f80\u963b\u585e\u961f\u5217\u4e2d\u751f\u4ea7\u6570\u636e&#xff0c;\u6d88\u8d39\u8005\u4e0d\u627e\u751f\u4ea7\u8005\u8981\u6570\u636e&#xff0c;\u76f4\u63a5\u4ece\u963b\u585e\u961f\u5217\u4e2d\u62ff\u6570\u636e\u5e76\u5904\u7406\u6570\u636e&#xff0c;\u963b\u585e\u961f\u5217\u662f\u4e00\u4e2a\u6570\u636e\u7f13\u51b2\u533a&#xff0c;\u8fd9\u4e2a\u963b\u585e\u961f\u5217\u5c06\u6d88\u8d39\u6570\u636e\u548c\u751f\u4ea7\u6570\u636e\u8fdb\u884c\u4e86\u89e3\u8026\u3002<\/p>\n<p id=\"uc3e3ba0b\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"600\" id=\"u40dd9cf4\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425174520-680bca301ed9c.png\" width=\"1144\" \/><\/p>\n<p id=\"u2acbe0c8\">\u6761\u4ef6\u53d8\u91cf\u4e3b\u8981\u5305\u542b\u4ee5\u4e0b\u4e24\u4e2a\u51fd\u6570&#xff1a;<\/p>\n<li>\n<li id=\"u55a27536\">wait()&#xff1a;\u7528\u4e8e\u6d88\u8d39\u8005&#xff0c;\u4f1a\u4f7f\u5f53\u524d\u7ebf\u7a0b\u8fdb\u5165\u963b\u585e\u72b6\u6001&#xff0c;\u76f4\u5230\u6761\u4ef6\u53d8\u91cf\u83b7\u5f97\u4fe1\u53f7&#xff0c;\u8be5\u7ebf\u7a0b\u624d\u4f1a\u7ee7\u7eed\u8fd0\u884c\u3002<\/li>\n<\/li>\n<p id=\"uc4790673\">\u8be5\u51fd\u6570\u4f1a\u81ea\u52a8\u91ca\u653e\u4e0e\u4e4b\u5173\u8054\u7684\u4e92\u65a5\u9501&#xff0c;\u963b\u585e\u6240\u5728\u7ebf\u7a0b&#xff0c;\u5e76\u5c06\u8be5\u7ebf\u7a0b\u52a0\u5165\u5230\u7b49\u5f85\u5f53\u524d\u6761\u4ef6\u53d8\u91cf\u7684\u7ebf\u7a0b\u5217\u8868\u4e2d\u3002\u5f53\u6709\u5176\u4ed6\u7ebf\u7a0b\u8c03\u7528\u5f53\u524d\u6761\u4ef6\u53d8\u91cf\u7684 notify_one() \u6216 notify_all() \u6210\u5458\u51fd\u6570\u65f6&#xff0c;\u8be5\u7ebf\u7a0b\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u3002\u4f46\u7531\u4e8e\u5524\u9192\u4e5f\u53ef\u80fd\u662f\u865a\u5047\u5524\u9192&#xff0c;\u56e0\u6b64\u6bcf\u6b21\u7ed3\u675f\u963b\u585e\u540e\u90fd\u5e94\u7acb\u5373\u91cd\u65b0\u68c0\u67e5\u81ea\u5df1\u6240\u7b49\u5f85\u7684\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\u3002<\/p>\n<p id=\"uf189869f\">\u8be5\u51fd\u6570\u6709\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\u4f5c\u4e3a\u81ea\u5df1\u7684\u53c2\u6570\u2014\u2014\u8fd9\u4e2a\u56de\u8c03\u51fd\u6570\u7684\u4f5c\u7528&#xff0c;\u5c31\u662f\u7528\u6765\u68c0\u67e5\u672c\u6b21\u5524\u9192\u662f\u5426\u4e3a\u865a\u5047\u5524\u9192\u3002<\/p>\n<p id=\"u363dd202\">\u5f53\u7ebf\u7a0b\u89e3\u9664\u963b\u585e\u540e&#xff0c;wait() \u51fd\u6570\u4f1a\u91cd\u65b0\u5bf9\u4e92\u65a5\u91cf\u52a0\u9501&#xff0c;\u8c03\u7528\u56de\u8c03\u51fd\u6570\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\u3002\u82e5\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u5219\u8be5\u51fd\u6570\u4f1a\u4ee5\u4e00\u6b21\u539f\u5b50\u64cd\u4f5c\u91ca\u653e\u9501&#xff0c;\u7136\u540e\u963b\u585e\u5f53\u524d\u7ebf\u7a0b&#xff0c;\u5e76\u5c06\u5f53\u524d\u7ebf\u7a0b\u52a0\u5165\u5230\u7b49\u5f85\u5f53\u524d\u6761\u4ef6\u53d8\u91cf\u7684\u7ebf\u7a0b\u5217\u8868\u4e2d\u3002<\/p>\n<li>\n<li id=\"u5d406a39\">notify_one()\/notify_all()&#xff1a;\u7528\u4e8e\u751f\u4ea7\u8005&#xff0c;\u8c03\u7528\u540e\u4f1a\u901a\u77e5\u6d88\u8d39\u8005\u662f\u5426\u5524\u9192\u6267\u884c<\/li>\n<\/li>\n<p id=\"u9cd2533c\">\u82e5\u6709\u591a\u4e2a\u7ebf\u7a0b\u5728\u7b49\u5f85\u540c\u4e00\u4e2a\u6761\u4ef6\u53d8\u91cf&#xff0c;\u5219 notify_one() \u4f1a\u53ea\u5524\u9192\u8fd9\u4e9b\u963b\u585e\u7ebf\u7a0b\u4e2d\u7684\u4e00\u4e2a\u7ebf\u7a0b\u3002<\/p>\n<p id=\"u8bbf5358\">\u82e5\u6709\u591a\u4e2a\u7ebf\u7a0b\u5728\u7b49\u5f85\u540c\u4e00\u4e2a\u6761\u4ef6\u53d8\u91cf&#xff0c;\u5219 notify_all() \u4f1a\u5524\u9192\u6240\u6709\u7684\u7ebf\u7a0b\u3002<\/p>\n<ul>\n<li id=\"u57ef05d3\">\u7ebf\u7a0b 1 \u8c03\u7528\u6761\u4ef6\u53d8\u91cf\u7684 wait() \u51fd\u6570&#xff0c;\u8be5\u51fd\u6570\u5185\u90e8\u4f1a\u5bf9\u4e00\u4e2a\u4e92\u65a5\u91cf\u52a0\u9501&#xff0c;\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3&#xff1b;<\/li>\n<li id=\"u5ee3f24b\">\u82e5\u8be5\u6761\u4ef6\u6ca1\u6709\u6ee1\u8db3&#xff0c;\u5219 wait() \u51fd\u6570\u4f1a\u91ca\u653e\u9501&#xff0c;\u7136\u540e\u8be5\u51fd\u6570\u5c06\u7b49\u5f85\u6761\u4ef6\u53d8\u91cf\u5f97\u5230\u5916\u90e8\u7684\u4fe1\u53f7&#xff08;\u4ece\u5916\u90e8\u770b&#xff0c;\u6b64\u65f6\u7684\u7ebf\u7a0b\u6b63\u5728 wait() \u51fd\u6570\u8fd9\u4e00\u53e5\u8bdd\u4e2d\u963b\u585e\u7b49\u5f85&#xff09;\u3002&#xff08;\u6761\u4ef6\u53d8\u91cf\u7684 wait() \u51fd\u6570\u80fd\u591f\u4fdd\u8bc1\u76f8\u5173\u64cd\u4f5c\u7684\u539f\u5b50\u6027&#xff09;&#xff1b;<\/li>\n<li id=\"ue3ccefe3\">\u53e6\u4e00\u4e2a\u7ebf\u7a0b&#xff08;\u6bd4\u5982\u7ebf\u7a0b 2 &#xff09;\u5728\u6761\u4ef61\u6240\u9700\u7684\u6761\u4ef6\u5df2\u7ecf\u51c6\u5907\u597d\u4e86\u4e4b\u540e&#xff0c;\u5bf9&#xff08;\u7ebf\u7a0b1\u6b63\u5728\u7b49\u5f85\u7684\u90a3\u4e2a&#xff09;\u6761\u4ef6\u53d8\u91cf\u53d1\u51fa\u4fe1\u53f7&#xff1b;<\/li>\n<li id=\"ubd695aa3\">\u4e00\u65e6\u6761\u4ef6\u53d8\u91cf\u5f97\u5230\u4fe1\u53f7&#xff0c;\u7ebf\u7a0b 1 \u5c31\u4f1a\u88ab\u5524\u9192&#xff08;\u4f46\u6b64\u65f6\u4ecd\u7136\u5728 wait() \u51fd\u6570\u4e2d&#xff0c;\u53ea\u4e0d\u8fc7\u662f\u7ee7\u7eed\u6267\u884c wait() \u51fd\u6570\u4e86&#xff09;&#xff0c;\u5524\u9192\u7684\u7b2c\u4e00\u4ef6\u4e8b\u662f\u518d\u6b21\u52a0\u9501&#xff0c;\u7136\u540e\u901a\u8fc7\u7528\u6237\u5b9a\u4e49\u7684\u68c0\u67e5\u51fd\u6570\u6765\u68c0\u67e5\u6761\u4ef6\u53d8\u91cf\u76f8\u5173\u8054\u7684\u6761\u4ef6\u771f\u7684\u88ab\u6ee1\u8db3\u4e86&#xff1a;\u5982\u679c\u771f\u7684\u6ee1\u8db3\u4e86&#xff0c;\u90a3 wait() \u51fd\u6570\u5c31\u4f1a\u8fd4\u56de&#xff0c;\u7ebf\u7a0b 1 \u771f\u6b63\u5f00\u59cb\u7ee7\u7eed\u8fd0\u884c\u3002\u5982\u679c\u68c0\u67e5\u7684\u7ed3\u679c\u662f\u5e76\u6ca1\u6709\u771f\u6b63\u6ee1\u8db3&#xff0c;\u90a3\u5c31\u610f\u5473\u7740\u8fd9\u6b21\u8fd0\u884c\u53ea\u662f\u4e00\u6b21\u865a\u5047\u5524\u9192&#xff08;spurious wakeup&#xff09;&#xff1b; \u5982\u679c\u6709\u591a\u4e2a\u7ebf\u7a0b\u6b63\u5728\u7b49\u5f85\u4fe1\u53f7&#xff0c;\u53ef\u4ee5\u4f7f\u7528 notify_one \u6765\u53ea\u6fc0\u6d3b\u5176\u4e2d\u4e00\u4e2a\u7b49\u5f85\u7684\u7ebf\u7a0b\u3002<\/li>\n<li id=\"u2cb3b162\">\u82e5\u6b64\u6b21\u8fd0\u884c\u662f\u4e00\u6b21\u865a\u5047\u5524\u9192&#xff0c;\u8be5\u51fd\u6570\u5c31\u4f1a\u91cd\u65b0\u8c03\u7528 wait() \u51fd\u6570&#xff0c;\u7ee7\u7eed\u7b49\u5f85\u771f\u6b63\u7684\u4fe1\u53f7\u6765\u4e34\u3002<\/li>\n<\/ul>\n<h3 id=\"slNz4\">5.2 \u672c\u7cfb\u7edf\u8bbe\u8ba1\u4e0e\u5b9e\u73b0<\/h3>\n<p id=\"uc0874488\">\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1200\" id=\"u088c3fae\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425174520-680bca307537e.png\" width=\"1200\" \/><\/p>\n<p id=\"ucab45399\">\u672c\u7cfb\u7edf\u670d\u52a1\u7aef\u8bbe\u8ba1\u6846\u67b6\u5982\u4e0a\u4e3b\u8981\u5305\u542b\u4e09\u5927\u90e8\u4ef6&#xff1a;<\/p>\n<li>\n<li id=\"udbb97445\">Tcpserver\u7c7b&#xff1a;\u5b9e\u73b0\u670d\u52a1\u5668\u5957\u63a5\u5b57\u521d\u59cb\u5316\u3001\u76d1\u542c\u8fde\u63a5\u4e0eIO\u64cd\u4f5c&#xff0c;\u5206\u53d1\u4e8b\u4ef6\u7ed9\u5de5\u4f5c\u7ebf\u7a0b<\/li>\n<li id=\"u46c4fde7\">\u4e8b\u4ef6\u5904\u7406\u5668\u63a5\u53e3EventHandler\u7c7b&#xff1a;\u5b9a\u4e49IO\u64cd\u4f5c<\/li>\n<li id=\"u3c224ee3\">\u8fde\u63a5\u5904\u7406\u5668ConnectionHandler&#xff1a;\u591a\u6001\u5b9e\u73b0\u5177\u4f53IO\u64cd\u4f5c<\/li>\n<\/li>\n<p id=\"u16320d96\">\u672c\u7cfb\u7edf\u7684\u6a21\u5f0f\u67b6\u6784\u5206\u4e3a\u4e24\u5927\u6a21\u5757&#xff08;Reactor\u6a21\u5f0f&#xff09;&#xff1a;<\/p>\n<li>\n<li id=\"u1613e5d4\">\u4e3b\u5faa\u73af\u5b9e\u73b0\u5faa\u73af\u76d1\u542c\u8fde\u63a5\u4e0e\u76d1\u542cIO\u64cd\u4f5c&#xff0c;\u5e76\u4e8b\u4ef6\u653e\u5165handler\u6570\u7ec4&#xff0c;\u540e\u7eed\u5206\u53d1\u7ed9\u5de5\u4f5c\u7ebf\u7a0b<\/li>\n<li id=\"u53852486\">\u5b50\u5faa\u73af&#xff08;\u5de5\u4f5c\u7ebf\u7a0b&#xff09;\u6267\u884c\u5177\u4f53\u64cd\u4f5c<\/li>\n<li id=\"uef2e280c\">\u5de5\u4f5c\u7ebf\u7a0b\u7684\u8c03\u7528\u91c7\u7528\u6761\u4ef6\u53d8\u91cf\u7684\u591a\u7ebf\u7a0b\u6a21\u578b<\/li>\n<\/li>\n<p id=\"u488ecd2f\">\u4ee3\u7801\u7684\u903b\u8f91\u601d\u8def\u662f&#xff1a;<\/p>\n<li>\n<li id=\"u26040638\">\u521d\u59cb\u5316\u670d\u52a1\u5668\u5957\u63a5\u5b57&#xff0c;\u521d\u59cb\u5316epoll\u5b9e\u4f8b&#xff08;epoll_create&#xff09;&#xff0c;\u5c06\u670d\u52a1\u5668\u5957\u63a5\u5b57\u6dfb\u52a0\u5230epoll\u5b9e\u4f8b\u4e2d&#xff08;epoll_ctl&#xff09;<\/li>\n<li id=\"u3d371e4e\">\u5faa\u73af\u76d1\u542c\u4e8b\u4ef6&#xff1a;&#xff08;epoll_wait&#xff09;<\/li>\n<\/li>\n<li>\n<li>\n<li id=\"ud548fdd4\">\u76d1\u542c\u591a\u5ba2\u6237\u7aef\u8fde\u63a5&#xff0c;\u5728hash\u4e2d\u4fdd\u5b58\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u4e8b\u4ef6<\/li>\n<li id=\"ue315d0b5\">\u76d1\u542cIO\u64cd\u4f5c\u4e8b\u4ef6&#xff0c;\u628a\u4e8b\u4ef6\u653e\u5165handler\u6570\u7ec4\u4e2d\u7528\u4e8e\u5206\u53d1<\/li>\n<\/li>\n<\/li>\n<li>\n<li id=\"u91cafe09\">\u5206\u53d1\u4e8b\u4ef6\u7ed9\u5de5\u4f5c\u7ebf\u7a0b&#xff1a;<\/li>\n<\/li>\n<li>\n<li>\n<li id=\"u611a0294\">\u5148\u628ahandler\u6570\u7ec4\u4e2d\u7684\u4e8b\u4ef6\u961f\u5217<\/li>\n<li id=\"u7581273a\">\u5206\u53d1\u4e8b\u4ef6&#xff08;\u751f\u4ea7\u8005&#xff09;\u548c\u5de5\u4f5c\u7ebf\u7a0b&#xff08;\u6d88\u8d39\u8005&#xff09;\u52a0\u4e92\u65a5\u9501<\/li>\n<li id=\"ua2f2d9ee\">\u751f\u4ea7\u8005\u901a\u77e5&#xff0c;\u6d88\u8d39\u8005\u6267\u884c\u5177\u4f53\u64cd\u4f5c<\/li>\n<\/li>\n<\/li>\n<p id=\"uec392246\">\u5ba2\u6237\u7aef\u4ee3\u7801\u903b\u8f91\u6bd4\u8f83\u7b80\u5355&#xff0c;\u5c31\u4e0d\u518d\u8d58\u8ff0&#xff0c;\u4e0b\u9644\u6e90\u7801&#xff1a;<\/p>\n<p id=\"uf811a81f\">main.cpp<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;thread&gt;<br \/>\n#include &#034;TcpserverEpoll.h&#034;<br \/>\n#include &#034;Tcpclient.h&#034;<\/p>\n<p>void run_server() {<br \/>\n    \/\/ \u521b\u5efa\u4e00\u4e2a\u76d1\u542cIP\u5730\u5740\u4e3a127.0.0.1&#xff0c;\u7aef\u53e3\u4e3a8080&#xff0c;\u7ebf\u7a0b\u6570\u4e3a4\u7684\u670d\u52a1\u5668<br \/>\n    Tcpserver server(&#034;127.0.0.1&#034;, 8080, 4);<br \/>\n    \/\/ \u542f\u52a8\u670d\u52a1\u5668<br \/>\n    server.start();<br \/>\n}<\/p>\n<p>void run_client() {<br \/>\n    \/\/ \u521b\u5efa\u5ba2\u6237\u7aef&#xff0c;\u8fde\u63a5\u5230127.0.0.1:8080<br \/>\n    Tcpclient client(&#034;127.0.0.1&#034;, 8080);<\/p>\n<p>    if (client.connection()) {<br \/>\n        std::cout &lt;&lt; &#034;Connected to server&#034; &lt;&lt; std::endl;<\/p>\n<p>        \/\/ \u53d1\u9001\u6570\u636e<br \/>\n        std::string message &#061; &#034;Hello, Server!&#034;;<br \/>\n        client.clisend(message);<\/p>\n<p>        \/\/ \u63a5\u6536\u6570\u636e<br \/>\n        std::string response;<br \/>\n        client.clirecv(response);<br \/>\n        std::cout &lt;&lt; &#034;Received from server: &#034; &lt;&lt; response &lt;&lt; std::endl;<br \/>\n    } else {<br \/>\n        std::cout &lt;&lt; &#034;Failed to connect to server&#034; &lt;&lt; std::endl;<br \/>\n    }<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    \/\/ \u542f\u52a8\u670d\u52a1\u5668\u7ebf\u7a0b<br \/>\n    std::thread server_thread(run_server);<\/p>\n<p>    \/\/ \u7b49\u5f85\u670d\u52a1\u5668\u542f\u52a8<br \/>\n    std::this_thread::sleep_for(std::chrono::seconds(1));<\/p>\n<p>    \/\/ \u542f\u52a8\u5ba2\u6237\u7aef\u7ebf\u7a0b<br \/>\n    std::thread client_thread(run_client);<\/p>\n<p>    \/\/ \u7b49\u5f85\u7ebf\u7a0b\u5b8c\u6210<br \/>\n    server_thread.join();<br \/>\n    client_thread.join();<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p id=\"u59f7308f\">TcpserverEpoll.h<\/p>\n<p>\/*<br \/>\n\u5229\u7528epoll\u673a\u5236\u4ee3\u66ffpoll\u673a\u5236&#xff0c;\u65e0\u9700poll\u673a\u5236\u4e0b\u6bcf\u6b21\u8c03\u7528\u65f6\u590d\u5236\u6574\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408&#xff0c;\u53ea\u9700\u8981\u5173\u6ce8\u5b9e\u9645\u53d1\u751f\u7684\u4e8b\u4ef6<\/p>\n<p>\u91c7\u7528reactor\u6a21\u5f0f&#xff1a;\u5c06\u4e3b\u5faa\u73af\u548c\u4e8b\u4ef6\u5904\u7406\u903b\u8f91\u5206\u79bb\u5f00&#xff0c;\u4e3b\u5faa\u73af\u8d1f\u8d23\u7b49\u5f85\u5c31\u7eea\u4e8b\u4ef6\u5206\u53d1\u7ed9\u5de5\u4f5c\u7ebf\u7a0b&#xff0c;\u5de5\u4f5c\u7ebf\u7a0b\u5229\u7528\u7ebf\u7a0b\u6c60\u5e76\u884c\u5904\u7406\u5b9e\u9645\u53d1\u751f\u7684\u4e8b\u4ef6<br \/>\n\u670d\u52a1\u5668\u7c7b&#xff1a;<br \/>\n1\u3001\u5957\u63a5\u5b57\u521d\u59cb\u5316\u548c\u8fde\u63a5<br \/>\n2\u3001\u6570\u636e\u8bfb\u5199<\/p>\n<p>\u5b9a\u4e49\u4ee5\u4e0b\u7ed3\u6784&#xff1a;<br \/>\n1\u3001Tcpserver\u7c7b&#xff1a;\u5957\u63a5\u5b57\u521d\u59cb\u5316\u3001\u8fde\u63a5\u3001\u4e8b\u4ef6\u5206\u53d1<br \/>\n2\u3001\u4e8b\u4ef6\u5904\u7406\u63a5\u53e3<br \/>\n2\u3001\u8fde\u63a5\u4e8b\u4ef6\u5904\u7406\u5668<\/p>\n<p>*\/<\/p>\n<p>#pragma once<br \/>\n#include&lt;iostream&gt;<br \/>\nusing namespace std;<br \/>\n#include &lt;sys\/epoll.h&gt;<br \/>\n#include&lt;vector&gt;<br \/>\n#include&lt;functional&gt;<br \/>\n#include &lt;condition_variable&gt;<br \/>\n#include&lt;queue&gt;<\/p>\n<p>\/\/Reactor\u6a21\u5f0f\u4e2d\u7684\u4e8b\u4ef6\u5904\u7406\u5668\u63a5\u53e3<br \/>\nclass EventHandler{<br \/>\npublic:<br \/>\n    virtual ~EventHandler() {}<br \/>\n    virtual void handleInput(int sockfd) &#061; 0;<br \/>\n    virtual void handleOutput(int sockfd) &#061; 0;<br \/>\n    virtual int getsocket() &#061; 0;<br \/>\n};<\/p>\n<p>\/\/Tcpserver\u4e3b\u7c7b<br \/>\nclass Tcpserver{<br \/>\npublic:<br \/>\n    \/\/\u6784\u9020\u51fd\u6570&#xff0c;\u521d\u59cb\u5316\u7ebf\u7a0b\u6570\u3001\u670d\u52a1\u5668ip\u548c\u7aef\u53e3\u53f7<br \/>\n    Tcpserver(string ip,int port,int numThreads);<\/p>\n<p>    \/\/\u521d\u59cb\u5316\u5957\u63a5\u5b57\u5e76\u7ed1\u5b9a\u5730\u5740&#xff0c;\u76d1\u542c\u8fde\u63a5\u8bf7\u6c42<br \/>\n    void init_server_socket();<\/p>\n<p>    \/\/\u63a5\u6536\u8fde\u63a5<br \/>\n    void accept_connection();<\/p>\n<p>    \/\/\u5177\u4f53\u5b9e\u73b0\u521d\u59cb\u5316\u5957\u63a5\u5b57\u548cepoll\u5b9e\u4f8b&#xff0c;\u7ed1\u5b9a\u5730\u5740&#xff0c;\u76d1\u542c\u94fe\u63a5\u8bf7\u6c42&#xff0c;\u63a5\u6536\u94fe\u63a5&#xff0c;\u8bfb\u5199\u6570\u636e<br \/>\n    void start();<\/p>\n<p>    \/\/\u5de5\u4f5c\u7ebf\u7a0b<br \/>\n    void work_thread();<\/p>\n<p>    \/\/\u5206\u53d1\u4e8b\u4ef6\u7ed9\u5de5\u4f5c\u7ebf\u7a0b,\u8d1f\u8d23\u628a\u5c31\u7eea\u4e8b\u4ef6\u7684\u7ebf\u7a0b\u6570\u7ec4\u5206\u53d1\u7ed9\u5de5\u4f5c\u7ebf\u7a0b&#xff0c;\u5b9e\u73b0\u591a\u7ebf\u7a0b\u5904\u7406<br \/>\n    void distribute_events(vector&lt;EventHandler*&gt;&amp;&amp; handlers);<\/p>\n<p>    \/\/ \/\/\u53d1\u9001\u6570\u636e<br \/>\n    \/\/ void sersend(int socket,string&amp; data);<\/p>\n<p>    \/\/ \/\/\u63a5\u6536\u6570\u636e<br \/>\n    \/\/ ssize_t serrecv(int socket,string&amp; show_inbuff);<\/p>\n<p>private:<br \/>\n    string s_ip;<br \/>\n    int s_port;<br \/>\n    int listensock;<br \/>\n    \/\/\u7ebf\u7a0b\u6570\u91cf<br \/>\n    int m_numThreads;<br \/>\n    \/\/epoll\u5b9e\u4f8b<br \/>\n    int epfd;<br \/>\n    \/\/\u7ed3\u6784\u4f53\u6570\u7ec4evlist&#xff0c;\u7528\u4e8e\u4fdd\u5b58\u5b9e\u9645\u53d1\u751f\u7684\u4e8b\u4ef6\u4fe1\u606f<br \/>\n    vector&lt;struct epoll_event&gt; events;<\/p>\n<p>    \/\/\u591a\u7ebf\u7a0b\u54c8\u5e0c\u8868,\u7528\u4e8e\u4fdd\u5b58\u591a\u4e2a\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7684\u8fde\u63a5\u4e0eIO\u64cd\u4f5c\u4fe1\u606f<br \/>\n    \/\/\u667a\u80fd\u6307\u9488&#xff1a;unique_ptr\u6765\u7ba1\u7406EventHandler\u5b9e\u4f8b&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u9732\u3002\u3010\u667a\u80fd\u6307\u9488\u7684\u7528\u6cd5\u4e0e\u539f\u7406\u8fd8\u9700\u8981\u590d\u4e60&#xff01;&#xff01;&#xff01;\u3011<br \/>\n    \/\/\u7528\u4e8e\u5c06\u6bcf\u4e2a\u5ba2\u6237\u7aef\u7684\u5957\u63a5\u5b57&#xff08;datasock&#xff09;\u6620\u5c04\u5230\u4e00\u4e2a std::unique_ptr&#xff0c;\u8be5\u6307\u9488\u6307\u5411\u4e00\u4e2a EventHandler \u5bf9\u8c61,<br \/>\n    \/\/\u7528\u7236\u7c7b\u8fdb\u884c\u5b9a\u4e49&#xff0c;\u53ef\u4ee5\u4f7f\u5f97\u5728hash\u8868\u4e2d\u4fdd\u5b58\u4e0d\u540c\u7c7b\u578b\u7684\u5b50\u7c7b\u5bf9\u8c61&#xff0c;\u5b9e\u73b0\u591a\u6001<br \/>\n    unordered_map&lt;int,unique_ptr&lt;EventHandler&gt;&gt;m_handlers;<\/p>\n<p>    \/\/\u591a\u7ebf\u7a0b\u4e0e\u4e92\u65a5\u9501\u76f8\u5173\u53d8\u91cf<br \/>\n    \/\/\u4e8b\u4ef6\u961f\u5217&#xff0c;\u7528\u4e8e\u540e\u7eed\u5206\u53d1\u7ed9\u5de5\u4f5c\u7ebf\u7a0b<br \/>\n    queue&lt;EventHandler*&gt; m_eventQueue;<br \/>\n    \/\/\u5b9a\u4e49\u4e8b\u4ef6\u4e92\u65a5\u9501&#xff0c;\u7528\u4e8e\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90&#xff0c;\u9632\u6b62\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u8be5\u8d44\u6e90\u5bfc\u81f4\u7684\u6570\u636e\u7ade\u4e89\u548c\u4e0d\u4e00\u81f4\u6027<br \/>\n    \/\/\u8fc7\u4e92\u65a5\u9501&#xff0c;\u786e\u4fdd\u5728\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90<br \/>\n    mutex m_eventQueueMutex;<br \/>\n    \/\/\u6761\u4ef6\u53d8\u91cf\u7528\u4e8e\u7ebf\u7a0b\u95f4\u7684\u901a\u4fe1&#xff0c;\u5141\u8bb8\u4e00\u4e2a\u7ebf\u7a0b\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u53d1\u51fa\u7684\u4fe1\u53f7\u3002<br \/>\n    condition_variable m_eventQueueCond;<\/p>\n<p>};<\/p>\n<p>\/\/\u8fde\u63a5\u5904\u7406\u5668&#xff1a;\u8fde\u63a5\u3001\u6570\u636e\u8bfb\u5199<br \/>\nclass ConnectionHandler:public EventHandler{<br \/>\npublic:<\/p>\n<p>    \/\/\u8fde\u63a5\u5668\u521d\u59cb\u5316,\u7528\u4e8e\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u8fde\u63a5\u7684\u5957\u63a5\u5b57\u4f20\u9012<br \/>\n    ConnectionHandler(int socket):m_sockfd(socket){};<\/p>\n<p>    \/\/\u670d\u52a1\u5668\u8bfb\u53d6\u6570\u636e\u5e76\u5904\u7406<br \/>\n    void handleInput(int sockfd);<\/p>\n<p>    \/\/\u670d\u52a1\u5668\u8f93\u51fa\u6570\u636e\u5e76\u5904\u7406<br \/>\n    void handleOutput(int sockfd);<\/p>\n<p>    \/\/\u83b7\u53d6\u670d\u52a1\u5668\u5957\u63a5\u5b57<br \/>\n    int getsocket();<br \/>\nprivate:<\/p>\n<p>    int m_sockfd;<\/p>\n<p>}; <\/p>\n<p>TcpserverEpoll.cpp<\/p>\n<p>#include&lt;iostream&gt;<br \/>\nusing namespace std;<br \/>\n#include &#034;TcpserverEpoll.h&#034;<br \/>\n#include&lt;sys\/socket.h&gt;<br \/>\n#include &lt;arpa\/inet.h&gt;<br \/>\n#include &lt;cstring&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;sys\/epoll.h&gt;<br \/>\n#include &lt;thread&gt;<\/p>\n<p>Tcpserver::Tcpserver(string ip,int port,int numThreads):s_ip(ip),s_port(port),m_numThreads(numThreads),events(1024){};<\/p>\n<p>void Tcpserver::init_server_socket(){<br \/>\n    \/\/\u521d\u59cb\u5316\u670d\u52a1\u5668\u5957\u63a5\u5b57&#xff1a;IPV4,TCP\u5b57\u8282\u6d41&#xff0c;\u9ed8\u8ba4\u534f\u8bae<br \/>\n    listensock&#061;socket(AF_INET,SOCK_STREAM,0);<br \/>\n    if (listensock &lt; 0) {<br \/>\n        perror(&#034;socket error&#034;);<br \/>\n        exit(EXIT_FAILURE);<br \/>\n    }<\/p>\n<p>    \/\/\u7ed1\u5b9a\u5730\u5740<br \/>\n    struct  sockaddr_in servaddr;<br \/>\n    memset(&amp;servaddr,0,sizeof(servaddr));<br \/>\n    servaddr.sin_family&#061;AF_INET;<br \/>\n    \/\/\u6b64ip\u548cport\u662f\u7528\u6237\u6307\u5b9a\u7684<br \/>\n    servaddr.sin_addr.s_addr&#061;inet_addr(s_ip.c_str());<br \/>\n    servaddr.sin_port&#061;htons(s_port);<\/p>\n<p>    if (bind(listensock, (struct sockaddr*)&amp;servaddr, sizeof(servaddr)) &lt; 0) {<br \/>\n        perror(&#034;bind error&#034;);<br \/>\n        close(listensock);<br \/>\n        exit(EXIT_FAILURE);<br \/>\n    }<br \/>\n    \/\/\u76d1\u542c\u94fe\u63a5\u8bf7\u6c42,\u540e\u9762\u7684\u6570\u5b57\u662f\u76d1\u542c\u7684\u7ebf\u7a0b\u6570<br \/>\n    if (listen(listensock, m_numThreads) &lt; 0) {<br \/>\n        perror(&#034;listen error&#034;);<br \/>\n        close(listensock);<br \/>\n        exit(EXIT_FAILURE);<br \/>\n    }<\/p>\n<p>    cout&lt;&lt;&#034;server listensock&#061; &#034;&lt;&lt;listensock&lt;&lt;endl;<\/p>\n<p>}<\/p>\n<p>\/\/\u5229\u7528epoll_ctl\u65b9\u6cd5\u5c06\u6570\u636e\u4f20\u8f93\u5957\u63a5\u5b57\u6dfb\u52a0\u5230epoll\u5b9e\u4f8b\u4e2d<br \/>\nvoid Tcpserver::accept_connection(){<\/p>\n<p>    struct sockaddr_in cliaddr;<br \/>\n    socklen_t cliaddelen&#061;sizeof(cliaddr);\\\\<br \/>\n    \/\/\u521b\u5efa\u5ba2\u6237\u7aef\u670d\u52a1\u5668\u6570\u636e\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u4e3a\u540e\u7eed\u6570\u636e\u4f20\u8f93\u505a\u51c6\u5907<br \/>\n    int datasock&#061;accept(listensock,(struct sockaddr*)&amp;cliaddr,&amp;cliaddelen);<\/p>\n<p>    cout&lt;&lt;&#034;client datasock&#061; &#034;&lt;&lt;datasock&lt;&lt;endl;<\/p>\n<p>    \/\/\u5229\u7528\u591a\u7ebf\u7a0b\u7ba1\u7406\u591a\u4e2a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u8fde\u63a5&#xff0c;\u91c7\u7528hash\u8868\u7ed3\u6784&#xff08;key&#xff1a;datasock,value:ConnectionHandler&#xff09;<br \/>\n    \/\/\u4f7f\u7528 std::make_unique \u521b\u5efa\u4e00\u4e2a ConnectionHandler \u5bf9\u8c61\u7684 std::unique_ptr&#xff0c;\u5e76\u5c06\u5176\u5b58\u50a8\u5728\u54c8\u5e0c\u8868\u4e2d\u3002<br \/>\n    \/\/\u8fd9\u6837&#xff0c;\u54c8\u5e0c\u8868\u4e2d\u7684\u6bcf\u4e2a\u6761\u76ee\u90fd\u7ba1\u7406\u4e00\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5\u3002<br \/>\n    m_handlers[datasock]&#061;make_unique&lt;ConnectionHandler&gt;(datasock);<\/p>\n<p>    \/\/\u6784\u5efa\u6570\u636e\u53ef\u8bfbevent&#xff0c;\u5c06\u6570\u636e\u8fde\u63a5\u5957\u63a5\u5b57\u6dfb\u52a0\u5230epoll\u5b9e\u4f8b\u4e2d\u3002\u540c\u65f6\u8bbe\u7f6e\u89e6\u53d1\u6a21\u5f0f\u4e3a\u8fb9\u7f18\u89e6\u53d1<br \/>\n    struct epoll_event event;<br \/>\n    event.data.fd&#061;datasock;<br \/>\n    event.events&#061;EPOLLIN|EPOLLET;<\/p>\n<p>    epoll_ctl(epfd,EPOLL_CTL_ADD,datasock,&amp;event);<br \/>\n}<\/p>\n<p>\/\/\u76f8\u5f53\u4e8e\u751f\u4ea7\u8005&#xff1a;\u9501\u5b9a\u4e92\u65a5\u9501&#xff0c;\u8bbe\u7f6e\u6761\u4ef6&#xff0c;\u901a\u77e5\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\nvoid Tcpserver::distribute_events(vector&lt;EventHandler*&gt;&amp;&amp; handlers){<br \/>\n    \/\/\u5b9a\u4e49\u4e00\u4e2a\u4f5c\u7528\u57df\u5757&#xff0c;\u63a7\u5236\u9501\u7684\u751f\u547d\u5468\u671f<br \/>\n    {<br \/>\n        \/\/\u628a\u5c31\u7eea\u4e8b\u4ef6\u7ebf\u7a0b\u653e\u5165\u4e8b\u4ef6\u961f\u5217&#xff0c;\u5de5\u4f5c\u7ebf\u7a0b\u5173\u6ce8\u4e8b\u4ef6\u961f\u5217<br \/>\n        unique_lock&lt;mutex&gt; lock(m_eventQueueMutex);\/\/\u9501\u5b9a\u4e92\u65a5\u9501<br \/>\n        for (auto handler : handlers) {<br \/>\n            m_eventQueue.push(handler);\/\/\u8bbe\u7f6e\u6761\u4ef6<br \/>\n        }<br \/>\n    }<br \/>\n    \/\/\u6761\u4ef6\u53d8\u91cf\u901a\u77e5\u7b49\u5f85\u7684\u7ebf\u7a0b<br \/>\n    m_eventQueueCond.notify_all();<br \/>\n}<\/p>\n<p>\/\/\u76f8\u5f53\u4e8e\u6d88\u8d39\u8005&#xff1a;\u9501\u5b9a\u4e92\u65a5\u9501&#xff0c;\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3&#xff0c;\u6267\u884c\u64cd\u4f5c<br \/>\nvoid Tcpserver::work_thread(){<br \/>\n    \/\/\u5de5\u4f5c\u7ebf\u7a0b\u5faa\u73af\u7b49\u5f85\u4e8b\u4ef6\u961f\u5217\u7684\u901a\u77e5<br \/>\n    while(true){<br \/>\n        EventHandler* handler &#061; nullptr;<br \/>\n        \/\/\u5b9a\u4e49\u4e00\u4e2a\u4f5c\u7528\u57df\u5757&#xff0c;\u63a7\u5236\u9501\u7684\u751f\u547d\u5468\u671f<br \/>\n        {<br \/>\n            \/*<br \/>\n            \u8fd9\u662f\u4e00\u4e2a\u6761\u4ef6\u53d8\u91cf\u7b49\u5f85\u64cd\u4f5c\u3002\u7ebf\u7a0b\u4f1a\u5728 m_eventQueueCond \u4e0a\u7b49\u5f85&#xff0c;\u76f4\u5230\u961f\u5217 m_eventQueue \u975e\u7a7a\u3002<br \/>\n            Lambda \u8868\u8fbe\u5f0f [this] { return !m_eventQueue.empty(); } \u7528\u4e8e\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\u3002[this] \u8868\u793a\u6355\u83b7\u5f53\u524d\u5bf9\u8c61\u7684 this \u6307\u9488\u3002<br \/>\n            *\/<br \/>\n            unique_lock&lt;mutex&gt; lock(m_eventQueueMutex);\/\/\u9501\u5b9a\u4e92\u65a5\u9501&#xff0c;\u4e92\u65a5\u9501\u5728\u79bb\u5f00\u4f5c\u7528\u57df\u540e\u81ea\u52a8\u91ca\u653e<br \/>\n            m_eventQueueCond.wait(lock, [this] { return !m_eventQueue.empty(); });\/\/\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u6ee1\u8db3<br \/>\n            \/\/\u6267\u884c\u64cd\u4f5c<br \/>\n            handler &#061; m_eventQueue.front();<br \/>\n            m_eventQueue.pop();<br \/>\n        }<br \/>\n        \/\/\u4ece\u5c31\u7eea\u4e8b\u4ef6\u961f\u5217\u4e2d\u63d0\u53d6\u5b50\u7ebf\u7a0b&#xff0c;\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c&#xff08;\u8bfb\u5199\u6570\u636e&#xff09;<br \/>\n        if (handler) {<br \/>\n            handler-&gt;handleInput(handler-&gt;getsocket());<br \/>\n            handler-&gt;handleOutput(handler-&gt;getsocket());<br \/>\n        }<\/p>\n<p>    }<br \/>\n}<\/p>\n<p>void Tcpserver::start(){<\/p>\n<p>    \/\/\u521d\u59cb\u5316\u670d\u52a1\u5668\u5957\u63a5\u5b57<br \/>\n    init_server_socket();<\/p>\n<p>    \/\/\u521b\u5efaepoll\u5b9e\u4f8b<\/p>\n<p>    epfd&#061;epoll_create1(0);<br \/>\n    if (epfd &lt; 0) {<br \/>\n        perror(&#034;epoll_create error&#034;);<br \/>\n        close(listensock);<br \/>\n        exit(EXIT_FAILURE);<br \/>\n    }<\/p>\n<p>    \/\/\u5c06\u76d1\u542c\u5957\u63a5\u5b57\u6dfb\u52a0\u5230epoll\u5b9e\u4f8b\u4e2d<br \/>\n    struct epoll_event event;<br \/>\n    event.data.fd&#061;listensock;<br \/>\n    event.events&#061;EPOLLIN;<br \/>\n    if (epoll_ctl(epfd, EPOLL_CTL_ADD, listensock, &amp;event) &lt; 0) {<br \/>\n        perror(&#034;epoll_ctl error&#034;);<br \/>\n        close(listensock);<br \/>\n        close(epfd);<br \/>\n        exit(EXIT_FAILURE);<br \/>\n    }<\/p>\n<p>    \/\/\u542f\u52a8\u5de5\u4f5c\u7ebf\u7a0b<br \/>\n    vector&lt;thread&gt; threads;<br \/>\n    for (int i &#061; 0; i &lt; m_numThreads; &#043;&#043;i) {<br \/>\n        threads.emplace_back(&amp;Tcpserver::work_thread, this);<br \/>\n    }<\/p>\n<p>    \/\/\u4e8b\u4ef6\u5faa\u73af&#xff1a;\u5efa\u7acb\u8fde\u63a5&#xff0c;\u5206\u53d1\u5c31\u7eea\u4e8b\u4ef6\u7ed9\u5de5\u4f5c\u7ebf\u7a0b<br \/>\n    while(true){<br \/>\n        \/\/\u5229\u7528epoll_wait()\u7b49\u5f85\u8fd4\u56de\u5df2\u53d1\u751f\u7684\u4e8b\u4ef6[\u4eceevlist\u91cc\u9762\u83b7\u53d6\u5df2\u53d1\u751f\u7684\u4e8b\u4ef6]<br \/>\n        int nfds &#061; epoll_wait(epfd, events.data(), events.size(), -1);<br \/>\n        if (nfds &lt; 0) {<br \/>\n            perror(&#034;epoll_wait error&#034;);<br \/>\n            break;<br \/>\n        }<br \/>\n        \/\/\u5efa\u7acb\u5c31\u7eea\u4e8b\u4ef6\u7ebf\u7a0b\u6570\u7ec4<br \/>\n        vector&lt;EventHandler*&gt; handlers;<br \/>\n        \/\/\u904d\u5386\u5c31\u7eea\u4e8b\u4ef6&#xff0c;\u628a\u8bfb\u5199\u4e8b\u4ef6\u653e\u5165\u7ebf\u7a0b\u6570\u7ec4<br \/>\n        \/\/\u3010\u6ce8\u610f&#xff1a;\u4e3b\u5faa\u73af\u8d1f\u8d23\u76d1\u542c\u4e8b\u4ef6\u7c7b\u578b\u548c\u628a\u4e8b\u4ef6\u653e\u5230\u7ebf\u7a0b\u6570\u7ec4&#xff0c;\u4e4b\u540e\u5e76\u628a\u7ebf\u7a0b\u6570\u7ec4\u5206\u53d1\u5230\u7ebf\u7a0b\u961f\u5217&#xff1b;\u5728\u5de5\u4f5c\u7ebf\u7a0b\u5173\u6ce8\u7684\u662f\u7ebf\u7a0b\u961f\u5217\u6267\u884c\u5b50\u7ebf\u7a0b\u7684\u4efb\u52a1\u3011<br \/>\n        for(int i&#061;0;i&lt;nfds;i&#043;&#043;){<br \/>\n            \/\/\u76d1\u542c\u5df2\u53d1\u751f\u4e8b\u4ef6\u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\n            int sockfd&#061;events[i].data.fd;<br \/>\n            \/\/\u5982\u679c\u662f\u76d1\u542c\u63cf\u8ff0\u7b26&#xff0c;\u8bf4\u660e\u8981\u5efa\u7acb\u8fde\u63a5<br \/>\n            if(sockfd&#061;&#061;listensock){<br \/>\n                accept_connection();<br \/>\n            }<br \/>\n            \/\/\u8bf4\u660e\u8981\u8fdb\u884c\u6570\u636e\u4f20\u8f93,\u9700\u8981\u76d1\u542c\u5177\u4f53\u662f\u8bfb\u8fd8\u662f\u5199<br \/>\n            else{<br \/>\n                \/\/\u670d\u52a1\u5668\u63a5\u6536&#xff0c;\u6839\u636e\u54c8\u5e0c\u6620\u5c04\u5f97\u5230\u7ebf\u7a0b<br \/>\n                if(events[i].events&amp;EPOLLIN){<br \/>\n                    cout&lt;&lt;&#034;clitoserv &#034;&lt;&lt;endl;<br \/>\n                    handlers.push_back(m_handlers[sockfd].get());<br \/>\n                }<br \/>\n                \/\/\u670d\u52a1\u5668\u53d1\u9001<br \/>\n                if(events[i].events&amp;EPOLLOUT){<br \/>\n                    handlers.push_back(m_handlers[sockfd].get());<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/ \u5206\u53d1\u4e8b\u4ef6\u7ed9\u5de5\u4f5c\u7ebf\u7a0b<br \/>\n        distribute_events(std::move(handlers));<br \/>\n    }<br \/>\n    \/\/ \u7b49\u5f85\u5de5\u4f5c\u7ebf\u7a0b\u9000\u51fa<br \/>\n    for (auto&amp; thread : threads) {<br \/>\n        thread.join();<br \/>\n    }<\/p>\n<p>}<\/p>\n<p>\/\/ ssize_t Tcpserver::serrecv(int socket,string&amp; show_inbuff){<br \/>\n\/\/     \/\/\u5b9a\u4e49\u5199\u5165\u7684\u7f13\u51b2\u533a<br \/>\n\/\/     char buff[1024];<br \/>\n\/\/     ssize_t nbytes&#061;recv(socket,buff,sizeof(buff),0);<br \/>\n\/\/     \/\/\u8bf4\u660e\u6ca1\u6709\u6570\u636e\u5199\u5165<br \/>\n\/\/     if (nbytes &lt;&#061; 0) {<br \/>\n\/\/         if (nbytes &#061;&#061; 0) {<br \/>\n\/\/             cout &lt;&lt; &#034;Client disconnected&#034; &lt;&lt; endl;<br \/>\n\/\/         } else {<br \/>\n\/\/             perror(&#034;recv error&#034;);<br \/>\n\/\/         }<br \/>\n\/\/     }<br \/>\n\/\/     else{<br \/>\n\/\/         show_inbuff.append(buff,nbytes);<br \/>\n\/\/     }<br \/>\n\/\/     return nbytes;<br \/>\n\/\/ }<\/p>\n<p>\/\/ void Tcpserver::sersend(int socket,string&amp; data){<br \/>\n\/\/     send(socket,data.data(),data.size(),0);<br \/>\n\/\/ }<\/p>\n<p>\/*&#8212;&#8212;&#8212;&#8212;-\u8fde\u63a5\u5668\u7c7b\u5b9e\u73b0&#8212;&#8212;&#8212;&#8211;*\/<br \/>\n\/\/\u670d\u52a1\u5668\u8bfb\u53d6\u6570\u636e\u5e76\u5904\u7406<br \/>\nvoid ConnectionHandler::handleInput(int sockfd){<\/p>\n<p>    \/\/\u670d\u52a1\u5668\u8bfb\u53d6\u6570\u636e\u5e76\u663e\u793a<br \/>\n    string inbuff;<br \/>\n    char buff[1024];<br \/>\n    ssize_t nbytes&#061;recv(sockfd,buff,sizeof(buff),0);<br \/>\n     if (nbytes &lt;&#061; 0) {<br \/>\n        if (nbytes &#061;&#061; 0) {<br \/>\n            cout &lt;&lt; &#034;Client disconnected&#034; &lt;&lt; endl;<br \/>\n        } else {<br \/>\n            perror(&#034;recv error&#034;);<br \/>\n        }<br \/>\n    }<br \/>\n    else{<br \/>\n        inbuff.append(buff,nbytes);<br \/>\n        cout &lt;&lt; &#034;Received data: &#034; &lt;&lt; inbuff &lt;&lt; endl;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/\u670d\u52a1\u5668\u8f93\u51fa\u6570\u636e\u5e76\u5904\u7406<br \/>\nvoid ConnectionHandler::handleOutput(int sockfd){<br \/>\n    string outbuff &#061; &#034;Hello, Client!&#034;;<br \/>\n    send(sockfd,outbuff.data(),outbuff.size(),0);<br \/>\n}<\/p>\n<p>\/\/\u83b7\u53d6\u670d\u52a1\u5668\u5957\u63a5\u5b57<br \/>\nint ConnectionHandler::getsocket() {<\/p>\n<p>    return m_sockfd;<br \/>\n} <\/p>\n<p id=\"ub3143a1c\">Tcpclient.h<\/p>\n<p>\/*<br \/>\n\u5ba2\u6237\u7aef\u4e3b\u8981\u5b9e\u73b0\u529f\u80fd\u5982\u4e0b&#xff1a;<\/p>\n<p>1\u3001\u8fde\u63a5\u670d\u52a1\u5668<br \/>\n2\u3001\u53d1\u9001\u6570\u636e<br \/>\n3\u3001\u63a5\u6536\u54cd\u5e94<\/p>\n<p>*\/<\/p>\n<p>#pragma once<\/p>\n<p>#include&lt;iostream&gt;<br \/>\nusing namespace std;<\/p>\n<p>class Tcpclient{<\/p>\n<p>public:<br \/>\n    Tcpclient(string ip,int port);<\/p>\n<p>    ~Tcpclient();<br \/>\n    \/\/\u8fde\u63a5\u670d\u52a1\u5668<br \/>\n    bool connection();<\/p>\n<p>    ssize_t clisend(string&amp; data);<\/p>\n<p>    ssize_t clirecv(string&amp; buff);<\/p>\n<p>private:<\/p>\n<p>    \/\/\u5ba2\u6237\u7aefip<br \/>\n    string c_ip;<br \/>\n    \/\/\u5ba2\u6237\u7aef\u7aef\u53e3\u53f7<br \/>\n    int c_port;<br \/>\n    \/\/\u5ba2\u6237\u7aefsocket<br \/>\n    int clisock;<\/p>\n<p>};<\/p>\n<p id=\"ue5204f55\">Tcpclient.cpp<\/p>\n<p>#include&lt;iostream&gt;<br \/>\nusing namespace std;<br \/>\n#include&#034;Tcpclient.h&#034;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include &lt;arpa\/inet.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;poll.h&gt;<br \/>\n#include &lt;cstring&gt;<\/p>\n<p>Tcpclient:: Tcpclient(string ip,int port):c_ip(ip),c_port(port),clisock(-1){};<\/p>\n<p>Tcpclient::~Tcpclient(){<br \/>\n    if(clisock!&#061;-1){<br \/>\n        close(clisock);<br \/>\n    }<br \/>\n}<\/p>\n<p>bool Tcpclient::connection(){<\/p>\n<p>    \/\/\u521d\u59cb\u5316\u5ba2\u6237\u7aef\u5957\u63a5\u5b57&#xff1a;IPV4,TCP\u5b57\u8282\u6d41&#xff0c;\u9ed8\u8ba4\u534f\u8bae<br \/>\n    clisock&#061;socket(AF_INET,SOCK_STREAM,0);<\/p>\n<p>    \/\/\u7ed1\u5b9a\u5730\u5740<br \/>\n    struct  sockaddr_in cliaddr;<br \/>\n    memset(&amp;cliaddr,0,sizeof(cliaddr));<br \/>\n    cliaddr.sin_family&#061;AF_INET;<br \/>\n    \/\/\u6b64ip\u548cport\u662f\u7528\u6237\u6307\u5b9a\u7684<br \/>\n    cliaddr.sin_addr.s_addr&#061;inet_addr(c_ip.c_str());;<br \/>\n    cliaddr.sin_port&#061;htons(c_port);<\/p>\n<p>    \/\/\u8fde\u63a5\u670d\u52a1\u5668<\/p>\n<p>    if(connect(clisock,(struct sockaddr*)&amp;cliaddr,sizeof(cliaddr))&#061;&#061;-1){<br \/>\n        return false;<br \/>\n    }<br \/>\n    else{<br \/>\n        return true;<br \/>\n    }<\/p>\n<p>}<\/p>\n<p>ssize_t Tcpclient::clisend(string&amp; data){<br \/>\n    return send(clisock,data.data(),data.size(),0);<br \/>\n}<\/p>\n<p>ssize_t Tcpclient::clirecv(string&amp; buff){<br \/>\n    char temp[1024];<br \/>\n    ssize_t nbytes&#061;recv(clisock,temp,sizeof(temp),0);<br \/>\n    \/\/\u8bf4\u660e\u6ca1\u6709\u6570\u636e\u63a5\u6536\u5230<br \/>\n    if (nbytes &lt;&#061; 0) {<br \/>\n        if (nbytes &#061;&#061; 0) {<br \/>\n            cout &lt;&lt; &#034;\u670d\u52a1\u5668\u5173\u95ed\u8fde\u63a5&#034; &lt;&lt; endl;<br \/>\n        } else {<br \/>\n            perror(&#034;recv error&#034;);<br \/>\n        }<br \/>\n    }<br \/>\n    else {<br \/>\n        buff.append(temp, nbytes);<br \/>\n    }<br \/>\n    return nbytes;<br \/>\n} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.9k\u6b21\uff0c\u70b9\u8d5e37\u6b21\uff0c\u6536\u85cf37\u6b21\u3002\u57fa\u4e8e\u524d\u6587Epoll\u539f\u7406\uff0c\u672c\u6587\u5728\u57fa\u4e8epoll\u673a\u5236\u7684\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u901a\u4fe1\u7cfb\u7edf\u57fa\u7840\u4e0a\u8fdb\u884c\u4f18\u5316\uff0c\u5229\u7528epoll\u673a\u5236\u8fdb\u884c\u5b9e\u73b0_epoll\u5ba2\u6237\u7aef<\/p>\n","protected":false},"author":2,"featured_media":32860,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,190,427],"topic":[],"class_list":["post-32862","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-190","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf - \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\/32862.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.9k\u6b21\uff0c\u70b9\u8d5e37\u6b21\uff0c\u6536\u85cf37\u6b21\u3002\u57fa\u4e8e\u524d\u6587Epoll\u539f\u7406\uff0c\u672c\u6587\u5728\u57fa\u4e8epoll\u673a\u5236\u7684\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u901a\u4fe1\u7cfb\u7edf\u57fa\u7840\u4e0a\u8fdb\u884c\u4f18\u5316\uff0c\u5229\u7528epoll\u673a\u5236\u8fdb\u884c\u5b9e\u73b0_epoll\u5ba2\u6237\u7aef\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/32862.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-25T17:45:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425174520-680bca301ed9c.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\/32862.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/32862.html\",\"name\":\"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-25T17:45:22+00:00\",\"dateModified\":\"2025-04-25T17:45:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/32862.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/32862.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32862.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf\"}]},{\"@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":"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf - \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\/32862.html","og_locale":"zh_CN","og_type":"article","og_title":"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.9k\u6b21\uff0c\u70b9\u8d5e37\u6b21\uff0c\u6536\u85cf37\u6b21\u3002\u57fa\u4e8e\u524d\u6587Epoll\u539f\u7406\uff0c\u672c\u6587\u5728\u57fa\u4e8epoll\u673a\u5236\u7684\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u901a\u4fe1\u7cfb\u7edf\u57fa\u7840\u4e0a\u8fdb\u884c\u4f18\u5316\uff0c\u5229\u7528epoll\u673a\u5236\u8fdb\u884c\u5b9e\u73b0_epoll\u5ba2\u6237\u7aef","og_url":"https:\/\/www.wsisp.com\/helps\/32862.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-25T17:45:22+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425174520-680bca301ed9c.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\/32862.html","url":"https:\/\/www.wsisp.com\/helps\/32862.html","name":"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-25T17:45:22+00:00","dateModified":"2025-04-25T17:45:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/32862.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/32862.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/32862.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Epoll\u5b9e\u6218\uff1a\u624b\u6413Epoll\u673a\u5236\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u901a\u4fe1\u7cfb\u7edf"}]},{"@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\/32862","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=32862"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32862\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/32860"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=32862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=32862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=32862"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=32862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}