{"id":77641,"date":"2026-02-25T03:41:53","date_gmt":"2026-02-24T19:41:53","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/77641.html"},"modified":"2026-02-25T03:41:53","modified_gmt":"2026-02-24T19:41:53","slug":"%e3%80%90c-%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e3%80%91%e4%b8%80%e7%af%87%e6%96%87%e7%ab%a0%e6%90%9e%e6%87%82i-o%e5%a4%9a%e8%b7%af%e5%a4%8d%e7%94%a8%ef%bc%88select%e3%80%81poll%e3%80%81epoll","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/77641.html","title":{"rendered":"\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09"},"content":{"rendered":"<h3>I\/O\u591a\u8def\u590d\u7528<\/h3>\n<p>IO\u591a\u8def\u590d\u7528\u4e5f\u79f0\u4e3aIO\u591a\u8def\u8f6c\u63a5&#xff0c;\u5b83\u662f\u4e00\u79cd\u7f51\u7edc\u901a\u4fe1\u7684\u624b\u6bb5&#xff08;\u673a\u5236&#xff09;&#xff0c;\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u540c\u65f6\u76d1\u6d4b\u591a\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u5e76\u4e14\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u963b\u585e\u7684&#xff0c;\u4e00\u65e6\u68c0\u6d4b\u5230\u6709\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea&#xff08; \u53ef\u4ee5\u8bfb\u6570\u636e\u6216\u8005\u53ef\u4ee5\u5199\u6570\u636e&#xff09;\u7a0b\u5e8f\u7684\u963b\u585e\u5c31\u4f1a\u88ab\u89e3\u9664&#xff0c;\u4e4b\u540e\u5c31\u53ef\u4ee5\u57fa\u4e8e\u8fd9\u4e9b&#xff08;\u4e00\u4e2a\u6216\u591a\u4e2a&#xff09;\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u901a\u4fe1\u4e86\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u5728\u5355\u7ebf\u7a0b\/\u8fdb\u7a0b\u7684\u573a\u666f\u4e0b\u4e5f\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u7aef\u5b9e\u73b0\u5e76\u53d1\u3002\u5e38\u89c1\u7684IO\u591a\u8def\u8f6c\u63a5\u65b9\u5f0f\u6709&#xff1a;select\u3001poll\u3001epoll&#xff08;select\u8de8\u5e73\u53f0 \u540e\u4e24\u79cdLinux\u5e73\u53f0\u72ec\u5360&#xff09;<\/p>\n<p>\u4e0b\u9762\u5148\u5bf9\u591a\u7ebf\u7a0b\/\u591a\u8fdb\u7a0b\u5e76\u53d1\u548cI\/O\u591a\u8def\u590d\u7528\u7684\u5e76\u53d1\u5904\u7406\u6d41\u7a0b\u8fdb\u884c\u5bf9\u6bd4&#xff08;\u670d\u52a1\u5668\u7aef&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u591a\u7ebf\u7a0b\/\u591a\u8fdb\u7a0b\u5e76\u53d1\n<ul>\n<li>\u4e3b\u7ebf\u7a0b\/\u7236\u8fdb\u7a0b&#xff1a;\u8c03\u7528 accept()\u76d1\u6d4b\u5ba2\u6237\u7aef\u8fde\u63a5\u8bf7\u6c42\n<ul>\n<li>\u5982\u679c\u6ca1\u6709\u65b0\u7684\u5ba2\u6237\u7aef\u7684\u8fde\u63a5\u8bf7\u6c42&#xff0c;\u5f53\u524d\u7ebf\u7a0b\/\u8fdb\u7a0b\u4f1a\u963b\u585e<\/li>\n<li>\u5982\u679c\u6709\u65b0\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\u8bf7\u6c42\u89e3\u9664\u963b\u585e&#xff0c;\u5efa\u7acb\u8fde\u63a5<\/li>\n<\/ul>\n<\/li>\n<li>\u5b50\u7ebf\u7a0b\/\u5b50\u8fdb\u7a0b&#xff1a;\u548c\u5efa\u7acb\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u901a\u4fe1\n<ul>\n<li>\u8c03\u7528 read() \/ recv() \u63a5\u6536\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u901a\u4fe1\u6570\u636e&#xff0c;\u5982\u679c\u6ca1\u6709\u901a\u4fe1\u6570\u636e&#xff0c;\u5f53\u524d\u7ebf\u7a0b\/\u8fdb\u7a0b\u4f1a\u963b\u585e&#xff0c;\u6570\u636e\u5230\u8fbe\u4e4b\u540e\u963b\u585e\u81ea\u52a8\u89e3\u9664<\/li>\n<li>\u8c03\u7528 write() \/ send() \u7ed9\u5ba2\u6237\u7aef\u53d1\u9001\u6570\u636e&#xff0c;\u5982\u679c\u5199\u7f13\u51b2\u533a\u5df2\u6ee1&#xff0c;\u5f53\u524d\u7ebf\u7a0b\/\u8fdb\u7a0b\u4f1a\u963b\u585e&#xff0c;\u5426\u5219\u5c06\u5f85\u53d1\u9001\u6570\u636e\u5199\u5165\u5199\u7f13\u51b2\u533a\u4e2d<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>I\/O\u591a\u8def\u590d\u7528\u5e76\u53d1\n<ul>\n<li>\u4f7f\u7528I\/O\u591a\u8def\u8f6c\u63a5\u51fd\u6570\u59d4\u6258\u5185\u6838\u68c0\u6d4b\u670d\u52a1\u5668\u7aef\u6240\u6709\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff08;\u901a\u4fe1\u548c\u76d1\u542c\u4e24\u7c7b&#xff09;&#xff0c;\u8fd9\u4e2a\u68c0\u6d4b\u8fc7\u7a0b\u4f1a\u5bfc\u81f4\u8fdb\u7a0b\/\u7ebf\u7a0b\u7684\u963b\u585e&#xff0c;\u5982\u679c\u68c0\u6d4b\u5230\u5df2\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u963b\u585e\u89e3\u9664&#xff0c;\u5219\u5c06\u8fd9\u4e9b\u5df2\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fd4\u56de<\/li>\n<li>\u6839\u636e\u7c7b\u578b\u5bf9\u4f20\u51fa\u7684\u6240\u6709\u5df2\u5c31\u7eea\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u5224\u65ad&#xff0c;\u5e76\u505a\u51fa\u4e0d\u540c\u7684\u5904\u7406\n<ul>\n<li>\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff1a;\u548c\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5<\/li>\n<li>\u6b64\u65f6\u8c03\u7528accept()\u662f\u4e0d\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u963b\u585e\u7684&#xff0c;\u56e0\u4e3a\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5df2\u5c31\u7eea\u7684&#xff08;\u6709\u65b0\u8bf7\u6c42&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\u901a\u4fe1\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff1a;\u8c03\u7528\u901a\u4fe1\u51fd\u6570\u548c\u5df2\u5efa\u7acb\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u901a\u4fe1\n<ul>\n<li>\u8c03\u7528 read() \/ recv() \u4e0d\u4f1a\u963b\u585e\u7a0b\u5e8f&#xff0c;\u56e0\u4e3a\u901a\u4fe1\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5c31\u7eea\u7684&#xff0c;\u8bfb\u7f13\u51b2\u533a\u5185\u5df2\u6709\u6570\u636e<\/li>\n<li>\u8c03\u7528 write() \/ send() \u4e0d\u4f1a\u963b\u585e\u7a0b\u5e8f&#xff0c;\u56e0\u4e3a\u901a\u4fe1\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5c31\u7eea\u7684&#xff0c;\u5199\u7f13\u51b2\u533a\u4e0d\u6ee1&#xff0c;\u53ef\u4ee5\u5f80\u91cc\u9762\u5199\u6570\u636e<\/li>\n<\/ul>\n<\/li>\n<li>\u5bf9\u8fd9\u4e9b\u6587\u4ef6\u63cf\u8ff0\u7b26\u7ee7\u7eed\u8fdb\u884c\u4e0b\u4e00\u8f6e\u7684\u68c0\u6d4b&#xff08;\u5faa\u73af\u5f80\u590d\u3002\u3002\u3002&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4e0e\u591a\u8fdb\u7a0b\u548c\u591a\u7ebf\u7a0b\u6280\u672f\u76f8\u6bd4&#xff0c;I\/O\u591a\u8def\u590d\u7528\u6280\u672f\u7684\u6700\u5927\u4f18\u52bf\u662f\u7cfb\u7edf\u5f00\u9500\u5c0f&#xff0c;\u7cfb\u7edf\u4e0d\u5fc5\u521b\u5efa\u8fdb\u7a0b\/\u7ebf\u7a0b&#xff0c;\u4e5f\u4e0d\u5fc5\u7ef4\u62a4\u8fd9\u4e9b\u8fdb\u7a0b\/\u7ebf\u7a0b&#xff0c;\u4ece\u800c\u5927\u5927\u51cf\u5c0f\u4e86\u7cfb\u7edf\u7684\u5f00\u9500\u3002<\/p>\n<h4>select<\/h4>\n<p>\u4f7f\u7528select\u8fd9\u79cdI\/O\u591a\u8def\u590d\u7528\u65b9\u5f0f\u9700\u8981\u8c03\u7528\u4e00\u4e2a\u540c\u540d\u51fd\u6570select&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u662f\u8de8\u5e73\u53f0\u7684&#xff0c;Linux\u3001Mac\u3001Windows\u90fd\u662f\u652f\u6301\u7684\u3002<\/p>\n<p>\u901a\u8fc7\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u59d4\u6258\u5185\u6838\u5e2e\u52a9\u6211\u4eec\u68c0\u6d4b\u82e5\u5e72\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u72b6\u6001&#xff0c;\u5176\u5b9e\u5c31\u662f\u68c0\u6d4b\u8fd9\u4e9b\u6587\u4ef6\u63cf\u8ff0\u7b26\u5bf9\u5e94\u7684\u8bfb\u5199\u7f13\u51b2\u533a\u7684\u72b6\u6001&#xff1a;<\/p>\n<ul>\n<li>\u8bfb\u7f13\u51b2\u533a&#xff1a;\u68c0\u6d4b\u91cc\u8fb9\u6709\u6ca1\u6709\u6570\u636e&#xff0c;\u5982\u679c\u6709\u6570\u636e\u8be5\u7f13\u51b2\u533a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea<\/li>\n<li>\u5199\u7f13\u51b2\u533a&#xff1a;\u68c0\u6d4b\u5199\u7f13\u51b2\u533a\u662f\u5426\u53ef\u4ee5\u5199(\u6709\u6ca1\u6709\u5bb9\u91cf)&#xff0c;\u5982\u679c\u6709\u5bb9\u91cf\u53ef\u4ee5\u5199&#xff0c;\u7f13\u51b2\u533a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea<\/li>\n<li>\u8bfb\u5199\u5f02\u5e38&#xff1a;\u68c0\u6d4b\u8bfb\u5199\u7f13\u51b2\u533a\u662f\u5426\u6709\u5f02\u5e38&#xff0c;\u5982\u679c\u6709\u8be5\u7f13\u51b2\u533a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea<\/li>\n<\/ul>\n<p>\u59d4\u6258\u68c0\u6d4b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u88ab\u904d\u5386\u68c0\u6d4b\u5b8c\u6bd5\u4e4b\u540e&#xff0c;\u5df2\u5c31\u7eea\u7684\u8fd9\u4e9b\u6ee1\u8db3\u6761\u4ef6\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4f1a\u901a\u8fc7select()\u7684\u53c2\u6570\u52063\u4e2a\u96c6\u5408\u4f20\u51fa&#xff0c;\u5f97\u5230\u8fd9\u51e0\u4e2a\u96c6\u5408\u4e4b\u540e\u5c31\u53ef\u4ee5\u5206\u60c5\u51b5\u4f9d\u6b21\u5904\u7406\u4e86\u3002<\/p>\n<p>select\u51fd\u6570\u539f\u578b:<\/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;sys\/select.h&gt;<\/span><\/span><br \/>\n<span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">timeval<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    time_t      tv_sec<span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/* seconds *\/<\/span><br \/>\n    suseconds_t tv_usec<span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/* microseconds *\/<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u963b\u585e\u603b\u65f6\u957f\u4e3a sec &#043; microsec, \u4e24\u8005\u90fd\u9700\u8981\u521d\u59cb\u5316&#xff0c;\u5426\u5219\u53ef\u80fd\u8bfb\u53d6\u5230\u968f\u673a\u503c<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">select<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> nfds<span class=\"token punctuation\">,<\/span>          <span class=\"token comment\">\/\/ \u76d1\u542c\u7684\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26 &#043; 1<\/span><br \/>\n    fd_set <span class=\"token operator\">*<\/span>readfds<span class=\"token punctuation\">,<\/span>   <span class=\"token comment\">\/\/ \u76d1\u542c\u201c\u8bfb\u4e8b\u4ef6\u201d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408<\/span><br \/>\n    fd_set <span class=\"token operator\">*<\/span>writefds<span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">\/\/ \u76d1\u542c\u201c\u5199\u4e8b\u4ef6\u201d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408<\/span><br \/>\n    fd_set <span class=\"token operator\">*<\/span>exceptfds<span class=\"token punctuation\">,<\/span> <span class=\"token comment\">\/\/ \u76d1\u542c\u201c\u5f02\u5e38\u4e8b\u4ef6\u201d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408<\/span><br \/>\n    <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">timeval<\/span> <span class=\"token operator\">*<\/span>timeout  <span class=\"token comment\">\/\/ \u8d85\u65f6\u65f6\u95f4&#xff08;NULL\u8868\u793a\u6c38\u4e45\u963b\u585e&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<ul>\n<li>\u51fd\u6570\u53c2\u6570&#xff1a;\n<ul>\n<li>nfds&#xff1a;\u59d4\u6258\u5185\u6838\u68c0\u6d4b\u7684\u8fd9\u4e09\u4e2a\u96c6\u5408\u4e2d\u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26 &#043; 1&#xff08;\u6700\u59271024&#xff09;\n<ul>\n<li>\u5185\u6838\u9700\u8981\u7ebf\u6027\u904d\u5386\u8fd9\u4e9b\u96c6\u5408\u4e2d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u8fd9\u4e2a\u503c\u662f\u5faa\u73af\u7ed3\u675f\u7684\u6761\u4ef6<\/li>\n<li>\u5728Window\u4e2d\u8fd9\u4e2a\u53c2\u6570\u662f\u65e0\u6548\u7684&#xff0c;\u6307\u5b9a\u4e3a-1\u5373\u53ef<\/li>\n<\/ul>\n<\/li>\n<li>readfds&#xff1a;\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u96c6\u5408, \u5185\u6838\u53ea\u68c0\u6d4b\u8fd9\u4e2a\u96c6\u5408\u4e2d\u6587\u4ef6\u63cf\u8ff0\u7b26\u5bf9\u5e94\u7684\u8bfb\u7f13\u51b2\u533a\n<ul>\n<li>\u4f20\u5165\u4f20\u51fa\u53c2\u6570&#xff0c;\u8bfb\u96c6\u5408\u4e00\u822c\u60c5\u51b5\u4e0b\u90fd\u662f\u9700\u8981\u68c0\u6d4b\u7684&#xff0c;\u8fd9\u6837\u624d\u77e5\u9053\u901a\u8fc7\u54ea\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u63a5\u6536\u6570\u636e<\/li>\n<\/ul>\n<\/li>\n<li>writefds&#xff1a;\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u96c6\u5408, \u5185\u6838\u53ea\u68c0\u6d4b\u8fd9\u4e2a\u96c6\u5408\u4e2d\u6587\u4ef6\u63cf\u8ff0\u7b26\u5bf9\u5e94\u7684\u5199\u7f13\u51b2\u533a\n<ul>\n<li>\u4f20\u5165\u4f20\u51fa\u53c2\u6570&#xff0c;\u5982\u679c\u4e0d\u9700\u8981\u4f7f\u7528\u8fd9\u4e2a\u53c2\u6570\u53ef\u4ee5\u6307\u5b9a\u4e3aNULL<\/li>\n<\/ul>\n<\/li>\n<li>exceptfds&#xff1a;\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u96c6\u5408, \u5185\u6838\u68c0\u6d4b\u96c6\u5408\u4e2d\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5426\u6709\u5f02\u5e38\u72b6\u6001\n<ul>\n<li>\u4f20\u5165\u4f20\u51fa\u53c2\u6570&#xff0c;\u5982\u679c\u4e0d\u9700\u8981\u4f7f\u7528\u8fd9\u4e2a\u53c2\u6570\u53ef\u4ee5\u6307\u5b9a\u4e3aNULL<\/li>\n<\/ul>\n<\/li>\n<li>timeout&#xff1a;\u8d85\u65f6\u65f6\u957f&#xff0c;\u7528\u6765\u5f3a\u5236\u89e3\u9664select()\u51fd\u6570\u7684\u963b\u585e\u7684\n<ul>\n<li>NULL&#xff1a;\u51fd\u6570\u68c0\u6d4b\u4e0d\u5230\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4f1a\u4e00\u76f4\u963b\u585e\u3002<\/li>\n<li>\u7b49\u5f85\u56fa\u5b9a\u65f6\u957f&#xff08;\u79d2&#xff09;&#xff1a;\u51fd\u6570\u68c0\u6d4b\u4e0d\u5230\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u5728\u6307\u5b9a\u65f6\u957f\u4e4b\u540e\u5f3a\u5236\u89e3\u9664\u963b\u585e&#xff0c;\u51fd\u6570\u8fd4\u56de0<\/li>\n<li>\u4e0d\u7b49\u5f85&#xff1a;\u51fd\u6570\u4e0d\u4f1a\u963b\u585e&#xff0c;\u76f4\u63a5\u5c06\u8be5\u53c2\u6570\u5bf9\u5e94\u7684\u7ed3\u6784\u4f53\u521d\u59cb\u5316\u4e3a0\u5373\u53ef\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u51fd\u6570\u8fd4\u56de\u503c&#xff1a;\n<ul>\n<li>\u5927\u4e8e0&#xff1a;\u6210\u529f&#xff0c;\u8fd4\u56de\u96c6\u5408\u4e2d\u5df2\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u603b\u4e2a\u6570<\/li>\n<li>\u7b49\u4e8e-1&#xff1a;\u51fd\u6570\u8c03\u7528\u5931\u8d25<\/li>\n<li>\u7b49\u4e8e0&#xff1a;\u8d85\u65f6&#xff0c;\u6ca1\u6709\u68c0\u6d4b\u5230\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408fd_set\u53ca\u64cd\u4f5c\u51fd\u6570<\/h5>\n<p>fd_set\u662f\u4e00\u4e2a\u4f4d\u56fe(Bitset)\u7ed3\u6784&#xff08;\u672c\u8d28\u662f\u6574\u6570\u6570\u7ec4&#xff09;&#xff0c;\u6bcf\u4e2a\u4f4d\u5bf9\u5e94\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u72b6\u6001&#xff08;0 &#061; \u4e0d\u76d1\u542c&#xff0c;1 &#061; \u76d1\u542c&#xff09;\u3002\u7cfb\u7edf\u63d0\u4f9b 4 \u4e2a\u64cd\u4f5c\u51fd\u6570&#xff1a;<\/p>\n<p>\/\/ \u5c06fd\u4eceset\u4e2d\u6e05\u9664&#xff08;\u7f6e0&#xff09;<br \/>\nvoid FD_CLR(int fd, fd_set *set);<br \/>\n\/\/ \u68c0\u67e5fd\u662f\u5426\u5728set\u4e2d&#xff08;\u8fd4\u56de1\u8868\u793a\u5b58\u5728&#xff0c;0\u8868\u793a\u4e0d\u5b58\u5728&#xff09;<br \/>\nint FD_ISSET(int fd, fd_set *set);<br \/>\n\/\/ \u5c06fd\u6dfb\u52a0\u5230set\u4e2d&#xff08;\u7f6e1&#xff09;<br \/>\nvoid FD_SET(int fd, fd_set *set);<br \/>\n\/\/ \u5c06set\u4e2d\u6240\u6709\u4f4d\u6e05\u96f6<br \/>\nvoid FD_ZERO(fd_set *set);<\/p>\n<p>\u5728select()\u51fd\u6570\u4e2d\u7b2c2\u30013\u30014\u4e2a\u53c2\u6570\u90fd\u662ffd_set\u7c7b\u578b&#xff0c;\u5b83\u8868\u793a\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u96c6\u5408&#xff0c;\u7c7b\u4f3c\u4e8e\u4fe1\u53f7\u96c6 sigset_t&#xff0c;\u8fd9\u4e2a\u7c7b\u578b\u7684\u6570\u636e\u6709128\u4e2a\u5b57\u8282&#xff0c;\u4e5f\u5c31\u662f1024\u4e2a\u6807\u5fd7\u4f4d&#xff0c;\u548c\u5185\u6838\u4e2d\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\u4e2d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2a\u6570\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u8fd9\u5e76\u4e0d\u662f\u5de7\u5408&#xff0c;\u800c\u662f\u6545\u610f\u4e3a\u4e4b\u3002\u8fd9\u5757\u5185\u5b58\u4e2d\u7684\u6bcf\u4e00\u4e2abit \u548c \u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u4e00\u4e00\u5bf9\u5e94\u7684\u5173\u7cfb&#xff0c;\u8fd9\u6837\u5c31\u53ef\u4ee5\u4f7f\u7528\u6700\u5c0f\u7684\u5b58\u50a8\u7a7a\u95f4\u5c06\u8981\u8868\u8fbe\u7684\u610f\u601d\u63cf\u8ff0\u51fa\u6765\u4e86\u3002<\/p>\n<p>\u4e0b\u56fe\u4e2d\u7684fd_set\u4e2d\u5b58\u50a8\u4e86\u8981\u59d4\u6258\u5185\u6838\u68c0\u6d4b\u8bfb\u7f13\u51b2\u533a\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u96c6\u5408\u4e2d\u7684\u6807\u5fd7\u4f4d\u4e3a0\u4ee3\u8868\u4e0d\u68c0\u6d4b\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u72b6\u6001<\/li>\n<li>\u5982\u679c\u96c6\u5408\u4e2d\u7684\u6807\u5fd7\u4f4d\u4e3a1\u4ee3\u8868\u68c0\u6d4b\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u72b6\u6001<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194144-699dfef8b21ca.png\" alt=\"\u3002\" \/><\/p>\n<p>\u5185\u6838\u5728\u904d\u5386\u8fd9\u4e2a\u8bfb\u96c6\u5408\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u5982\u679c\u88ab\u68c0\u6d4b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5bf9\u5e94\u7684\u8bfb\u7f13\u51b2\u533a\u4e2d\u6ca1\u6709\u6570\u636e&#xff0c;\u5185\u6838\u5c06\u4fee\u6539\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u5728\u8bfb\u96c6\u5408fd_set\u4e2d\u5bf9\u5e94\u7684\u6807\u5fd7\u4f4d&#xff0c;\u6539\u4e3a0&#xff0c;\u5982\u679c\u6709\u6570\u636e\u90a3\u4e48\u8fd9\u4e2a\u6807\u5fd7\u4f4d\u7684\u503c\u4e0d\u53d8&#xff0c;\u8fd8\u662f1<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194145-699dfef9c166d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h5>\u4f7f\u7528select\u5904\u7406\u5e76\u53d1<\/h5>\n<p>\u5982\u679c\u5728\u670d\u52a1\u5668\u57fa\u4e8eselect\u5b9e\u73b0\u5e76\u53d1&#xff0c;\u5176\u5904\u7406\u6d41\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa\u76d1\u542c\u7684\u5957\u63a5\u5b57 lfd &#061; socket()<\/li>\n<li>\u5c06\u76d1\u542c\u7684\u5957\u63a5\u5b57\u548c\u672c\u5730\u7684IP\u548c\u7aef\u53e3\u7ed1\u5b9a bind()<\/li>\n<li>\u7ed9\u76d1\u542c\u7684\u5957\u63a5\u5b57\u8bbe\u7f6e\u76d1\u542c listen()<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408 fd_set&#xff0c;\u7528\u4e8e\u5b58\u50a8\u9700\u8981\u68c0\u6d4b\u8bfb\u4e8b\u4ef6\u7684\u6240\u6709\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\n<ul>\n<li>\u901a\u8fc7 FD_ZERO() \u521d\u59cb\u5316<\/li>\n<li>\u901a\u8fc7 FD_SET() \u5c06\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u653e\u5165\u68c0\u6d4b\u7684\u8bfb\u96c6\u5408\u4e2d<\/li>\n<\/ul>\n<\/li>\n<li>\u5faa\u73af\u8c03\u7528select()&#xff0c;\u5468\u671f\u6027\u7684\u5bf9\u6240\u6709\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u68c0\u6d4b<\/li>\n<li>select() \u89e3\u9664\u963b\u585e\u8fd4\u56de&#xff0c;\u5f97\u5230\u5185\u6838\u4f20\u51fa\u7684\u6ee1\u8db3\u6761\u4ef6\u7684\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\n<ul>\n<li>\u901a\u8fc7FD_ISSET() \u5224\u65ad\u96c6\u5408\u4e2d\u7684\u6807\u5fd7\u4f4d\u662f\u5426\u4e3a 1\n<ul>\n<li>\u5982\u679c\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u8c03\u7528 accept() \u548c\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5\n<ul>\n<li>\u5c06\u5f97\u5230\u7684\u65b0\u7684\u901a\u4fe1\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u901a\u8fc7FD_SET() \u653e\u5165\u5230\u68c0\u6d4b\u96c6\u5408\u4e2d<\/li>\n<\/ul>\n<\/li>\n<li>\u5982\u679c\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u901a\u4fe1\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;                      \u8c03\u7528\u901a\u4fe1\u51fd\u6570\u548c\u5ba2\u6237\u7aef\u901a\u4fe1\n<ul>\n<li>\u5982\u679c\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u65ad\u5f00\u4e86\u8fde\u63a5&#xff0c;\u4f7f\u7528FD_CLR()\u5c06\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u4ece\u68c0\u6d4b\u96c6\u5408\u4e2d\u5220\u9664<\/li>\n<li>\u5982\u679c\u6ca1\u6709\u65ad\u5f00\u8fde\u63a5&#xff0c;\u6b63\u5e38\u901a\u4fe1\u5373\u53ef<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u91cd\u590d\u7b2c6\u6b65<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194146-699dfefad1608.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>poll<\/h4>\n<p>poll\u7684\u673a\u5236\u4e0eselect\u7c7b\u4f3c&#xff0c;\u4e0eselect\u5728\u672c\u8d28\u4e0a\u6ca1\u6709\u591a\u5927\u5dee\u522b&#xff0c;\u4f7f\u7528\u65b9\u6cd5\u4e5f\u7c7b\u4f3c&#xff0c;\u4e0b\u9762\u7684\u662f\u5bf9\u4e8e\u4e8c\u8005\u7684\u5bf9\u6bd4&#xff1a;<\/p>\n<ul>\n<li>\u5185\u6838\u5bf9\u5e94\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u68c0\u6d4b\u4e5f\u662f\u4ee5\u7ebf\u6027\u7684\u65b9\u5f0f\u8fdb\u884c\u8f6e\u8be2&#xff0c;\u6839\u636e\u63cf\u8ff0\u7b26\u7684\u72b6\u6001\u8fdb\u884c\u5904\u7406<\/li>\n<li>poll\u548cselect\u68c0\u6d4b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u4f1a\u5728\u68c0\u6d4b\u8fc7\u7a0b\u4e2d\u9891\u7e41\u7684\u8fdb\u884c\u7528\u6237\u533a\u548c\u5185\u6838\u533a\u7684\u62f7\u8d1d&#xff0c;\u5b83\u7684\u5f00\u9500\u968f\u7740\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\u7684\u589e\u52a0\u800c\u7ebf\u6027\u589e\u5927&#xff0c;\u4ece\u800c\u6548\u7387\u4e5f\u4f1a\u8d8a\u6765\u8d8a\u4f4e\u3002<\/li>\n<li>select\u68c0\u6d4b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2a\u6570\u4e0a\u9650\u662f1024&#xff0c;poll\u6ca1\u6709\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\u7684\u9650\u5236<\/li>\n<li>select\u53ef\u4ee5\u8de8\u5e73\u53f0\u4f7f\u7528&#xff0c;poll\u53ea\u80fd\u5728Linux\u5e73\u53f0\u4f7f\u7528<\/li>\n<\/ul>\n<p>poll\u51fd\u6570\u7684\u51fd\u6570\u539f\u578b\u5982\u4e0b&#xff1a;<\/p>\n<p>#include &lt;poll.h&gt;<br \/>\n\/\/ \u6838\u5fc3\u53c2\u6570&#xff1a;<br \/>\n\/\/   fds&#xff1a;\u5f85\u76d1\u542c\u7684fd\u6570\u7ec4&#xff08;struct pollfd\u7c7b\u578b&#xff09;<br \/>\n\/\/   nfds&#xff1a;\u6570\u7ec4\u957f\u5ea6&#xff08;\u9700\u4f20\u5165\u6700\u5927\u7684fd&#043;1&#xff0c;\u548cselect\u4e00\u81f4&#xff09;<br \/>\n\/\/   timeout&#xff1a;\u8d85\u65f6\u65f6\u95f4&#xff08;\u6beb\u79d2&#xff09;&#xff0c;-1&#061;\u6c38\u4e45\u963b\u585e&#xff0c;0&#061;\u975e\u963b\u585e<br \/>\nint poll(struct pollfd *fds, nfds_t nfds, int timeout);<\/p>\n<p>\u6838\u5fc3pollfd\u7ed3\u6784\u4f53<\/p>\n<p>struct pollfd {<br \/>\n    int   fd;         \/\/ \u8981\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff08;\u5982server_fd\u3001client_fd&#xff09;<br \/>\n    short events;     \/\/ \u8981\u76d1\u542c\u7684\u4e8b\u4ef6&#xff08;\u8f93\u5165&#xff1a;\u544a\u8bc9\u5185\u6838\u6211\u8981\u7b49\u4ec0\u4e48\u4e8b\u4ef6&#xff09;<br \/>\n    short revents;    \/\/ \u5b9e\u9645\u53d1\u751f\u7684\u4e8b\u4ef6&#xff08;\u8f93\u51fa&#xff1a;\u5185\u6838\u544a\u8bc9\u6211\u4eec\u53d1\u751f\u4e86\u4ec0\u4e48&#xff09;<br \/>\n};<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194147-699dfefb30e0d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5e38\u7528\u4e8b\u4ef6\u5b8f&#xff08;events\/revents&#xff09;&#xff1a;<\/p>\n<table>\n<tr>\u4e8b\u4ef6\u5b8f\u542b\u4e49\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td align=\"center\">POLLIN<\/td>\n<td align=\"center\">\u6709\u6570\u636e\u53ef\u8bfb&#xff08;\u5bf9\u5e94 select \u7684\u8bfb\u4e8b\u4ef6&#xff09;<\/td>\n<td align=\"center\">\u76d1\u542c\u5ba2\u6237\u7aef\u8fde\u63a5\u3001\u63a5\u6536\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">POLLOUT<\/td>\n<td align=\"center\">\u53ef\u5199\u6570\u636e&#xff08;\u5bf9\u5e94 select \u7684\u5199\u4e8b\u4ef6&#xff09;<\/td>\n<td align=\"center\">\u53d1\u9001\u6570\u636e&#xff08;\u5982\u5927\u6587\u4ef6\u4f20\u8f93&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">POLLERR<\/td>\n<td align=\"center\">fd \u53d1\u751f\u9519\u8bef<\/td>\n<td align=\"center\">\u68c0\u6d4b\u8fde\u63a5\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">POLLHUP<\/td>\n<td align=\"center\">fd \u88ab\u6302\u65ad&#xff08;\u5982\u5ba2\u6237\u7aef\u65ad\u5f00&#xff09;<\/td>\n<td align=\"center\">\u68c0\u6d4b\u8fde\u63a5\u5173\u95ed<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">POLLNVAL<\/td>\n<td align=\"center\">fd \u65e0\u6548&#xff08;\u672a\u6253\u5f00 \/ \u5df2\u5173\u95ed&#xff09;<\/td>\n<td align=\"center\">\u68c0\u6d4b fd \u5408\u6cd5\u6027<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd4\u56de\u503c&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6210\u529f&#xff1a;\u8fd4\u56de\u6709\u4e8b\u4ef6\u53d1\u751f\u7684 fd \u6570\u91cf&#xff1b;<\/p>\n<\/li>\n<li>\n<p>0&#xff1a;\u8d85\u65f6&#xff08;timeout&gt;0 \u65f6&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>-1&#xff1a;\u5931\u8d25&#xff08;\u8bbe\u7f6e errno&#xff0c;\u5982 EINTR \u8868\u793a\u88ab\u4fe1\u53f7\u4e2d\u65ad&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>poll \u5bf9\u6bd4 select&#xff1a;\u6838\u5fc3\u4f18\u52bf<\/h5>\n<p>poll() \u5b8c\u7f8e\u89e3\u51b3\u4e86 select() \u7684 3 \u4e2a\u6838\u5fc3\u95ee\u9898&#xff1a;<\/p>\n<table>\n<tr>\u7279\u6027select()poll()<\/tr>\n<tbody>\n<tr>\n<td align=\"center\">fd \u5b58\u50a8\u65b9\u5f0f<\/td>\n<td align=\"center\">\u7528 fd_set&#xff08;\u4f4d\u56fe&#xff09;&#xff0c;\u9ed8\u8ba4\u6700\u5927\u76d1\u542c 1024 \u4e2a<\/td>\n<td align=\"center\">\u7528 struct pollfd \u6570\u7ec4&#xff0c;\u65e0 fd \u6570\u91cf\u9650\u5236&#xff08;\u4ec5\u53d7\u7cfb\u7edf\u8d44\u6e90\u9650\u5236&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u4e8b\u4ef6\u4e0e\u7ed3\u679c\u5206\u79bb<\/td>\n<td align=\"center\">\u8f93\u5165\u8f93\u51fa\u5171\u7528 fd_set&#xff0c;\u6bcf\u6b21\u9700\u91cd\u65b0\u521d\u59cb\u5316<\/td>\n<td align=\"center\">events&#xff08;\u8f93\u5165&#xff09;\u548c revents&#xff08;\u8f93\u51fa&#xff09;\u5206\u79bb&#xff0c;\u65e0\u9700\u91cd\u590d\u521d\u59cb\u5316<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u65e0\u6548 fd \u5904\u7406<\/td>\n<td align=\"center\">\u9700\u624b\u52a8\u904d\u5386\u6392\u9664\u65e0\u6548 fd<\/td>\n<td align=\"center\">revents \u4f1a\u8fd4\u56de POL\u00b7<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u6027\u80fd&#xff08;\u9ad8\u5e76\u53d1&#xff09;<\/td>\n<td align=\"center\">\u6bcf\u6b21\u9700\u904d\u5386 0~max_fd&#xff0c;\u4f4e\u6548<\/td>\n<td align=\"center\">\u53ea\u9700\u904d\u5386\u6709\u4e8b\u4ef6\u7684 fd&#xff0c;\u9ad8\u6548<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li>select() \u6bcf\u6b21\u5faa\u73af\u90fd\u8981\u91cd\u65b0\u62f7\u8d1d read_fds \u5230 temp_fds&#xff0c;\u56e0\u4e3a select() \u4f1a\u4fee\u6539\u4f20\u5165\u7684 fd_set&#xff1b;<\/li>\n<li>poll() \u53ea\u9700\u521d\u59cb\u5316\u4e00\u6b21 struct pollfd \u6570\u7ec4&#xff08;\u540e\u7eed\u4ec5\u66f4\u65b0\u9700\u8981\u76d1\u542c\u7684 fd&#xff09;&#xff0c;\u56e0\u4e3a events \u4e0d\u4f1a\u88ab\u5185\u6838\u4fee\u6539&#xff0c;\u53ea\u6709 revents \u4f1a\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<h4>epoll<\/h4>\n<p>epoll \u5168\u79f0 eventpoll&#xff0c;epoll \u662f Linux \u5185\u6838\u4e13\u4e3a\u9ad8\u5e76\u53d1 IO\u8bbe\u8ba1\u7684\u591a\u8def\u590d\u7528\u673a\u5236&#xff0c;\u662f select\/poll \u7684\u7ec8\u6781\u5347\u7ea7\u7248 \u2014\u2014 \u89e3\u51b3\u4e86\u524d\u4e24\u8005 \u201c\u904d\u5386\u6240\u6709 fd\u201d \u7684\u6027\u80fd\u74f6\u9888&#xff0c;\u4e5f\u662f Nginx\/Redis \u7b49\u9ad8\u6027\u80fd\u4e2d\u95f4\u4ef6\u7684\u6838\u5fc3 IO \u6a21\u578b\u3002<\/p>\n<h5>epoll\u6838\u5fc3\u539f\u7406<\/h5>\n<p>\u6838\u5fc3\u75db\u70b9&#xff1a;select\/poll \u7684\u6027\u80fd\u74f6\u9888<\/p>\n<ul>\n<li>select\/poll \u662f **\u201c\u8f6e\u8be2\u201d \u6a21\u5f0f **&#xff1a;\u6bcf\u6b21\u8c03\u7528\u90fd\u8981\u628a\u6240\u6709\u76d1\u542c\u7684 fd \u4ece\u7528\u6237\u6001\u62f7\u8d1d\u5230\u5185\u6838\u6001&#xff0c;\u7136\u540e\u5185\u6838\u904d\u5386\u6240\u6709 fd \u68c0\u6d4b\u4e8b\u4ef6&#xff0c;\u6700\u540e\u518d\u628a\u7ed3\u679c\u62f7\u8d1d\u56de\u7528\u6237\u6001&#xff1b;<\/li>\n<li>\u5373\u4f7f\u53ea\u6709 1 \u4e2a fd \u6709\u4e8b\u4ef6&#xff0c;\u4e5f\u9700\u8981\u904d\u5386\u5168\u90e8 fd&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6 O (n)&#xff0c;\u5e76\u53d1\u8d8a\u9ad8\u8d8a\u6162&#xff08;\u6bd4\u5982 10 \u4e07 fd \u65f6&#xff0c;\u904d\u5386\u6210\u672c\u6781\u9ad8&#xff09;\u3002<\/li>\n<\/ul>\n<p>epoll \u7684\u6838\u5fc3\u6539\u8fdb&#xff1a;\u201c\u4e8b\u4ef6\u9a71\u52a8\u201d&#043;\u201c\u5185\u5b58\u6620\u5c04\u201d<\/p>\n<p>epoll \u5f7b\u5e95\u98a0\u8986\u4e86\u8f6e\u8be2\u6a21\u5f0f&#xff0c;\u6838\u5fc3\u8bbe\u8ba1&#xff1a;<\/p>\n<table>\n<tr>\u7279\u6027\u5b9e\u73b0\u65b9\u5f0f\u6548\u679c<\/tr>\n<tbody>\n<tr>\n<td align=\"center\">\u5185\u6838\u6001\u4e8b\u4ef6\u8868<\/td>\n<td align=\"center\">\u5728\u5185\u6838\u4e2d\u521b\u5efa\u4e00\u4e2aepoll \u5b9e\u4f8b&#xff08;\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff09;&#xff0c;\u4e13\u95e8\u5b58\u50a8\u9700\u8981\u76d1\u542c\u7684 fd \u548c\u4e8b\u4ef6&#xff1b;<\/td>\n<td align=\"center\">\u65e0\u9700\u6bcf\u6b21\u62f7\u8d1d fd \u5230\u5185\u6838\u6001<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u4e8b\u4ef6\u56de\u8c03\u673a\u5236<\/td>\n<td align=\"center\">\u5185\u6838\u901a\u8fc7\u56de\u8c03\u51fd\u6570\u76f4\u63a5\u6807\u8bb0\u6709\u4e8b\u4ef6\u7684 fd&#xff0c;\u800c\u975e\u904d\u5386\u6240\u6709 fd&#xff1b;<\/td>\n<td align=\"center\">\u65f6\u95f4\u590d\u6742\u5ea6 O (1)&#xff0c;\u4ec5\u5904\u7406\u6709\u4e8b\u4ef6\u7684 fd<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u5185\u5b58\u6620\u5c04&#xff08;mmap&#xff09;<\/td>\n<td align=\"center\">\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u5171\u4eab\u4e8b\u4ef6\u8868\u5185\u5b58&#xff0c;\u907f\u514d\u6570\u636e\u62f7\u8d1d&#xff1b;<\/td>\n<td align=\"center\">\u51cf\u5c11\u5185\u5b58\u62f7\u8d1d\u5f00\u9500<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u652f\u6301\u8fb9\u7f18\u89e6\u53d1&#xff08;ET&#xff09;<\/td>\n<td align=\"center\">\u4ec5\u5728 fd \u72b6\u6001\u53d8\u5316\u65f6\u89e6\u53d1\u4e8b\u4ef6&#xff08;\u800c\u975e\u6c34\u5e73\u89e6\u53d1 LT \u7684 \u201c\u6709\u6570\u636e\u5c31\u89e6\u53d1\u201d&#xff09;&#xff1b;<\/td>\n<td align=\"center\">\u51cf\u5c11\u4e8b\u4ef6\u89e6\u53d1\u6b21\u6570&#xff0c;\u63d0\u5347\u6548\u7387<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>epoll \u652f\u6301\u4e24\u79cd\u4e8b\u4ef6\u89e6\u53d1\u6a21\u5f0f&#xff0c;\u8fd9\u662f\u5176\u9ad8\u6027\u80fd\u7684\u5173\u952e&#xff1a;<\/p>\n<h5>\u6c34\u5e73\u89e6\u53d1&#xff08;LT&#xff0c;Level Trigger&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u884c\u4e3a&#xff1a;\u53ea\u8981 fd \u7684\u7f13\u51b2\u533a\u6709\u6570\u636e \/ \u53ef\u5199&#xff0c;\u5c31\u4f1a\u6301\u7eed\u89e6\u53d1\u4e8b\u4ef6&#xff08;\u548c select\/poll \u884c\u4e3a\u4e00\u81f4&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7279\u70b9&#xff1a;\u7f16\u7a0b\u7b80\u5355&#xff0c;\u4e0d\u6613\u51fa\u9519&#xff0c;\u9002\u5408\u65b0\u624b&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u573a\u666f&#xff1a;\u4e2d\u5c0f\u5e76\u53d1\u3001\u9700\u8981\u517c\u5bb9 select\/poll \u903b\u8f91\u7684\u573a\u666f\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>\u8fb9\u7f18\u89e6\u53d1&#xff08;ET&#xff0c;Edge Trigger&#xff09;<\/h5>\n<ul>\n<li>\u884c\u4e3a&#xff1a;\u4ec5\u5728 fd \u7684\u72b6\u6001 \u201c\u53d8\u5316\u201d \u65f6\u89e6\u53d1\u4e00\u6b21\u4e8b\u4ef6&#xff08;\u6bd4\u5982&#xff1a;\u7f13\u51b2\u533a\u4ece\u7a7a\u2192\u6709\u6570\u636e&#xff0c;\u4ec5\u89e6\u53d1\u4e00\u6b21&#xff09;&#xff1b;<\/li>\n<li>\u7279\u70b9&#xff1a;\u89e6\u53d1\u6b21\u6570\u6781\u5c11&#xff0c;\u6027\u80fd\u6781\u9ad8&#xff0c;\u4f46\u7f16\u7a0b\u8981\u6c42\u9ad8&#xff08;\u5fc5\u987b\u4e00\u6b21\u6027\u8bfb\u5b8c\u7f13\u51b2\u533a\u6240\u6709\u6570\u636e&#xff09;&#xff1b;<\/li>\n<li>\u573a\u666f&#xff1a;\u9ad8\u5e76\u53d1&#xff08;10 \u4e07 &#043; \u8fde\u63a5&#xff09;\u3001\u8ffd\u6c42\u6781\u81f4\u6027\u80fd\u7684\u573a\u666f&#xff08;\u5982 Nginx&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u6ce8\u610f&#xff1a;epoll \u9ed8\u8ba4\u662f LT \u6a21\u5f0f&#xff0c;ET \u6a21\u5f0f\u9700\u8981\u663e\u5f0f\u6307\u5b9a\u3002<\/p>\n<h5>epoll\u7684\u6838\u5fc3API<\/h5>\n<p>epoll \u7684 API \u975e\u5e38\u7b80\u6d01&#xff0c;\u53ea\u6709 3 \u4e2a\u6838\u5fc3\u51fd\u6570&#xff0c;\u5168\u90e8\u5b9a\u4e49\u5728 &lt;sys\/epoll.h&gt; \u5934\u6587\u4ef6\u4e2d\u3002<\/p>\n<ul>\n<li>epoll_create&#xff1a;\u521b\u5efa epoll \u5b9e\u4f8b<\/li>\n<\/ul>\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;sys\/epoll.h&gt;<\/span><\/span><br \/>\n<span class=\"token comment\">\/\/ size&#xff1a;\u5df2\u5e9f\u5f03&#xff08;\u5386\u53f2\u9057\u7559\u53c2\u6570&#xff09;&#xff0c;\u53ea\u9700\u4f20\u5165\u5927\u4e8e0\u7684\u6570\u5373\u53ef<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8fd4\u56de\u503c&#xff1a;epoll\u5b9e\u4f8b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff08;epfd&#xff09;&#xff0c;\u5931\u8d25\u8fd4\u56de-1<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">epoll_create<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> size<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u5347\u7ea7\u7248&#xff08;\u63a8\u8350&#xff09;&#xff1a;\u6307\u5b9aEPOLL_CLOEXEC&#xff0c;\u8fdb\u7a0b\u66ff\u6362\u65f6\u81ea\u52a8\u5173\u95edepfd<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">epoll_create1<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> flags<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4f5c\u7528&#xff1a;\u5728\u5185\u6838\u4e2d\u521b\u5efa\u4e00\u4e2a epoll \u4e8b\u4ef6\u8868&#xff08;\u7ea2\u9ed1\u6811\u5b9e\u73b0&#xff09;&#xff0c;\u8fd4\u56de\u7684 epfd \u662f\u64cd\u4f5c\u8fd9\u4e2a\u4e8b\u4ef6\u8868\u7684\u53e5\u67c4&#xff1b;<\/p>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> epfd <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">epoll_create1<\/span><span class=\"token punctuation\">(<\/span>EPOLL_CLOEXEC<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>epfd <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;epoll_create1 failed&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span>EXIT_FAILURE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<ul>\n<li>epoll_ctl&#xff1a;\u7ba1\u7406 epoll \u4e8b\u4ef6\u8868&#xff08;\u589e \/ \u5220 \/ \u6539 fd&#xff09;<\/li>\n<\/ul>\n<p>\u8fd9\u662f epoll \u7684\u6838\u5fc3 \u2014\u2014 \u5411\u4e8b\u4ef6\u8868\u4e2d\u6dfb\u52a0 \/ \u5220\u9664 \/ \u4fee\u6539\u9700\u8981\u76d1\u542c\u7684 fd \u548c\u4e8b\u4ef6\u3002<\/p>\n<p><span class=\"token comment\">\/\/ epfd&#xff1a;epoll\u5b9e\u4f8b\u7684fd&#xff08;epoll_create\u7684\u8fd4\u56de\u503c&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/ op&#xff1a;\u64cd\u4f5c\u7c7b\u578b&#xff08;EPOLL_CTL_ADD\/EPOLL_CTL_MOD\/EPOLL_CTL_DEL&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/ fd&#xff1a;\u8981\u76d1\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff08;\u5982server_fd\/client_fd&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/ event&#xff1a;\u8981\u76d1\u542c\u7684\u4e8b\u4ef6&#xff08;struct epoll_event\u7ed3\u6784\u4f53&#xff09;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">epoll_ctl<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> epfd<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> op<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> fd<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">epoll_event<\/span> <span class=\"token operator\">*<\/span>event<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6838\u5fc3\u7ed3\u6784\u4f53 struct epoll_event&#xff1a;<\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">epoll_event<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">uint32_t<\/span>     events<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8981\u76d1\u542c\u7684\u4e8b\u4ef6&#xff08;\u5982EPOLLIN&#xff09;<\/span><br \/>\n    <span class=\"token class-name\">epoll_data_t<\/span> data<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u81ea\u5b9a\u4e49\u6570\u636e&#xff08;\u901a\u5e38\u5b58fd&#xff0c;\u4e5f\u53ef\u5b58\u6307\u9488&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u8054\u5408\u4f53&#xff0c;\u6309\u9700\u4f7f\u7528<\/span><br \/>\n<span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">union<\/span> epoll_data <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">void<\/span>        <span class=\"token operator\">*<\/span>ptr<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u81ea\u5b9a\u4e49\u6307\u9488<\/span><br \/>\n    <span class=\"token keyword\">int<\/span>          fd<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u5b58\u50a8fd&#xff08;\u6700\u5e38\u7528&#xff09;<\/span><br \/>\n    <span class=\"token class-name\">uint32_t<\/span>     u32<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token class-name\">uint64_t<\/span>     u64<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> <span class=\"token class-name\">epoll_data_t<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5e38\u7528\u4e8b\u4ef6\u5b8f&#xff1a;<\/p>\n<table>\n<tr>\u4e8b\u4ef6\u5b8f\u542b\u4e49\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td align=\"center\">EPOLLIN<\/td>\n<td align=\"center\">\u6709\u6570\u636e\u53ef\u8bfb&#xff08;\u65b0\u8fde\u63a5 \/ \u5ba2\u6237\u7aef\u53d1\u6570\u636e&#xff09;<\/td>\n<td align=\"center\">\u6838\u5fc3\u4e8b\u4ef6&#xff0c;\u5fc5\u76d1\u542c<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">EPOLLOUT<\/td>\n<td align=\"center\">\u53ef\u5199\u6570\u636e<\/td>\n<td align=\"center\">\u5927\u6587\u4ef6\u4f20\u8f93 \/ \u6279\u91cf\u53d1\u9001<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">EPOLLERR<\/td>\n<td align=\"center\">fd \u53d1\u751f\u9519\u8bef<\/td>\n<td align=\"center\">\u81ea\u52a8\u76d1\u542c&#xff0c;\u65e0\u9700\u663e\u5f0f\u6307\u5b9a<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">EPOLLHUP<\/td>\n<td align=\"center\">fd \u88ab\u6302\u65ad&#xff08;\u5ba2\u6237\u7aef\u65ad\u5f00&#xff09;<\/td>\n<td align=\"center\">\u81ea\u52a8\u76d1\u542c&#xff0c;\u65e0\u9700\u663e\u5f0f\u6307\u5b9a<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">EPOLLET<\/td>\n<td align=\"center\">\u8fb9\u7f18\u89e6\u53d1\u6a21\u5f0f&#xff08;\u9ed8\u8ba4 LT&#xff09;<\/td>\n<td align=\"center\">\u9ad8\u5e76\u53d1\u573a\u666f<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">EPOLLONESHOT<\/td>\n<td align=\"center\">\u4ec5\u89e6\u53d1\u4e00\u6b21\u4e8b\u4ef6&#xff0c;\u9700\u91cd\u65b0\u6ce8\u518c<\/td>\n<td align=\"center\">\u591a\u7ebf\u7a0b\u5904\u7406\u540c\u4e00 fd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5e38\u7528\u64cd\u4f5c&#xff08;op&#xff09;&#xff1a;<\/p>\n<ul>\n<li>EPOLL_CTL_ADD&#xff1a;\u5411 epoll \u4e8b\u4ef6\u8868\u6dfb\u52a0 fd \u548c\u76d1\u542c\u4e8b\u4ef6&#xff1b;<\/li>\n<li>EPOLL_CTL_MOD&#xff1a;\u4fee\u6539\u5df2\u76d1\u542c fd \u7684\u4e8b\u4ef6&#xff1b;<\/li>\n<li>EPOLL_CTL_DEL&#xff1a;\u4ece\u4e8b\u4ef6\u8868\u4e2d\u5220\u9664 fd&#xff08;\u5ba2\u6237\u7aef\u65ad\u5f00\u65f6&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b&#xff1a;&#xff08;\u6dfb\u52a0\u670d\u52a1\u5668fd\u76d1\u542c&#xff09;<\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">epoll_event<\/span> ev<span class=\"token punctuation\">;<\/span><br \/>\nev<span class=\"token punctuation\">.<\/span>events <span class=\"token operator\">&#061;<\/span> EPOLLIN<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u76d1\u542c\u8bfb\u4e8b\u4ef6&#xff08;\u65b0\u8fde\u63a5&#xff09;<\/span><br \/>\nev<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">.<\/span>fd <span class=\"token operator\">&#061;<\/span> server_fd<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u5b58\u50a8\u670d\u52a1\u5668fd<\/span><br \/>\n<span class=\"token comment\">\/\/ \u628aserver_fd\u6dfb\u52a0\u5230epoll\u4e8b\u4ef6\u8868<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">epoll_ctl<\/span><span class=\"token punctuation\">(<\/span>epfd<span class=\"token punctuation\">,<\/span> EPOLL_CTL_ADD<span class=\"token punctuation\">,<\/span> server_fd<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>ev<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;epoll_ctl add server_fd failed&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span>EXIT_FAILURE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<ul>\n<li>epoll_wait&#xff1a;\u963b\u585e\u7b49\u5f85\u4e8b\u4ef6\u53d1\u751f<\/li>\n<\/ul>\n<p><span class=\"token comment\">\/\/ epfd&#xff1a;epoll\u5b9e\u4f8b\u7684fd<\/span><br \/>\n<span class=\"token comment\">\/\/ events&#xff1a;\u8f93\u51fa\u53c2\u6570&#xff0c;\u5b58\u50a8\u6709\u4e8b\u4ef6\u7684fd\u6570\u7ec4&#xff08;\u7528\u6237\u6001\u5206\u914d&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/ maxevents&#xff1a;events\u6570\u7ec4\u7684\u6700\u5927\u957f\u5ea6&#xff08;\u6700\u591a\u5904\u7406\u591a\u5c11\u4e2a\u4e8b\u4ef6&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/ timeout&#xff1a;\u8d85\u65f6\u65f6\u95f4&#xff08;\u6beb\u79d2&#xff09;&#xff0c;-1&#061;\u6c38\u4e45\u963b\u585e&#xff0c;0&#061;\u975e\u963b\u585e<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8fd4\u56de\u503c&#xff1a;\u6210\u529f&#061;\u6709\u4e8b\u4ef6\u7684fd\u6570\u91cf&#xff1b;0&#061;\u8d85\u65f6&#xff1b;-1&#061;\u5931\u8d25&#xff08;errno&#061;EINTR\u4e3a\u4fe1\u53f7\u4e2d\u65ad&#xff09;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">epoll_wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> epfd<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">epoll_event<\/span> <span class=\"token operator\">*<\/span>events<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> maxevents<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> timeout<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6838\u5fc3\u7279\u70b9&#xff1a;\u53ea\u8fd4\u56de\u6709\u4e8b\u4ef6\u7684 fd&#xff0c;\u65e0\u9700\u904d\u5386\u6240\u6709 fd&#xff0c;\u8fd9\u662f epoll \u9ad8\u6027\u80fd\u7684\u5173\u952e&#xff1b;<\/p>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">epoll_event<\/span> events<span class=\"token punctuation\">[<\/span><span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6700\u591a\u5904\u74061024\u4e2a\u4e8b\u4ef6<\/span><br \/>\n<span class=\"token comment\">\/\/ \u963b\u585e\u7b49\u5f85\u4e8b\u4ef6<\/span><br \/>\n<span class=\"token keyword\">int<\/span> nfds <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">epoll_wait<\/span><span class=\"token punctuation\">(<\/span>epfd<span class=\"token punctuation\">,<\/span> events<span class=\"token punctuation\">,<\/span> <span class=\"token number\">1024<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>nfds <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>errno <span class=\"token operator\">&#061;&#061;<\/span> EINTR<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">continue<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u4fe1\u53f7\u4e2d\u65ad&#xff0c;\u6b63\u5e38\u91cd\u8bd5<\/span><br \/>\n    <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;epoll_wait failed&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span>EXIT_FAILURE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/ \u4ec5\u904d\u5386\u6709\u4e8b\u4ef6\u7684fd&#xff08;nfds\u4e2a&#xff09;<\/span><br \/>\n<span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> nfds<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> fd <span class=\"token operator\">&#061;<\/span> events<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">.<\/span>fd<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>fd <span class=\"token operator\">&#061;&#061;<\/span> server_fd<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5904\u7406\u65b0\u8fde\u63a5<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5904\u7406\u5ba2\u6237\u7aef\u901a\u4fe1<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194147-699dfefb692f9.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194149-699dfefdc1029.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h5>epoll vs select\/poll<\/h5>\n<p>\u7ed3\u5408\u4f60\u7684 TCP \u670d\u52a1\u5668\u573a\u666f&#xff0c;\u7528\u8868\u683c\u6e05\u6670\u5bf9\u6bd4\u4e09\u8005\u7684\u6838\u5fc3\u5dee\u5f02&#xff1a;<\/p>\n<table>\n<tr>\u7279\u6027selectpollepoll<\/tr>\n<tbody>\n<tr>\n<td align=\"center\">fd \u6570\u91cf\u9650\u5236<\/td>\n<td align=\"center\">\u6709&#xff08;\u9ed8\u8ba4 1024&#xff09;<\/td>\n<td align=\"center\">\u65e0&#xff08;\u53d7\u7cfb\u7edf\u8d44\u6e90\u9650\u5236&#xff09;<\/td>\n<td align=\"center\">\u65e0&#xff08;\u4ec5\u53d7\u7cfb\u7edf\u6700\u5927\u6587\u4ef6\u63cf\u8ff0\u7b26\u9650\u5236&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u6570\u636e\u62f7\u8d1d<\/td>\n<td align=\"center\">\u6bcf\u6b21\u8c03\u7528\u62f7\u8d1d\u6240\u6709 fd<\/td>\n<td align=\"center\">\u6bcf\u6b21\u8c03\u7528\u62f7\u8d1d\u6240\u6709 fd<\/td>\n<td align=\"center\">\u4ec5\u62f7\u8d1d\u4e00\u6b21&#xff08;mmap \u5171\u4eab\u5185\u5b58&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u4e8b\u4ef6\u68c0\u6d4b\u65b9\u5f0f<\/td>\n<td align=\"center\">\u904d\u5386\u6240\u6709 fd&#xff08;O (n)&#xff09;<\/td>\n<td align=\"center\">\u904d\u5386\u6240\u6709 fd&#xff08;O (n)&#xff09;<\/td>\n<td align=\"center\">\u56de\u8c03\u6807\u8bb0\u6709\u4e8b\u4ef6\u7684 fd&#xff08;O (1)&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u4e8b\u4ef6\u8fd4\u56de<\/td>\n<td align=\"center\">\u8fd4\u56de\u6240\u6709 fd&#xff0c;\u9700\u904d\u5386\u7b5b\u9009<\/td>\n<td align=\"center\">\u8fd4\u56de\u6240\u6709 fd&#xff0c;\u9700\u904d\u5386\u7b5b\u9009<\/td>\n<td align=\"center\">\u4ec5\u8fd4\u56de\u6709\u4e8b\u4ef6\u7684 fd&#xff0c;\u76f4\u63a5\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u89e6\u53d1\u6a21\u5f0f<\/td>\n<td align=\"center\">\u4ec5 LT<\/td>\n<td align=\"center\">\u4ec5 LT<\/td>\n<td align=\"center\">LT\/ET&#xff08;\u652f\u6301\u8fb9\u7f18\u89e6\u53d1&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u5185\u5b58\u5f00\u9500<\/td>\n<td align=\"center\">\u968f fd \u6570\u91cf\u7ebf\u6027\u589e\u957f<\/td>\n<td align=\"center\">\u968f fd \u6570\u91cf\u7ebf\u6027\u589e\u957f<\/td>\n<td align=\"center\">\u56fa\u5b9a\u5f00\u9500&#xff08;\u5185\u6838\u4e8b\u4ef6\u8868&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u9ad8\u5e76\u53d1\u6027\u80fd<\/td>\n<td align=\"center\">\u6781\u5dee&#xff08;1 \u4e07 fd \u57fa\u672c\u5361\u6b7b&#xff09;<\/td>\n<td align=\"center\">\u5dee&#xff08;1 \u4e07 fd \u904d\u5386\u6210\u672c\u9ad8&#xff09;<\/td>\n<td align=\"center\">\u6781\u4f73&#xff08;10 \u4e07 &#043; fd \u65e0\u538b\u529b&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">\u8de8\u5e73\u53f0\u652f\u6301<\/td>\n<td align=\"center\">\u5168\u5e73\u53f0&#xff08;Linux\/Windows&#xff09;<\/td>\n<td align=\"center\">\u5927\u90e8\u5206\u5e73\u53f0<\/td>\n<td align=\"center\">\u4ec5 Linux \u5185\u6838 2.6&#043;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>I\/O\u591a\u8def\u590d\u7528<br \/>\nIO\u591a\u8def\u590d\u7528\u4e5f\u79f0\u4e3aIO\u591a\u8def\u8f6c\u63a5&#xff0c;\u5b83\u662f\u4e00\u79cd\u7f51\u7edc\u901a\u4fe1\u7684\u624b\u6bb5&#xff08;\u673a\u5236&#xff09;&#xff0c;\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u540c\u65f6\u76d1\u6d4b\u591a\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u5e76\u4e14\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u963b\u585e\u7684&#xff0c;\u4e00\u65e6\u68c0\u6d4b\u5230\u6709\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea&#xff08; \u53ef\u4ee5\u8bfb\u6570\u636e\u6216\u8005\u53ef\u4ee5\u5199\u6570\u636e&#xff09;\u7a0b\u5e8f\u7684\u963b\u585e\u5c31\u4f1a\u88ab\u89e3\u9664&#xff0c;\u4e4b\u540e\u5c31\u53ef\u4ee5\u57fa\u4e8e\u8fd9\u4e9b&#xff08;\u4e00\u4e2a\u6216\u591a\u4e2a&#xff09;\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u901a\u4fe1\u4e86\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u5728\u5355\u7ebf\u7a0b\/\u8fdb\u7a0b\u7684\u573a\u666f\u4e0b\u4e5f\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u7aef\u5b9e\u73b0\u5e76\u53d1\u3002\u5e38<\/p>\n","protected":false},"author":2,"featured_media":77635,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,43,305,78],"topic":[],"class_list":["post-77641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-43","tag-305","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09 - \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\/77641.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"I\/O\u591a\u8def\u590d\u7528 IO\u591a\u8def\u590d\u7528\u4e5f\u79f0\u4e3aIO\u591a\u8def\u8f6c\u63a5&#xff0c;\u5b83\u662f\u4e00\u79cd\u7f51\u7edc\u901a\u4fe1\u7684\u624b\u6bb5&#xff08;\u673a\u5236&#xff09;&#xff0c;\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u540c\u65f6\u76d1\u6d4b\u591a\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u5e76\u4e14\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u963b\u585e\u7684&#xff0c;\u4e00\u65e6\u68c0\u6d4b\u5230\u6709\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea&#xff08; \u53ef\u4ee5\u8bfb\u6570\u636e\u6216\u8005\u53ef\u4ee5\u5199\u6570\u636e&#xff09;\u7a0b\u5e8f\u7684\u963b\u585e\u5c31\u4f1a\u88ab\u89e3\u9664&#xff0c;\u4e4b\u540e\u5c31\u53ef\u4ee5\u57fa\u4e8e\u8fd9\u4e9b&#xff08;\u4e00\u4e2a\u6216\u591a\u4e2a&#xff09;\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u901a\u4fe1\u4e86\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u5728\u5355\u7ebf\u7a0b\/\u8fdb\u7a0b\u7684\u573a\u666f\u4e0b\u4e5f\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u7aef\u5b9e\u73b0\u5e76\u53d1\u3002\u5e38\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/77641.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-24T19:41:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194144-699dfef8b21ca.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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77641.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/77641.html\",\"name\":\"\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-24T19:41:53+00:00\",\"dateModified\":\"2026-02-24T19:41:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/77641.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/77641.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77641.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09\"}]},{\"@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++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09 - \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\/77641.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"I\/O\u591a\u8def\u590d\u7528 IO\u591a\u8def\u590d\u7528\u4e5f\u79f0\u4e3aIO\u591a\u8def\u8f6c\u63a5&#xff0c;\u5b83\u662f\u4e00\u79cd\u7f51\u7edc\u901a\u4fe1\u7684\u624b\u6bb5&#xff08;\u673a\u5236&#xff09;&#xff0c;\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u540c\u65f6\u76d1\u6d4b\u591a\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u5e76\u4e14\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u963b\u585e\u7684&#xff0c;\u4e00\u65e6\u68c0\u6d4b\u5230\u6709\u6587\u4ef6\u63cf\u8ff0\u7b26\u5c31\u7eea&#xff08; \u53ef\u4ee5\u8bfb\u6570\u636e\u6216\u8005\u53ef\u4ee5\u5199\u6570\u636e&#xff09;\u7a0b\u5e8f\u7684\u963b\u585e\u5c31\u4f1a\u88ab\u89e3\u9664&#xff0c;\u4e4b\u540e\u5c31\u53ef\u4ee5\u57fa\u4e8e\u8fd9\u4e9b&#xff08;\u4e00\u4e2a\u6216\u591a\u4e2a&#xff09;\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u8fdb\u884c\u901a\u4fe1\u4e86\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u5728\u5355\u7ebf\u7a0b\/\u8fdb\u7a0b\u7684\u573a\u666f\u4e0b\u4e5f\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u7aef\u5b9e\u73b0\u5e76\u53d1\u3002\u5e38","og_url":"https:\/\/www.wsisp.com\/helps\/77641.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-24T19:41:53+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260224194144-699dfef8b21ca.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/77641.html","url":"https:\/\/www.wsisp.com\/helps\/77641.html","name":"\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-24T19:41:53+00:00","dateModified":"2026-02-24T19:41:53+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/77641.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/77641.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/77641.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++ \u7f51\u7edc\u7f16\u7a0b\u3011\u4e00\u7bc7\u6587\u7ae0\u641e\u61c2I\/O\u591a\u8def\u590d\u7528\uff08select\u3001poll\u3001epoll\uff09"}]},{"@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\/77641","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=77641"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/77641\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/77635"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=77641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=77641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=77641"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=77641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}