{"id":2606,"date":"2025-03-24T18:47:26","date_gmt":"2025-03-24T10:47:26","guid":{"rendered":"https:\/\/guapicoding.com\/?p=2606"},"modified":"2025-03-31T09:23:03","modified_gmt":"2025-03-31T01:23:03","slug":"%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e6%b7%b1%e5%b1%82%e5%89%96%e6%9e%90","status":"publish","type":"post","link":"https:\/\/guapicoding.com\/?p=2606","title":{"rendered":"\u7f51\u7edc\u7f16\u7a0b\u6df1\u5c42\u5256\u6790"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u9700\u8981 EPOLLONESHOT\uff1f<\/h2>\n\n\n\n<p><strong><code>epoll<\/code><\/strong> \u6709\u4e24\u79cd\u89e6\u53d1\u7684\u65b9\u5f0f\uff1aLT\uff08<strong>\u6c34\u5e73\u89e6\u53d1<\/strong>\uff09\u548cET\uff08<strong>\u8fb9\u7f18\u89e6\u53d1<\/strong>\uff09\u3002\u5bf9\u4e8e\u524d\u8005\uff0c\u53ea\u8981\u5b58\u5728\u7740\u4e8b\u4ef6\u5c31\u4f1a\u4e0d\u65ad\u7684\u89e6\u53d1\uff0c\u76f4\u5230\u5904\u7406\u5b8c\u6210\uff1b\u800c\u540e\u8005\u53ea\u89e6\u53d1\u4e00\u6b21\u76f8\u540c\u4e8b\u4ef6\uff0c\u6216\u8005\u8bf4\u53ea\u5728\u4ece\u975e\u89e6\u53d1\u5230\u89e6\u53d1\u4e24\u4e2a\u72b6\u6001\u8f6c\u6362\u7684\u65f6\u5019\u624d\u89e6\u53d1\u3002<\/p>\n\n\n\n<p>\u60f3\u8c61\u8fd9\u6837\u4e00\u79cd\u60c5\u51b5\uff0c\u5f53\u524d\u662f<strong>\u591a\u7ebf\u7a0b<\/strong>\u5728\u5904\u7406\uff0c\u4e00\u4e2a <code>socket<\/code> \u4e8b\u4ef6\u5230\u6765\uff0c\u6570\u636e\u5f00\u59cb\u89e3\u6790\u3002\u8fd9\u65f6\u5019\u8fd9\u4e2a <code>socket<\/code> \u53c8\u6765\u4e86\u540c\u6837\u4e00\u4e2a\u4e8b\u4ef6\uff0c\u800c\u4f60\u7684\u6570\u636e\u89e3\u6790\u5c1a\u672a\u5b8c\u6210\uff0c\u90a3\u4e48\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u8c03\u5ea6\u53e6\u5916\u4e00\u4e2a\u7ebf\u7a0b\u6216\u8005\u8fdb\u7a0b\u6765\u5904\u7406\u65b0\u7684\u4e8b\u4ef6\u3002\u8fd9\u5c31\u4f1a\u9020\u6210\u4e00\u4e2a\u5f88\u4e25\u91cd\u7684\u95ee\u9898\uff1a\u4e0d\u540c\u7684\u7ebf\u7a0b\u6216\u8005\u8fdb\u7a0b\u5728\u5904\u7406\u540c\u4e00\u4e2a <code>socket<\/code> \u7684\u4e8b\u4ef6\uff0c\u8fd9\u4f1a\u4f7f\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u5927\u5927\u964d\u4f4e\uff0c\u5373\u4f7f\u5728<strong>ET\u6a21\u5f0f<\/strong>\u4e0b\u4e5f\u6709\u53ef\u80fd\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n\n\n\n<p>\u89e3\u51b3\u8fd9\u79cd\u60c5\u51b5\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4e00\u662f\u5728\u5355\u72ec\u7684\u7ebf\u7a0b\u6216\u8fdb\u7a0b\u91cc\u89e3\u6790\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u63a5\u6536\u6570\u636e\u7684\u7ebf\u7a0b\u7acb\u523b\u5c06\u6570\u636e\u8f6c\u79fb\u81f3\u53e6\u5916\u7684\u7ebf\u7a0b\uff1b\u4e8c\u5c31\u662f\u5229\u7528<strong> <code>EPOLLONESHOT<\/code><\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u5bf9\u4e8e\u6ce8\u518c\u4e86 <code>EPOLLONESHOT<\/code> \u4e8b\u4ef6\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u64cd\u4f5c\u7cfb\u7edf\u6700\u591a\u53ea\u89e6\u53d1\u5176\u4e0a\u6ce8\u518c\u7684\u4e00\u4e2a\u4e8b\u4ef6\uff0c\u4e14\u4ec5\u89e6\u53d1\u4e00\u6b21<\/strong>\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u5904\u7406\u8be5 <code>socket<\/code> \u65f6\uff0c\u5176\u4ed6\u7ebf\u7a0b\u4e0d\u4f1a\u518d\u6536\u5230\u8be5 <code>socket<\/code> \u7684\u4e8b\u4ef6\u901a\u77e5\u3002<\/p>\n\n\n\n<p><strong>\u5982\u679c\u9700\u8981\u8ba9\u8be5 <code>socket<\/code> \u5728\u4e0b\u6b21\u53ef\u8bfb\u65f6\u4ecd\u7136\u89e6\u53d1\u4e8b\u4ef6<\/strong>\uff0c\u5fc5\u987b\u5728\u5904\u7406\u5b8c\u6bd5\u540e\uff0c\u4f7f\u7528 <code>epoll_ctl<\/code> \u91cd\u65b0\u6ce8\u518c <code>EPOLLONESHOT<\/code> \u4e8b\u4ef6\uff0c\u4ee5\u4fbf <code>socket<\/code> \u5728\u4e0b\u4e00\u6b21\u6709\u6570\u636e\u53ef\u8bfb\u65f6\u80fd\u518d\u6b21\u88ab\u89e6\u53d1\uff0c\u4ece\u800c\u8ba9\u5176\u4ed6\u7ebf\u7a0b\u6709\u673a\u4f1a\u7ee7\u7eed\u5904\u7406\u8be5 <code>socket<\/code>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e24\u79cd\u4e8b\u4ef6\u5904\u7406\u6a21\u578b\uff1aReactor\/Proactor<\/h2>\n\n\n\n<p>\u4e8c\u8005\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e <strong>\u8c01\u8d1f\u8d23\u5b8c\u6210 I\/O \u64cd\u4f5c<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Reactor<\/strong>\uff1aI\/O \u64cd\u4f5c\u7531 <strong>\u5de5\u4f5c\u7ebf\u7a0b<\/strong> \u5b8c\u6210\uff08<strong>\u540c\u6b65I\/O<\/strong>\uff09<\/li>\n\n\n\n<li><strong>Proactor<\/strong>\uff1aI\/O \u64cd\u4f5c\u7531 <strong>\u5185\u6838\u6216\u4e3b\u7ebf\u7a0b<\/strong> \u5b8c\u6210\uff0c\u5de5\u4f5c\u7ebf\u7a0b<strong>\u53ea\u5904\u7406\u903b\u8f91<\/strong>\uff08<strong>\u5f02\u6b65I\/O<\/strong>\uff09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Reactor<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e3b\u8981\u7279\u70b9\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u4e3b\u7ebf\u7a0b\uff08I\/O \u7ebf\u7a0b\uff09<\/strong> \u8d1f\u8d23\u76d1\u542c socket \u662f\u5426\u53ef\u8bfb\/\u53ef\u5199 <\/li>\n\n\n\n<li>\u5f53 <strong>socket \u53ef\u8bfb\/\u53ef\u5199<\/strong> \u65f6\uff0c\u4e3b\u7ebf\u7a0b\u901a\u77e5 <strong>\u5de5\u4f5c\u7ebf\u7a0b\uff08\u903b\u8f91\u7ebf\u7a0b\uff09<\/strong> \u8fdb\u884c\u6570\u636e\u8bfb\u53d6\u6216\u5199\u5165\uff0c\u5e76\u5904\u7406\u4e1a\u52a1\u903b\u8f91\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5904\u7406\u6d41\u7a0b\uff08\u4ee5 <code>read()<\/code> \u4e3a\u4f8b\uff09\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u4e3b\u7ebf\u7a0b\uff08I\/O \u7ebf\u7a0b\uff09<\/strong> \u76d1\u542c socket \u4e8b\u4ef6\uff08epoll\u3001select\u3001poll\uff09 <\/li>\n\n\n\n<li>\u5f53 socket <strong>\u53ef\u8bfb<\/strong> \u65f6\uff0c\u901a\u77e5 <strong>\u5de5\u4f5c\u7ebf\u7a0b<\/strong> \u5904\u7406 <\/li>\n\n\n\n<li><strong>\u5de5\u4f5c\u7ebf\u7a0b<\/strong> \u8c03\u7528 <code>read()<\/code> \u8bfb\u53d6\u6570\u636e\uff0c\u7136\u540e\u8fdb\u884c\u4e1a\u52a1\u5904\u7406 <\/li>\n\n\n\n<li>\u5904\u7406\u5b8c\u6210\u540e\uff0c<strong>\u5de5\u4f5c\u7ebf\u7a0b<\/strong> \u53ef\u80fd\u4f1a\u5411 socket <strong>\u5199\u5165<\/strong> \u54cd\u5e94\u6570\u636e <\/li>\n\n\n\n<li>\u82e5 socket \u53ef\u5199\uff0c<strong>\u4e3b\u7ebf\u7a0b<\/strong> \u518d\u6b21\u901a\u77e5 <strong>\u5de5\u4f5c\u7ebf\u7a0b<\/strong> \u5904\u7406\u5199\u64cd\u4f5c <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u4f18\u70b9\uff1a<strong>\u9ad8\u5e76\u53d1\u6027\u80fd<\/strong>\uff0c\u56e0\u4e3a I\/O \u7ebf\u7a0b\u53ea\u8d1f\u8d23\u4e8b\u4ef6\u901a\u77e5\uff0c\u4e0d\u505a\u7e41\u91cd\u7684 I\/O \u5904\u7406 <\/li>\n\n\n\n<li>\u7f3a\u70b9\uff1a<strong>\u6570\u636e\u8bfb\u53d6\u548c\u5199\u5165\u7531\u5de5\u4f5c\u7ebf\u7a0b\u5b8c\u6210<\/strong>\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4 <strong>I\/O \u963b\u585e<\/strong>\uff0c\u964d\u4f4e\u6027\u80fd <\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Proactor<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e3b\u8981\u7279\u70b9\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u4e3b\u7ebf\u7a0b\uff08I\/O \u7ebf\u7a0b\uff09+ \u5185\u6838<\/strong> \u8d1f\u8d23\u5b8c\u6210 I\/O \u64cd\u4f5c\uff08\u8bfb\/\u5199\uff09 <\/li>\n\n\n\n<li><strong>\u5de5\u4f5c\u7ebf\u7a0b<\/strong> \u53ea\u9700\u8981\u5904\u7406\u4e1a\u52a1\u903b\u8f91\uff0c\u800c\u4e0d\u6d89\u53ca I\/O \u8bfb\u5199\u64cd\u4f5c <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5904\u7406\u6d41\u7a0b\uff08\u4ee5 <code>read()<\/code> \u4e3a\u4f8b\uff09\uff1a\n<ul class=\"wp-block-list\">\n<li><strong>\u4e3b\u7ebf\u7a0b\uff08I\/O \u7ebf\u7a0b\uff09<\/strong> \u901a\u8fc7 <code>aio_read()<\/code> \u7b49\u5f02\u6b65 I\/O \u64cd\u4f5c\u5411 <strong>\u5185\u6838<\/strong> \u53d1\u8d77 I\/O \u8bf7\u6c42 <\/li>\n\n\n\n<li><strong>\u5185\u6838<\/strong> \u8d1f\u8d23\u5f02\u6b65\u5b8c\u6210 <code>read()<\/code> \u64cd\u4f5c\uff0c\u5e76\u5c06\u8bfb\u53d6\u7684\u6570\u636e\u653e\u5165\u7f13\u51b2\u533a <\/li>\n\n\n\n<li><strong>\u5f53\u5185\u6838\u5b8c\u6210 I\/O \u64cd\u4f5c<\/strong>\uff0c\u901a\u77e5 <strong>\u4e3b\u7ebf\u7a0b<\/strong>  <\/li>\n\n\n\n<li><strong>\u4e3b\u7ebf\u7a0b<\/strong> \u5c06\u4efb\u52a1\u4ea4\u7ed9 <strong>\u5de5\u4f5c\u7ebf\u7a0b<\/strong> \u8fdb\u884c\u4e1a\u52a1\u903b\u8f91\u5904\u7406\uff08\u5982 <code>pool-&gt;append(users + sockfd)<\/code>\uff09 <\/li>\n\n\n\n<li>\u82e5\u9700\u8981\u5199\u5165\u6570\u636e\uff0c<strong>\u4e3b\u7ebf\u7a0b<\/strong> \u8c03\u7528 <code>aio_write()<\/code>\uff0c\u8ba9 <strong>\u5185\u6838<\/strong> \u5f02\u6b65\u5b8c\u6210\u5199\u5165 <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u4f18\u70b9\uff1a<strong>I\/O \u7ebf\u7a0b\u51e0\u4e4e\u4e0d\u505a\u963b\u585e\u7b49\u5f85<\/strong>\uff0c\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u5904\u7406 I\/O \u8bf7\u6c42\uff0c\u66f4\u9002\u5408\u9ad8\u5e76\u53d1\u573a\u666f<\/li>\n\n\n\n<li>\u7f3a\u70b9\uff1a<strong>\u4f9d\u8d56\u64cd\u4f5c\u7cfb\u7edf\u652f\u6301\u5f02\u6b65 I\/O<\/strong>\uff0c<strong>\u5b9e\u73b0\u590d\u6742\u5ea6\u8f83\u9ad8<\/strong><br><\/li>\n<\/ul>\n\n\n\n<p><strong>Reactor \u662f\u975e\u963b\u585e\u540c\u6b65\u7f51\u7edc\u6a21\u5f0f\uff0c\u611f\u77e5\u7684\u662f<em>\u5c31\u7eea\u53ef\u8bfb\u5199\u4e8b\u4ef6<\/em><\/strong>\u3002\u5728\u6bcf\u6b21\u611f\u77e5\u5230\u6709\u4e8b\u4ef6\u53d1\u751f\uff08\u6bd4\u5982\u53ef\u8bfb\u5c31\u7eea\u4e8b\u4ef6\uff09\u540e\uff0c\u5c31\u9700\u8981\u5e94\u7528\u8fdb\u7a0b\u4e3b\u52a8\u8c03\u7528 read \u65b9\u6cd5\u6765\u5b8c\u6210\u6570\u636e\u7684\u8bfb\u53d6\uff0c\u4e5f\u5c31\u662f\u8981\u5e94\u7528\u8fdb\u7a0b\u4e3b\u52a8\u5c06 socket \u63a5\u6536\u7f13\u5b58\u4e2d\u7684\u6570\u636e\u8bfb\u5230\u5e94\u7528\u8fdb\u7a0b\u5185\u5b58\u4e2d\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u540c\u6b65\u7684\uff0c\u8bfb\u53d6\u5b8c\u6570\u636e\u540e\u5e94\u7528\u8fdb\u7a0b\u624d\u80fd\u5904\u7406\u6570\u636e\u3002<\/p>\n\n\n\n<p><strong>Proactor \u662f\u5f02\u6b65\u7f51\u7edc\u6a21\u5f0f\uff0c\u611f\u77e5\u7684\u662f<em>\u5df2\u5b8c\u6210\u7684\u8bfb\u5199\u4e8b\u4ef6<\/em><\/strong>\u3002\u5728\u53d1\u8d77\u5f02\u6b65\u8bfb\u5199\u8bf7\u6c42\u65f6\uff0c\u9700\u8981\u4f20\u5165\u6570\u636e\u7f13\u51b2\u533a\u7684\u5730\u5740\uff08\u7528\u6765\u5b58\u653e\u7ed3\u679c\u6570\u636e\uff09\u7b49\u4fe1\u606f\uff0c\u8fd9\u6837\u7cfb\u7edf\u5185\u6838\u624d\u53ef\u4ee5\u81ea\u52a8\u5e2e\u6211\u4eec\u628a\u6570\u636e\u7684\u8bfb\u5199\u5de5\u4f5c\u5b8c\u6210\uff0c\u8fd9\u91cc\u7684\u8bfb\u5199\u5de5\u4f5c\u5168\u7a0b\u7531\u64cd\u4f5c\u7cfb\u7edf\u6765\u505a\uff0c\u5e76\u4e0d\u9700\u8981\u50cf Reactor \u90a3\u6837\u8fd8\u9700\u8981\u5e94\u7528\u8fdb\u7a0b\u4e3b\u52a8\u53d1\u8d77 read\/write \u6765\u8bfb\u5199\u6570\u636e\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5b8c\u6210\u8bfb\u5199\u5de5\u4f5c\u540e\uff0c\u5c31\u4f1a\u901a\u77e5\u5e94\u7528\u8fdb\u7a0b\u76f4\u63a5\u5904\u7406\u6570\u636e\u3002<\/p>\n\n\n\n<p><br>\u56e0\u6b64\uff0cReactor \u53ef\u4ee5\u7406\u89e3\u4e3a<strong>\u6765\u4e86\u4e8b\u4ef6\u64cd\u4f5c\u7cfb\u7edf\u901a\u77e5\u5e94\u7528\u8fdb\u7a0b\uff0c\u8ba9\u5e94\u7528\u8fdb\u7a0b\u6765\u5904\u7406<\/strong>\uff0c\u800c Proactor \u53ef\u4ee5\u7406\u89e3\u4e3a<strong>\u6765\u4e86\u4e8b\u4ef6\u64cd\u4f5c\u7cfb\u7edf\u6765\u5904\u7406\uff0c\u5904\u7406\u5b8c\u518d\u901a\u77e5\u5e94\u7528\u8fdb\u7a0b<\/strong>\u3002\u8fd9\u91cc\u7684<strong>\u4e8b\u4ef6<\/strong>\u5c31\u662f\u6709\u65b0\u8fde\u63a5\u3001\u6709\u6570\u636e\u53ef\u8bfb\u3001\u6709\u6570\u636e\u53ef\u5199\u7684\u8fd9\u4e9b 1\/0 \u4e8b\u4ef6\u8fd9\u91cc\u7684<strong>\u5904\u7406<\/strong>\u5305\u542b\u4ece\u9a71\u52a8\u8bfb\u53d6\u5230\u5185\u6838\u4ee5\u53ca\u4ece\u5185\u6838\u8bfb\u53d6\u5230\u7528\u6237\u7a7a\u95f4\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u4e00\u822c\u60c5\u51b5\u4e0b epoll \u6027\u80fd\u8981\u4f18\u4e8e select \u548c poll\uff1f<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e select \u548c poll \u6765\u8bf4\uff0c\u6240\u6709\u6587\u4ef6\u63cf\u8ff0\u7b26\u90fd\u662f\u5728<strong>\u7528\u6237\u6001<\/strong>\u88ab\u52a0\u5165\u5176\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u7684\uff0c\u6bcf\u6b21\u8c03\u7528\u90fd\u9700\u8981\u5c06\u6574\u4e2a\u96c6\u5408\u62f7\u8d1d\u5230\u5185\u6838\u6001\uff1bepoll \u5219\u5c06\u6574\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u7ef4\u62a4\u5728<strong>\u5185\u6838\u6001<\/strong>\uff0c\u6bcf\u6b21\u6dfb\u52a0\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u65f6\u5019\u90fd\u9700\u8981\u6267\u884c\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\u3002<strong>\u7cfb\u7edf\u8c03\u7528<\/strong>\u7684\u5f00\u9500\u662f\u5f88\u5927\u7684\uff0c\u5728\u6709\u5f88\u591a\u77ed\u671f\u6d3b\u8dc3\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\uff0c\u7531\u4e8e\u8fd9\u4e9b\u5927\u91cf\u7684\u7cfb\u7edf\u8c03\u7528\u5f00\u9500\uff0cepoll \u53ef\u80fd\u4f1a\u6162\u4e8e select \u548c poll\u3002<\/li>\n\n\n\n<li>select \u4f7f\u7528\u7ebf\u6027\u8868\u63cf\u8ff0\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\uff0c<strong>\u6587\u4ef6\u63cf\u8ff0\u7b26\u6709\u4e0a\u9650<\/strong>\uff1bpoll \u4f7f\u7528\u94fe\u8868\u6765\u63cf\u8ff0\uff1b\u800c epoll \u5e95\u5c42\u901a\u8fc7<strong>\u7ea2\u9ed1\u6811<\/strong>\u6765\u63cf\u8ff0\uff0c\u5e76\u4e14\u7ef4\u62a4\u4e00\u4e2a ready list\uff0c\u5c06\u4e8b\u4ef6\u8868\u4e2d\u5df2\u7ecf\u5c31\u7eea\u7684\u4e8b\u4ef6\u6dfb\u52a0\u5230\u8fd9\u91cc\uff0c\u5728\u4f7f\u7528 epoll_wait \u8c03\u7528\u65f6\uff0c\u4ec5\u89c2\u5bdf\u8fd9\u4e2a list \u4e2d\u6709\u6ca1\u6709\u6570\u636e\u5373\u53ef\u3002<\/li>\n\n\n\n<li>select \u548c poll \u7684\u6700\u5927\u5f00\u9500\u6765\u81ea\u5185\u6838\u5224\u65ad\u662f\u5426\u6709\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea\u8fd9\u4e00\u8fc7\u7a0b\uff1a\u6bcf\u6b21\u6267\u884c select \u6216 poll \u8c03\u7528\u65f6\uff0c\u5b83\u4eec\u4f1a\u91c7\u7528\u904d\u5386\u7684\u65b9\u5f0f\uff0c\u904d\u5386\u6574\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u53bb\u5224\u65ad\u5404\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5426\u6709\u6d3b\u52a8\uff1bepoll \u5219\u4e0d\u9700\u8981\u53bb\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u68c0\u67e5\u3002\u5f53\u6709\u6d3b\u52a8\u4ea7\u751f\u65f6\uff0c\u4f1a\u81ea\u52a8\u89e6\u53d1 epoll \u56de\u8c03\u51fd\u6570\u901a\u77e5 epoll \u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u7136\u540e\u5185\u6838\u5c06\u8fd9\u4e9b\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u653e\u5230\u4e4b\u524d\u63d0\u5230\u7684 ready list \u4e2d\u7b49\u5f85 epoll_wait \u8c03\u7528\u540e\u88ab\u5904\u7406\u3002<\/li>\n\n\n\n<li>select \u548c poll \u90fd\u53ea\u80fd\u5de5\u4f5c\u5728\u76f8\u5bf9\u4f4e\u6548\u7684LT\u6a21\u5f0f\u4e0b\uff0c\u800c epoll \u540c\u65f6\u652f\u6301LT\u548cET\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7efc\u4e0a\uff0c\u5f53\u76d1\u6d4b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\u8f83\u5c0f\uff0c\u4e14\u90fd\u5f88\u6d3b\u8dc3\u7684\u60c5\u51b5\u4e0b\uff0c\u5efa\u8bae\u4f7f\u7528 select \u548c poll\uff1b\u5f53\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\u8f83\u591a\uff0c\u4e14\u5355\u4f4d\u65f6\u95f4\u4ec5\u90e8\u5206\u6d3b\u8dc3\u7684\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 epoll \u4f1a\u660e\u663e\u63d0\u5347\u6027\u80fd\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>GET\u548cPOST\u7684\u533a\u522b<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6700\u76f4\u89c2\u7684\u533a\u522b\u5c31\u662fGET\u628a\u53c2\u6570\u5305\u542b\u5728URL\u4e2d\uff0cPOST \u901a\u8fc7 request body \u4f20\u9012\u53c2\u6570\u3002<\/li>\n\n\n\n<li>GET\u8bf7\u6c42\u53c2\u6570\u4f1a\u88ab\u5b8c\u6574\u4fdd\u7559\u5728\u6d4f\u89c8\u5668\u5386\u53f2\u8bb0\u5f55\u91cc\uff0c\u800cPOST\u4e2d\u7684\u53c2\u6570\u4e0d\u4f1a\u88ab\u4fdd\u7559\u3002<\/li>\n\n\n\n<li>GET\u8bf7\u6c42\u5728URL\u4e2d\u4f20\u9001\u7684\u53c2\u6570\u662f\u6709\u957f\u5ea6\u9650\u5236\uff0c\uff08\u5927\u591a\u6570\uff09\u6d4f\u89c8\u5668\u901a\u5e38\u90fd\u4f1a\u9650\u5236url\u957f\u5ea6\u57282K\u4e2a\u5b57\u8282\uff0c\u800c\uff08\u5927\u591a\u6570\uff09\u670d\u52a1\u5668\u6700\u591a\u5904\u740664K\u5927\u5c0f\u7684url\u3002<\/li>\n\n\n\n<li>GET\u4ea7\u751f\u4e00\u4e2aTCP\u6570\u636e\u5305\uff1bPOST\u4ea7\u751f\u4e24\u4e2aTCP\u6570\u636e\u5305\u3002\u5bf9\u4e8eGET\u65b9\u5f0f\u7684\u8bf7\u6c42\uff0c\u6d4f\u89c8\u5668\u4f1a\u628a http header   \u548c data \u4e00\u5e76\u53d1\u9001\u51fa\u53bb\uff0c\u670d\u52a1\u5668\u54cd\u5e94 200\uff08\u8fd4\u56de\u6570\u636e\uff09\uff1b\u800c\u5bf9\u4e8ePOST\uff0c\u6d4f\u89c8\u5668\u5148\u53d1\u9001 header\uff0c\u670d\u52a1\u5668\u54cd\u5e94 100\uff08\u6307\u793a\u4fe1\u606f\u2014\u8868\u793a\u8bf7\u6c42\u5df2\u63a5\u6536\uff0c\u7ee7\u7eed\u5904\u7406\uff09continue\uff0c\u6d4f\u89c8\u5668\u518d\u53d1\u9001 data\uff0c\u670d\u52a1\u5668\u54cd\u5e94 200 ok\uff08\u8fd4\u56de\u6570\u636e\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u4e3e\u4f8b\uff1a<\/strong>\u5047\u8bbe\u4f60\u5df2\u7ecf\u642d\u597d\u4e86\u4f60\u7684HTTP\u670d\u52a1\u5668\uff0c\u7136\u540e\u4f60\u5728\u672c\u5730\u6d4f\u89c8\u5668\u4e2d\u952e\u5165<code>localhost:9000<\/code>\uff0c\u7136\u540e\u56de\u8f66\uff0c\u8fd9\u65f6\u5019\u4f60\u5c31\u7ed9\u4f60\u7684\u670d\u52a1\u5668\u53d1\u9001\u4e86\u4e00\u4e2aGET\u8bf7\u6c42\uff0c\u4ec0\u4e48\u90fd\u6ca1\u505a\uff0c\u7136\u540e\u670d\u52a1\u5668\u7aef\u5c31\u4f1a\u89e3\u6790\u4f60\u7684\u8fd9\u4e2aHTTP\u8bf7\u6c42\uff0c\u7136\u540e\u53d1\u73b0\u662f\u4e2aGET\u8bf7\u6c42\uff0c\u7136\u540e\u8fd4\u56de\u7ed9\u4f60\u4e00\u4e2a\u9759\u6001HTML\u9875\u9762\uff0c\u4e5f\u5c31\u662f\u9879\u76ee\u4e2d\u7684<code>judge.html<\/code>\u9875\u9762\uff0c\u90a3POST\u8bf7\u6c42\u600e\u4e48\u6765\u7684\u5462\uff1f\u8fd9\u65f6\u4f60\u4f1a\u53d1\u73b0\uff0c\u8fd4\u56de\u7684\u8fd9\u4e2a<code>judge<\/code>\u9875\u9762\u4e2d\u5305\u542b\u7740\u4e00\u4e9b<code>\u65b0\u7528\u6237<\/code>\u548c<code>\u5df2\u6709\u8d26\u53f7<\/code>\u8fd9\u4e24\u4e2a<code>button<\/code>\u5143\u7d20\uff0c\u5f53\u4f60\u7528\u9f20\u6807\u70b9\u51fb\u8fd9\u4e2a<code>button<\/code>\u65f6\uff0c\u4f60\u7684\u6d4f\u89c8\u5668\u5c31\u4f1a\u5411\u4f60\u7684\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2aPOST\u8bf7\u6c42\uff0c\u670d\u52a1\u5668\u6bb5\u901a\u8fc7\u68c0\u67e5<code>action<\/code>\u6765\u5224\u65ad\u4f60\u7684POST\u8bf7\u6c42\u7c7b\u578b\u662f\u4ec0\u4e48\uff0c\u8fdb\u800c\u505a\u51fa\u4e0d\u540c\u7684\u54cd\u5e94\u3002<\/p>\n\n\n\n<p><strong>\u603b\u7ed3\uff1aGET \u8bf7\u6c42\u662f\u7d22\u53d6\u6570\u636e\uff0cPOST \u8bf7\u6c42\u662f\u63d0\u4f9b\u6570\u636e<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u9700\u8981 EPOLLONESHOT\uff1f epoll \u6709\u4e24\u79cd\u89e6\u53d1\u7684\u65b9\u5f0f\uff1aLT\uff08\u6c34\u5e73\u89e6\u53d1\uff09\u548cET\uff08\u8fb9\u7f18\u89e6\u53d1\uff09\u3002\u5bf9\u4e8e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[87],"tags":[56,21,50],"class_list":["post-2606","post","type-post","status-publish","format-standard","hentry","category-87","tag-epoll","tag-linux","tag-50"],"_links":{"self":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts\/2606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2606"}],"version-history":[{"count":15,"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts\/2606\/revisions"}],"predecessor-version":[{"id":2737,"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts\/2606\/revisions\/2737"}],"wp:attachment":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}