{"id":115,"date":"2015-03-25T05:05:52","date_gmt":"2015-03-25T05:05:52","guid":{"rendered":""},"modified":"2015-03-25T05:05:52","modified_gmt":"2015-03-25T05:05:52","slug":"","status":"publish","type":"post","link":"http:\/\/weizn.net\/?p=115","title":{"rendered":"[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b"},"content":{"rendered":"<p>\u4e00\u3001\u4ecb\u7ecd<\/p>\n<p>&nbsp;&nbsp;&nbsp; epoll\u662fLinux(\u5185\u6838\u7248\u672c2.6\u53ca\u4ee5\u4e0a\u652f\u6301)\u4e0b\u591a\u8def\u590d\u7528IO\u63a5\u53e3select\/poll\u7684\u589e\u5f3a\u7248\u672c\uff0c\u5b83\u80fd\u663e\u8457\u63d0\u9ad8\u7a0b\u5e8f\u5728\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u4e2d\u53ea\u6709\u5c11\u91cf\u6d3b\u8dc3\u7684\u60c5\u51b5\u4e0b\u7684\u7cfb\u7edfCPU\u5229\u7528\u7387\uff0c\u56e0\u4e3a\u5b83\u4f1a\u590d\u7528\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u6765\u4f20\u9012\u7ed3\u679c\u800c\u4e0d\u7528\u8feb\u4f7f\u5f00\u53d1\u8005\u6bcf\u6b21\u7b49\u5f85\u4e8b\u4ef6\u4e4b\u524d\u90fd\u5fc5\u987b\u91cd\u65b0\u51c6\u5907\u8981\u88ab\u4fa6\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\uff0c\u53e6\u4e00\u70b9\u539f\u56e0\u5c31\u662f\u83b7\u53d6\u4e8b\u4ef6\u7684\u65f6\u5019\uff0c\u5b83\u65e0\u987b\u904d\u5386\u6574\u4e2a\u88ab\u4fa6\u542c\u7684\u63cf\u8ff0\u7b26\u96c6\uff0c\u53ea\u8981\u904d\u5386\u90a3\u4e9b\u88ab\u5185\u6838IO\u4e8b\u4ef6\u5f02\u6b65\u5524\u9192\u800c\u52a0\u5165Ready\u961f\u5217\u7684\u63cf\u8ff0\u7b26\u96c6\u5408\u5c31\u884c\u4e86\u3002<\/p>\n<p>&nbsp;&nbsp;&nbsp; Linux\u4e0bselect \u6a21\u578b\u548cepoll\u6a21\u578b\u533a\u522b\uff1a<\/p>\n<p>&nbsp;&nbsp;&nbsp; \u5047\u8bbe\u4f60\u5728\u5927\u5b66\u8bfb\u4e66\uff0c\u4f4f\u7684\u5bbf\u820d\u697c\u6709\u5f88\u591a\u95f4\u623f\u95f4\uff0c\u4f60\u7684\u670b\u53cb\u8981\u6765\u627e\u4f60\u3002 select\u7248\u5bbf\u7ba1\u5927\u5988\u5c31\u4f1a\u5e26\u7740\u4f60\u7684\u670b\u53cb\u6328\u4e2a\u623f\u95f4\u53bb\u627e\uff0c\u76f4\u5230\u627e\u5230\u4f60\u4e3a\u6b62\u3002\u800c epoll\u7248\u5bbf\u7ba1\u5927\u5988\u4f1a\u5148\u8bb0\u4e0b\u6bcf\u4f4d\u540c\u5b66\u7684\u623f\u95f4\u53f7\uff0c\u4f60\u7684\u670b\u53cb\u6765\u65f6\uff0c\u53ea\u9700\u544a\u8bc9\u4f60\u7684\u670b\u53cb\u4f60\u4f4f\u5728\u54ea\u4e2a\u623f\u95f4\u5373\u53ef\uff0c\u4e0d\u7528\u4eb2\u81ea\u5e26\u7740\u4f60\u7684\u670b\u53cb\u6ee1\u5927\u697c\u627e\u4eba\u3002\u5982\u679c\u6765\u4e86 10000\u4e2a\u4eba\uff0c\u90fd\u8981\u627e\u81ea\u5df1\u4f4f\u8fd9\u680b\u697c\u7684\u540c\u5b66\u65f6\uff0c select\u7248\u548cepoll \u7248\u5bbf\u7ba1\u5927\u5988\uff0c\u8c01\u7684\u6548\u7387\u66f4\u9ad8\uff0c\u4e0d\u8a00\u81ea\u660e\u3002\u540c\u7406\uff0c\u5728\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u4e2d\uff0c\u8f6e\u8be2 I\/O\u662f\u6700\u8017\u65f6\u95f4\u7684\u64cd\u4f5c\u4e4b\u4e00\uff0c select\u548cepoll \u7684\u6027\u80fd\u8c01\u7684\u6027\u80fd\u66f4\u9ad8\uff0c\u540c\u6837\u5341\u5206\u660e\u4e86\u3002<\/p>\n<p>\n\t\u4e8c\u3001\u8be6\u89e3\n<\/p>\n<p>\n\t\n<\/p>\n<p>epoll\u7684\u63a5\u53e3\u975e\u5e38\u7b80\u5355\uff0c\u4e00\u5171\u5c31\u4e09\u4e2a\u51fd\u6570\uff1a<br \/>\n1. int epoll_create(int size);<br \/>\n&nbsp;&nbsp;&nbsp; \u521b\u5efa\u4e00\u4e2aepoll\u7684\u53e5\u67c4\uff0csize\u7528\u6765\u544a\u8bc9\u5185\u6838\u8fd9\u4e2a\u76d1\u542c\u7684\u6570\u76ee\u4e00\u5171\u6709\u591a\u5927\u3002\u8fd9\u4e2a\u53c2\u6570\u4e0d\u540c\u4e8eselect()\u4e2d\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u7ed9\u51fa\u6700\u5927\u76d1\u542c\u7684fd+1\u7684\u503c\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5f53\u521b\u5efa\u597depoll\u53e5\u67c4\u540e\uff0c\u5b83\u5c31\u662f\u4f1a\u5360\u7528\u4e00\u4e2afd\u503c\uff0c\u5728linux\u4e0b\u5982\u679c\u67e5\u770b\/proc\/\u8fdb\u7a0bid\/fd\/\uff0c\u662f\u80fd\u591f\u770b\u5230\u8fd9\u4e2afd\u7684\uff0c\u6240\u4ee5\u5728\u4f7f\u7528\u5b8cepoll\u540e\uff0c\u5fc5\u987b\u8c03\u7528close()\u5173\u95ed\uff0c\u5426\u5219\u53ef\u80fd\u5bfc\u81f4fd\u88ab\u8017\u5c3d\u3002<\/p>\n<p>2. int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event);<br \/>\n&nbsp;&nbsp; epoll\u7684\u4e8b\u4ef6\u6ce8\u518c\u51fd\u6570\uff0c\u5373\u6ce8\u518c\u8981\u76d1\u542c\u7684\u4e8b\u4ef6\u7c7b\u578b\u3002<br \/>\n&nbsp;&nbsp; \u7b2c\u4e00\u4e2a\u53c2\u6570\u662fepoll_create()\u7684\u8fd4\u56de\u503c\uff0c<br \/>\n&nbsp;&nbsp; \u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u52a8\u4f5c\uff0c\u7528\u4e09\u4e2a\u5b8f\u6765\u8868\u793a\uff1a<br \/>\n&nbsp;&nbsp; EPOLL_CTL_ADD\uff1a\u6ce8\u518c\u65b0\u7684fd\u5230epfd\u4e2d\uff1b<br \/>\n&nbsp;&nbsp; EPOLL_CTL_MOD\uff1a\u4fee\u6539\u5df2\u7ecf\u6ce8\u518c\u7684fd\u7684\u76d1\u542c\u4e8b\u4ef6\uff1b<br \/>\n&nbsp;&nbsp; EPOLL_CTL_DEL\uff1a\u4eceepfd\u4e2d\u5220\u9664\u4e00\u4e2afd\uff1b<br \/>\n&nbsp;&nbsp; \u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u9700\u8981\u76d1\u542c\u7684fd\uff0c<br \/>\n&nbsp;&nbsp; \u7b2c\u56db\u4e2a\u53c2\u6570\u662f\u544a\u8bc9\u5185\u6838\u9700\u8981\u76d1\u542c\u4ec0\u4e48\u4e8b\uff0cstruct epoll_event\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<p>struct epoll_event {<br \/>\n&nbsp; __uint32_t events;&nbsp; epoll_data_t data;&nbsp; };<\/p>\n<p>typedef union epoll_data { void *ptr; int fd;<br \/>\n__uint32_t u32;<br \/>\n__uint64_t u64;<br \/>\n} epoll_data_t; <\/p>\n<p>&nbsp;&nbsp; events\u53ef\u4ee5\u662f\u4ee5\u4e0b\u51e0\u4e2a\u5b8f\u7684\u96c6\u5408\uff1a<\/p>\n<p>&nbsp;&nbsp; EPOLLIN \uff1a \u8868\u793a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u53ef\u4ee5\u8bfb\uff08\u5305\u62ec\u5bf9\u7aefSOCKET\u6b63\u5e38\u5173\u95ed\uff09\uff1b<br \/>\n&nbsp;&nbsp; EPOLLOUT\uff1a \u8868\u793a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u53ef\u4ee5\u5199\uff1b<br \/>\n&nbsp;&nbsp; EPOLLPRI\uff1a \u8868\u793a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6709\u7d27\u6025\u7684\u6570\u636e\u53ef\u8bfb\uff08\u8fd9\u91cc\u5e94\u8be5\u8868\u793a\u6709\u5e26\u5916\u6570\u636e\u5230\u6765\uff09\uff1b<br \/>\n&nbsp;&nbsp; EPOLLERR\uff1a \u8868\u793a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u53d1\u751f\u9519\u8bef\uff1b<br \/>\n&nbsp;&nbsp; EPOLLHUP\uff1a \u8868\u793a\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u88ab\u6302\u65ad\uff1b<br \/>\n&nbsp;&nbsp; EPOLLET\uff1a \u5c06 EPOLL\u8bbe\u4e3a\u8fb9\u7f18\u89e6\u53d1(Edge Triggered)\u6a21\u5f0f\uff08\u9ed8\u8ba4\u4e3a\u6c34\u5e73\u89e6\u53d1\uff09\uff0c\u8fd9\u662f\u76f8\u5bf9\u4e8e\u6c34\u5e73\u89e6\u53d1(Level Triggered)\u6765\u8bf4\u7684\u3002<br \/>\n&nbsp;&nbsp; EPOLLONESHOT\uff1a \u53ea\u76d1\u542c\u4e00\u6b21\u4e8b\u4ef6\uff0c\u5f53\u76d1\u542c\u5b8c\u8fd9\u6b21\u4e8b\u4ef6\u4e4b\u540e\uff0c\u5982\u679c\u8fd8\u9700\u8981\u7ee7\u7eed\u76d1\u542c\u8fd9\u4e2asocket\u7684\u8bdd\uff0c\u9700\u8981\u518d\u6b21\u628a\u8fd9\u4e2asocket\u52a0\u5165\u5230EPOLL\u961f\u5217\u91cc<\/p>\n<p>3. int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);<br \/>\n&nbsp;&nbsp; \u7b49\u5f85\u4e8b\u4ef6\u7684\u4ea7\u751f\u3002\u53c2\u6570events \u7528\u6765\u4ece\u5185\u6838\u5f97\u5230\u4e8b\u4ef6\u7684\u96c6\u5408\uff0cmaxevents \u544a\u4e4b\u5185\u6838\u8fd9\u4e2aevents \u6709\u591a\u5927\uff0c\u8fd9\u4e2amaxevents \u7684\u503c\u4e0d\u80fd\u5927\u4e8e\u521b\u5efaepoll_create()\u65f6\u7684size\uff0c\u53c2\u6570timeout\u662f\u8d85\u65f6\u65f6\u95f4\uff08\u6beb\u79d2\uff0c0\u4f1a\u7acb\u5373\u8fd4\u56de\uff0c-1\u5c06\u4e0d\u786e\u5b9a\uff0c\u4e5f\u6709\u8bf4\u6cd5\u8bf4\u662f\u6c38\u4e45\u963b\u585e\uff09\u3002\u8be5\u51fd\u6570\u8fd4\u56de\u9700\u8981\u5904\u7406\u7684\u4e8b\u4ef6\u6570\u76ee\uff0c\u5982\u8fd4\u56de0\u8868\u793a\u5df2\u8d85\u65f6\u3002<\/p>\n<p>4. EPOLL\u4e8b\u4ef6\u6709\u4e24\u79cd\u6a21\u578b\uff1a<\/p>\n<p>Edge Triggered (ET) \u8fb9\u7f18\u89e6\u53d1 \u53ea\u6709\u6570\u636e\u5230\u6765\uff0c\u624d\u89e6\u53d1\uff0c\u4e0d\u7ba1\u7f13\u5b58\u533a\u4e2d\u662f\u5426\u8fd8\u6709\u6570\u636e\u3002<br \/>\nLevel Triggered (LT) \u6c34\u5e73\u89e6\u53d1 \u53ea\u8981\u6709\u6570\u636e\u90fd\u4f1a\u89e6\u53d1\u3002<\/p>\n<p>\u5047\u5982\u6709\u8fd9\u6837\u4e00\u4e2a\u4f8b\u5b50\uff1a<br \/>\n1. \u6211\u4eec\u5df2\u7ecf\u628a\u4e00\u4e2a\u7528\u6765\u4ece\u7ba1\u9053\u4e2d\u8bfb\u53d6\u6570\u636e\u7684\u6587\u4ef6\u53e5\u67c4(RFD)\u6dfb\u52a0\u5230epoll\u63cf\u8ff0\u7b26<br \/>\n2. \u8fd9\u4e2a\u65f6\u5019\u4ece\u7ba1\u9053\u7684\u53e6\u4e00\u7aef\u88ab\u5199\u5165\u4e862KB\u7684\u6570\u636e<br \/>\n3. \u8c03\u7528epoll_wait(2)\uff0c\u5e76\u4e14\u5b83\u4f1a\u8fd4\u56deRFD\uff0c\u8bf4\u660e\u5b83\u5df2\u7ecf\u51c6\u5907\u597d\u8bfb\u53d6\u64cd\u4f5c<br \/>\n4. \u7136\u540e\u6211\u4eec\u8bfb\u53d6\u4e861KB\u7684\u6570\u636e<br \/>\n5. \u8c03\u7528epoll_wait(2)&#8230;&#8230;<br \/>\nEdge Triggered \u5de5\u4f5c\u6a21\u5f0f\uff1a<br \/>\n\u5982\u679c\u6211\u4eec\u5728\u7b2c1\u6b65\u5c06RFD\u6dfb\u52a0\u5230epoll\u63cf\u8ff0\u7b26\u7684\u65f6\u5019\u4f7f\u7528\u4e86EPOLLET\u6807\u5fd7\uff0c\u90a3\u4e48\u5728\u7b2c5\u6b65\u8c03\u7528epoll_wait(2)\u4e4b\u540e\u5c06\u6709\u53ef\u80fd\u4f1a\u6302\u8d77\uff0c\u56e0\u4e3a\u5269\u4f59\u7684\u6570\u636e\u8fd8\u5b58\u5728\u4e8e\u6587\u4ef6\u7684\u8f93\u5165\u7f13\u51b2\u533a\u5185\uff0c\u800c\u4e14\u6570\u636e\u53d1\u51fa\u7aef\u8fd8\u5728\u7b49\u5f85\u4e00\u4e2a\u9488\u5bf9\u5df2\u7ecf\u53d1\u51fa\u6570\u636e\u7684\u53cd\u9988\u4fe1\u606f\u3002\u53ea\u6709\u5728\u76d1\u89c6\u7684\u6587\u4ef6\u53e5\u67c4\u4e0a\u53d1\u751f\u4e86\u67d0\u4e2a\u4e8b\u4ef6\u7684\u65f6\u5019 ET \u5de5\u4f5c\u6a21\u5f0f\u624d\u4f1a\u6c47\u62a5\u4e8b\u4ef6\u3002\u56e0\u6b64\u5728\u7b2c5\u6b65\u7684\u65f6\u5019\uff0c\u8c03\u7528\u8005\u53ef\u80fd\u4f1a\u653e\u5f03\u7b49\u5f85\u4ecd\u5728\u5b58\u5728\u4e8e\u6587\u4ef6\u8f93\u5165\u7f13\u51b2\u533a\u5185\u7684\u5269\u4f59\u6570\u636e\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u4f1a\u6709\u4e00\u4e2a\u4e8b\u4ef6\u4ea7\u751f\u5728RFD\u53e5\u67c4\u4e0a\uff0c\u56e0\u4e3a\u5728\u7b2c2\u6b65\u6267\u884c\u4e86\u4e00\u4e2a\u5199\u64cd\u4f5c\uff0c\u7136\u540e\uff0c\u4e8b\u4ef6\u5c06\u4f1a\u5728\u7b2c3\u6b65\u88ab\u9500\u6bc1\u3002\u56e0\u4e3a\u7b2c4 \u6b65\u7684\u8bfb\u53d6\u64cd\u4f5c\u6ca1\u6709\u8bfb\u7a7a\u6587\u4ef6\u8f93\u5165\u7f13\u51b2\u533a\u5185\u7684\u6570\u636e\uff0c\u56e0\u6b64\u6211\u4eec\u5728\u7b2c5 \u6b65\u8c03\u7528epoll_wait(2)\u5b8c\u6210\u540e\uff0c\u662f\u5426\u6302\u8d77\u662f\u4e0d\u786e\u5b9a\u7684\u3002epoll\u5de5\u4f5c\u5728ET\u6a21\u5f0f\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u4f7f\u7528\u975e\u963b\u585e\u5957\u63a5\u53e3\uff0c\u4ee5\u907f\u514d\u7531\u4e8e\u4e00\u4e2a\u6587\u4ef6\u53e5\u67c4\u7684\u963b\u585e\u8bfb\/\u963b\u585e\u5199\u64cd\u4f5c\u628a\u5904\u7406\u591a\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u4efb\u52a1\u997f\u6b7b\u3002\u6700\u597d\u4ee5\u4e0b\u9762\u7684\u65b9\u5f0f\u8c03\u7528ET\u6a21\u5f0f\u7684epoll\u63a5\u53e3\uff0c\u5728\u540e\u9762\u4f1a\u4ecb\u7ecd\u907f\u514d\u53ef\u80fd\u7684\u7f3a\u9677\u3002<\/p>\n<p>i \u57fa\u4e8e\u975e\u963b\u585e\u6587\u4ef6\u53e5\u67c4<br \/>\nii \u53ea\u6709\u5f53read(2)\u6216\u8005write(2)\u8fd4\u56deEAGAIN\u65f6\u624d\u9700\u8981\u6302\u8d77\uff0c\u7b49\u5f85\u3002\u4f46\u8fd9\u5e76\u4e0d\u662f\u8bf4\u6bcf\u6b21read()\u65f6\u90fd\u9700\u8981\u5faa\u73af\u8bfb\uff0c\u76f4\u5230\u8bfb\u5230\u4ea7\u751f\u4e00\u4e2aEAGAIN \u624d\u8ba4\u4e3a\u6b64\u6b21\u4e8b\u4ef6\u5904\u7406\u5b8c\u6210\uff0c\u5f53read()\u8fd4\u56de\u7684\u8bfb\u5230\u7684\u6570\u636e\u957f\u5ea6\u5c0f\u4e8e\u8bf7\u6c42\u7684\u6570\u636e\u957f\u5ea6\u65f6\uff0c\u5c31\u53ef\u4ee5\u786e\u5b9a\u6b64\u65f6\u7f13\u51b2\u4e2d\u5df2\u6ca1\u6709\u6570\u636e\u4e86\uff0c\u4e5f\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u6b64\u4e8b\u8bfb\u4e8b\u4ef6\u5df2\u5904\u7406\u5b8c\u6210\u3002Level Triggered \u5de5\u4f5c\u6a21\u5f0f\u76f8\u53cd\u7684\uff0c\u4ee5LT\u65b9\u5f0f\u8c03\u7528epoll\u63a5\u53e3\u7684\u65f6\u5019\uff0c\u5b83\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u901f\u5ea6\u6bd4\u8f83\u5feb\u7684poll(2)\uff0c\u5e76\u4e14\u65e0\u8bba\u540e\u9762\u7684\u6570\u636e\u662f\u5426\u88ab\u4f7f\u7528\uff0c\u56e0\u6b64\u4ed6\u4eec\u5177\u6709\u540c\u6837\u7684\u804c\u80fd\u3002\u56e0\u4e3a\u5373\u4f7f\u4f7f\u7528ET\u6a21\u5f0f\u7684epoll\uff0c\u5728\u6536\u5230\u591a\u4e2achunk \u7684\u6570\u636e\u7684\u65f6\u5019\u4ecd\u7136\u4f1a\u4ea7\u751f\u591a\u4e2a\u4e8b\u4ef6\u3002\u8c03\u7528\u8005\u53ef\u4ee5\u8bbe\u5b9aEPOLLONESHOT\u6807\u5fd7\uff0c\u5728 epoll_wait(2)\u6536\u5230\u4e8b\u4ef6\u540eepoll\u4f1a\u4e0e\u4e8b\u4ef6\u5173\u8054\u7684\u6587\u4ef6\u53e5\u67c4\u4eceepoll\u63cf\u8ff0\u7b26\u4e2d\u7981\u6b62\u6389\u3002\u56e0\u6b64\u5f53EPOLLONESHOT\u8bbe\u5b9a\u540e\uff0c\u4f7f\u7528\u5e26\u6709 EPOLL_CTL_MOD\u6807\u5fd7\u7684epoll_ctl(2)\u5904\u7406\u6587\u4ef6\u53e5\u67c4\u5c31\u6210\u4e3a\u8c03\u7528\u8005\u5fc5\u987b\u4f5c\u7684\u4e8b\u60c5\u3002<\/p>\n<p>\u7136\u540e\u8be6\u7ec6\u89e3\u91caET, LT:<br \/>\nLT(level triggered)\u662f\u7f3a\u7701\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u5e76\u4e14\u540c\u65f6\u652f\u6301block \u548cno-blocksocket.\u5728\u8fd9\u79cd\u505a\u6cd5\u4e2d\uff0c\u5185\u6838\u544a\u8bc9\u4f60\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u5426\u5c31\u7eea\u4e86\uff0c\u7136\u540e\u4f60\u53ef\u4ee5\u5bf9\u8fd9\u4e2a\u5c31\u7eea\u7684fd\u8fdb\u884cIO\u64cd\u4f5c\u3002\u5982\u679c\u4f60\u4e0d\u4f5c\u4efb\u4f55\u64cd\u4f5c\uff0c\u5185\u6838\u8fd8\u662f\u4f1a\u7ee7\u7eed\u901a\u77e5\u4f60\u7684\uff0c\u6240\u4ee5\uff0c\u8fd9\u79cd\u6a21\u5f0f\u7f16\u7a0b\u51fa\u9519\u8bef\u53ef\u80fd\u6027\u8981\u5c0f\u4e00\u70b9\u3002\u4f20\u7edf\u7684select\/poll\u90fd\u662f\u8fd9\u79cd\u6a21\u578b\u7684\u4ee3\u8868\uff0e<\/p>\n<p>ET(edge-triggered)\u662f\u9ad8\u901f\u5de5\u4f5c\u65b9\u5f0f\uff0c\u53ea\u652f\u6301no-block socket\u3002\u5728\u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0c\u5f53\u63cf\u8ff0\u7b26\u4ece\u672a\u5c31\u7eea\u53d8\u4e3a\u5c31\u7eea\u65f6\uff0c\u5185\u6838\u901a\u8fc7epoll\u544a\u8bc9\u4f60\u3002\u7136\u540e\u5b83\u4f1a\u5047\u8bbe\u4f60\u77e5\u9053\u6587\u4ef6\u63cf\u8ff0\u7b26\u5df2\u7ecf\u5c31\u7eea\uff0c\u5e76\u4e14\u4e0d\u4f1a\u518d\u4e3a\u90a3\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u53d1\u9001\u66f4\u591a\u7684\u5c31\u7eea\u901a\u77e5\uff0c\u76f4\u5230\u4f60\u505a\u4e86\u67d0\u4e9b\u64cd\u4f5c\u5bfc\u81f4\u90a3\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0d\u518d\u4e3a\u5c31\u7eea\u72b6\u6001\u4e86(\u6bd4\u5982\uff0c\u4f60\u5728\u53d1\u9001\uff0c\u63a5\u6536\u6216\u8005\u63a5\u6536\u8bf7\u6c42\uff0c\u6216\u8005\u53d1\u9001\u63a5\u6536\u7684\u6570\u636e\u5c11\u4e8e\u4e00\u5b9a\u91cf\u65f6\u5bfc\u81f4\u4e86\u4e00\u4e2aEWOULDBLOCK \u9519\u8bef\uff09\u3002\u4f46\u662f\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u4e00\u76f4\u4e0d\u5bf9\u8fd9\u4e2afd\u4f5cIO\u64cd\u4f5c(\u4ece\u800c\u5bfc\u81f4\u5b83\u518d\u6b21\u53d8\u6210\u672a\u5c31\u7eea)\uff0c\u5185\u6838\u4e0d\u4f1a\u53d1\u9001\u66f4\u591a\u7684\u901a\u77e5(only once),\u4e0d\u8fc7\u5728TCP\u534f\u8bae\u4e2d\uff0cET\u6a21\u5f0f\u7684\u52a0\u901f\u6548\u7528\u4ecd\u9700\u8981\u66f4\u591a\u7684benchmark\u786e\u8ba4\uff08\u8fd9\u53e5\u8bdd\u4e0d\u7406\u89e3\uff09\u3002<br \/>\n\u5728\u8bb8\u591a\u6d4b\u8bd5\u4e2d\u6211\u4eec\u4f1a\u770b\u5230\u5982\u679c\u6ca1\u6709\u5927\u91cf\u7684idle -connection \u6216\u8005deadconnection\uff0cepoll \u7684\u6548\u7387\u5e76\u4e0d\u4f1a\u6bd4select\/poll \u9ad8\u5f88\u591a\uff0c\u4f46\u662f\u5f53\u6211\u4eec\u9047\u5230\u5927\u91cf\u7684idleconnection(\u4f8b\u5982WAN \u73af\u5883\u4e2d\u5b58\u5728\u5927\u91cf\u7684\u6162\u901f\u8fde\u63a5)\uff0c\u5c31\u4f1a\u53d1\u73b0epoll \u7684\u6548\u7387\u5927\u5927\u9ad8\u4e8eselect\/poll\u3002\uff08\u672a\u6d4b\u8bd5\uff09<br \/>\n\u53e6\u5916\uff0c\u5f53\u4f7f\u7528epoll\u7684ET\u6a21\u578b\u6765\u5de5\u4f5c\u65f6\uff0c\u5f53\u4ea7\u751f\u4e86\u4e00\u4e2aEPOLLIN\u4e8b\u4ef6\u540e\uff0c\u8bfb\u6570\u636e\u7684\u65f6\u5019\u9700\u8981\u8003\u8651\u7684\u662f\u5f53recv()\u8fd4\u56de\u7684\u5927\u5c0f\u5982\u679c\u7b49\u4e8e\u8bf7\u6c42\u7684\u5927\u5c0f\uff0c\u90a3\u4e48\u5f88\u6709\u53ef\u80fd\u662f\u7f13\u51b2\u533a\u8fd8\u6709\u6570\u636e\u672a\u8bfb\u5b8c\uff0c\u4e5f\u610f\u5473\u7740\u8be5\u6b21\u4e8b\u4ef6\u8fd8\u6ca1\u6709\u5904\u7406\u5b8c\uff0c\u6240\u4ee5\u8fd8\u9700\u8981\u518d\u6b21\u8bfb\u53d6\u3002<\/p>\n<p>\u8fd8\u6709\uff0c\u5047\u5982\u53d1\u9001\u7aef\u6d41\u91cf\u5927\u4e8e\u63a5\u6536\u7aef\u7684\u6d41\u91cf(\u610f\u601d\u662fepoll\u6240\u5728\u7684\u7a0b\u5e8f\u8bfb\u6bd4\u8f6c\u53d1\u7684socket\u8981\u5feb),\u7531\u4e8e\u662f\u975e\u963b\u585e\u7684socket,\u90a3\u4e48send()\u51fd\u6570\u867d\u7136\u8fd4\u56de,\u4f46\u5b9e\u9645\u7f13\u51b2\u533a\u7684\u6570\u636e\u5e76\u672a\u771f\u6b63\u53d1\u7ed9\u63a5\u6536\u7aef,\u8fd9\u6837\u4e0d\u65ad\u7684\u8bfb\u548c\u53d1\uff0c\u5f53\u7f13\u51b2\u533a\u6ee1\u540e\u4f1a\u4ea7\u751fEAGAIN\u9519\u8bef(\u53c2\u8003man send),\u540c\u65f6,\u4e0d\u7406\u4f1a\u8fd9\u6b21\u8bf7\u6c42\u53d1\u9001\u7684\u6570\u636e.\u6240\u4ee5,\u9700\u8981\u5c01\u88c5socket_send()\u7684\u51fd\u6570\u7528\u6765\u5904\u7406\u8fd9\u79cd\u60c5\u51b5,\u8be5\u51fd\u6570\u4f1a\u5c3d\u91cf\u5c06\u6570\u636e\u5199\u5b8c\u518d\u8fd4\u56de\uff0c\u8fd4\u56de-1 \u8868\u793a\u51fa\u9519\u3002\u5728socket_send()\u5185\u90e8,\u5f53\u5199\u7f13\u51b2\u5df2\u6ee1(send()\u8fd4\u56de-1,\u4e14errno\u4e3aEAGAIN),\u90a3\u4e48\u4f1a\u7b49\u5f85\u540e\u518d\u91cd\u8bd5.\u8fd9\u79cd\u65b9\u5f0f\u5e76\u4e0d\u5f88\u5b8c\u7f8e,\u5728\u7406\u8bba\u4e0a\u53ef\u80fd\u4f1a\u957f\u65f6\u95f4\u7684\u963b\u585e\u5728socket_send()\u5185\u90e8,\u4f46\u6682\u6ca1\u6709\u66f4\u597d\u7684\u529e\u6cd5\u3002<\/p>\n<p>\/* \u5b9e\u73b0\u529f\u80fd\uff1a\u901a\u8fc7epoll, \u5904\u7406\u591a\u4e2asocket<br \/>\n&nbsp;* \u76d1\u542c\u4e00\u4e2a\u7aef\u53e3,\u76d1\u542c\u5230\u6709\u94fe\u63a5\u65f6,\u6dfb\u52a0\u5230epoll_event<br \/>\n&nbsp;*\/<br \/>\n#include &#8220;select.h&#8221;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;sys\/socket.h&gt;<br \/>\n#include &lt;poll.h&gt;<br \/>\n#include &lt;sys\/epoll.h&gt;<br \/>\n#include &lt;sys\/time.h&gt;<br \/>\n#include &lt;netinet\/in.h&gt;<\/p>\n<p>typedef struct _CLIENT{<br \/>\n&nbsp;&nbsp;&nbsp; int fd;<br \/>\n&nbsp;&nbsp;&nbsp; struct sockaddr_in addr; \/* client&#8217;s address information *\/<br \/>\n} CLIENT;<\/p>\n<p>#define MYPORT 59000<\/p>\n<p>\/\/\u6700\u591a\u5904\u7406\u7684connect<br \/>\n#define MAX_EVENTS 500<\/p>\n<p>\/\/\u5f53\u524d\u7684\u8fde\u63a5\u6570<br \/>\nint currentClient = 0; <\/p>\n<p>\/\/\u6570\u636e\u63a5\u53d7 buf<br \/>\n#define REVLEN 10<br \/>\nchar recvBuf[REVLEN];<\/p>\n<p>\/\/EPOLL\u76f8\u5173 <br \/>\n\/\/epoll\u63cf\u8ff0\u7b26<br \/>\nint epollfd;<br \/>\n\/\/\u4e8b\u4ef6\u6570\u7ec4<br \/>\nstruct epoll_event eventList[MAX_EVENTS];<\/p>\n<p>void AcceptConn(int srvfd);<br \/>\nvoid RecvData(int fd);<\/p>\n<p>int main()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; int i, ret, sinSize;<br \/>\n&nbsp;&nbsp;&nbsp; int recvLen = 0;<br \/>\n&nbsp;&nbsp;&nbsp; fd_set readfds, writefds;<br \/>\n&nbsp;&nbsp;&nbsp; int sockListen, sockSvr, sockMax;<br \/>\n&nbsp;&nbsp;&nbsp; int timeout;<br \/>\n&nbsp;&nbsp;&nbsp; struct sockaddr_in server_addr;<br \/>\n&nbsp;&nbsp;&nbsp; struct sockaddr_in client_addr;<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; \/\/socket<br \/>\n&nbsp;&nbsp;&nbsp; if((sockListen=socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;socket error\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; bzero(&amp;server_addr, sizeof(server_addr));<br \/>\n&nbsp;&nbsp;&nbsp; server_addr.sin_family&nbsp; =&nbsp; AF_INET;<br \/>\n&nbsp;&nbsp;&nbsp; server_addr.sin_port = htons(MYPORT);<br \/>\n&nbsp;&nbsp;&nbsp; server_addr.sin_addr.s_addr&nbsp; =&nbsp; htonl(INADDR_ANY); <br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; \/\/bind<br \/>\n&nbsp;&nbsp;&nbsp; if(bind(sockListen, (struct sockaddr*)&amp;server_addr, sizeof(server_addr)) &lt; 0)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;bind error\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; \/\/listen<br \/>\n&nbsp;&nbsp;&nbsp; if(listen(sockListen, 5) &lt; 0)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;listen error\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; \/\/1. epoll \u521d\u59cb\u5316<br \/>\n&nbsp;&nbsp;&nbsp; epollfd = epoll_create(MAX_EVENTS);<br \/>\n&nbsp;&nbsp;&nbsp; struct epoll_event event;<br \/>\n&nbsp;&nbsp;&nbsp; event.events = EPOLLIN|EPOLLET;<br \/>\n&nbsp;&nbsp;&nbsp; event.data.fd = sockListen;<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; \/\/2. epoll_ctrl<br \/>\n&nbsp;&nbsp;&nbsp; if(epoll_ctl(epollfd, EPOLL_CTL_ADD, sockListen, &amp;event) &lt; 0)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;epoll add fail : fd = %d\\n&#8221;, sockListen);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; \/\/epoll<br \/>\n&nbsp;&nbsp;&nbsp; while(1)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; timeout=3000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/3. epoll_wait<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ret = epoll_wait(epollfd, eventList, MAX_EVENTS, timeout);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(ret &lt; 0)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;epoll error\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(ret == 0)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;timeout &#8230;\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/\u76f4\u63a5\u83b7\u53d6\u4e86\u4e8b\u4ef6\u6570\u91cf,\u7ed9\u51fa\u4e86\u6d3b\u52a8\u7684\u6d41,\u8fd9\u91cc\u662f\u548cpoll\u533a\u522b\u7684\u5173\u952e<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int n = 0;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(n=0; n&lt;ret; n++)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/\u9519\u8bef\u9000\u51fa<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((eventList[n].events &amp; EPOLLERR) ||<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (eventList[n].events &amp; EPOLLHUP) ||<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; !(eventList[n].events &amp; EPOLLIN))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf ( &#8220;epoll error\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close (eventList[n].data.fd);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (eventList[n].data.fd == sockListen)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcceptConn(sockListen);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RecvData(eventList[n].data.fd);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/\u4e0d\u5220\u9664<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/&nbsp;&nbsp; epoll_ctl(epollfd, EPOLL_CTL_DEL, pEvent-&gt;data.fd, pEvent);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; close(epollfd);<br \/>\n&nbsp;&nbsp;&nbsp; close(sockListen);<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; printf(&#8220;test\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp; return 0;<br \/>\n}<\/p>\n<p>\/**************************************************<br \/>\n\u51fd\u6570\u540d\uff1aAcceptConn<br \/>\n\u529f\u80fd\uff1a\u63a5\u53d7\u5ba2\u6237\u7aef\u7684\u94fe\u63a5<br \/>\n\u53c2\u6570\uff1asrvfd\uff1a\u76d1\u542cSOCKET<br \/>\n***************************************************\/<br \/>\nvoid AcceptConn(int srvfd)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; struct sockaddr_in sin;<br \/>\n&nbsp;&nbsp;&nbsp; socklen_t len = sizeof(struct sockaddr_in);<br \/>\n&nbsp;&nbsp;&nbsp; bzero(&amp;sin, len);<\/p>\n<p>&nbsp;&nbsp;&nbsp; int confd = accept(srvfd, (struct sockaddr*)&amp;sin, &amp;len);<\/p>\n<p>&nbsp;&nbsp;&nbsp; if (confd &lt; 0)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;bad accept\\n&#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br \/>\n&nbsp;&nbsp;&nbsp; }else<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;Accept Connection: %d&#8221;, confd);<br \/>\n&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;&nbsp;&nbsp; \/\/setnonblocking(confd);<\/p>\n<p>&nbsp;&nbsp;&nbsp; \/\/4. epoll_wait<br \/>\n&nbsp;&nbsp;&nbsp; \/\/\u5c06\u65b0\u5efa\u7acb\u7684\u8fde\u63a5\u6dfb\u52a0\u5230EPOLL\u7684\u76d1\u542c\u4e2d<br \/>\n&nbsp;&nbsp;&nbsp; struct epoll_event event;<br \/>\n&nbsp;&nbsp;&nbsp; event.data.fd = confd;<br \/>\n&nbsp;&nbsp;&nbsp; event.events =&nbsp; EPOLLIN|EPOLLET;<br \/>\n&nbsp;&nbsp;&nbsp; epoll_ctl(epollfd, EPOLL_CTL_ADD, confd, &amp;event);<br \/>\n}<\/p>\n<p>\/\/\u8bfb\u53d6\u6570\u636e<br \/>\nvoid RecvData(int fd)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; int ret;<br \/>\n&nbsp;&nbsp;&nbsp; int recvLen = 0;<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; memset(recvBuf, 0, REVLEN);<br \/>\n&nbsp;&nbsp;&nbsp; printf(&#8220;RecvData function\\n&#8221;);<br \/>\n&nbsp;&nbsp; &nbsp;<br \/>\n&nbsp;&nbsp;&nbsp; if(recvLen != REVLEN)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(1)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/recv\u6570\u636e<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret = recv(fd, (char *)recvBuf+recvLen, REVLEN-recvLen, 0);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(ret == 0)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recvLen = 0;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if(ret &lt; 0)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recvLen = 0;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/\u6570\u636e\u63a5\u53d7\u6b63\u5e38<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recvLen = recvLen+ret;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(recvLen&lt;REVLEN)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/\u6570\u636e\u63a5\u53d7\u5b8c\u6bd5<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&#8220;buf = %s\\n&#8221;,&nbsp; recvBuf);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recvLen = 0;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;&nbsp;&nbsp; printf(&#8220;content is %s&#8221;, recvBuf);<br \/>\n}<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<h2 style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;line-height:21px;text-transform:none;background-color:#ffffff;list-style-type:none;font-variant:normal;font-style:normal;text-indent:0px;margin:0px;padding-left:0px;letter-spacing:normal;padding-right:0px;font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;white-space:normal;color:#4b4b4b;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<span style=\"line-height:28px;font-family:\u9ed1\u4f53;word-wrap:normal;font-size:14pt;word-break:normal;\">\u4e00\u3001\u4ecb\u7ecd<\/span><br \/>\n<\/h2>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<span style=\"line-height:21px;font-family:\u5b8b\u4f53;word-wrap:normal;font-size:14px;word-break:normal;\">&nbsp;<wbr><span class=\"Apple-converted-space\">&nbsp;<\/span>&nbsp;<wbr><span class=\"Apple-converted-space\">&nbsp;<\/span>epoll\u662fLinux(\u5185\u6838\u7248\u672c2.6\u53ca\u4ee5\u4e0a\u652f\u6301)\u4e0b\u591a\u8def\u590d\u7528IO\u63a5\u53e3select\/poll\u7684\u589e\u5f3a\u7248\u672c\uff0c\u5b83\u80fd<span style=\"line-height:21px;word-wrap:normal;color:#ff0000;word-break:normal;\">\u663e\u8457\u63d0\u9ad8\u7a0b\u5e8f\u5728\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u4e2d\u53ea\u6709\u5c11\u91cf\u6d3b\u8dc3\u7684\u60c5\u51b5\u4e0b\u7684\u7cfb\u7edfCPU\u5229\u7528\u7387<\/span>\uff0c\u56e0\u4e3a\u5b83\u4f1a\u590d\u7528\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u6765\u4f20\u9012\u7ed3\u679c\u800c\u4e0d\u7528\u8feb\u4f7f\u5f00\u53d1\u8005\u6bcf\u6b21\u7b49\u5f85\u4e8b\u4ef6\u4e4b\u524d\u90fd\u5fc5\u987b\u91cd\u65b0\u51c6\u5907\u8981\u88ab\u4fa6\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\uff0c\u53e6\u4e00\u70b9\u539f\u56e0\u5c31\u662f\u83b7\u53d6\u4e8b\u4ef6\u7684\u65f6\u5019\uff0c\u5b83\u65e0\u987b\u904d\u5386\u6574\u4e2a\u88ab\u4fa6\u542c\u7684\u63cf\u8ff0\u7b26\u96c6\uff0c&#8230;<\/span>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<span style=\"line-height:21px;font-family:\u5b8b\u4f53;word-wrap:normal;font-size:14px;word-break:normal;\"><wbr><wbr><wbr><\/span>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<span style=\"line-height:21px;font-family:\u5b8b\u4f53;word-wrap:normal;font-size:14px;word-break:normal;\"><wbr><wbr><\/span>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<wbr>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<wbr><wbr>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<wbr><wbr>\n<\/p>\n<p style=\"border-bottom:0px;text-align:left;border-left:0px;padding-bottom:0px;text-transform:none;background-color:#ffffff;list-style-type:none;text-indent:0px;margin:10px auto;padding-left:0px;letter-spacing:normal;padding-right:0px;font:13px\/19px Verdana, Geneva, Arial, Helvetica, sans-serif;word-wrap:normal;white-space:normal;color:#4b4b4b;word-break:normal;border-top:0px;border-right:0px;word-spacing:0px;padding-top:0px;-webkit-text-stroke-width:0px;\">\n\t<wbr><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[332],"tags":[],"class_list":["post-115","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b - Wayne&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/weizn.net\/?p=115\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b - Wayne&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u4ecb\u7ecd   &nbsp;&nbsp;&nbsp;&nbsp;epoll\u662fLinux(\u5185\u6838\u7248\u672c2.6\u53ca\u4ee5\u4e0a\u652f\u6301)\u4e0b\u591a\u8def\u590d\u7528IO\u63a5\u53e3select\/poll\u7684\u589e\u5f3a\u7248\u672c\uff0c\u5b83\u80fd\u663e\u8457\u63d0\u9ad8\u7a0b\u5e8f\u5728\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u4e2d\u53ea\u6709\u5c11\u91cf\u6d3b\u8dc3\u7684\u60c5\u51b5\u4e0b\u7684\u7cfb\u7edfCPU\u5229\u7528\u7387\uff0c\u56e0\u4e3a\u5b83\u4f1a\u590d\u7528\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u6765\u4f20\u9012\u7ed3\u679c\u800c\u4e0d\u7528\u8feb\u4f7f\u5f00\u53d1\u8005\u6bcf\u6b21\u7b49\u5f85\u4e8b\u4ef6\u4e4b\u524d\u90fd\u5fc5\u987b\u91cd\u65b0\u51c6\u5907\u8981\u88ab\u4fa6\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\uff0c\u53e6\u4e00\u70b9\u539f\u56e0\u5c31\u662f\u83b7\u53d6\u4e8b\u4ef6\u7684\u65f6\u5019\uff0c\u5b83\u65e0\u987b\u904d\u5386\u6574\u4e2a\u88ab\u4fa6\u542c\u7684\u63cf\u8ff0\u7b26\u96c6\uff0c...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/weizn.net\/?p=115\" \/>\n<meta property=\"og:site_name\" content=\"Wayne&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-03-25T05:05:52+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"zinan\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/weizn.net\/#website\",\"url\":\"http:\/\/weizn.net\/\",\"name\":\"Wayne&#039;s Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/weizn.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/weizn.net\/?p=115#webpage\",\"url\":\"http:\/\/weizn.net\/?p=115\",\"name\":\"[\\u8f6c]Linux epoll\\u4e8b\\u4ef6\\u6a21\\u578b - Wayne&#039;s Blog\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/#website\"},\"datePublished\":\"2015-03-25T05:05:52+00:00\",\"dateModified\":\"2015-03-25T05:05:52+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/weizn.net\/?p=115#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/weizn.net\/?p=115\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/weizn.net\/?p=115#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\\u9996\\u9875\",\"item\":\"http:\/\/weizn.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[\\u8f6c]Linux epoll\\u4e8b\\u4ef6\\u6a21\\u578b\"}]},{\"@type\":\"Article\",\"@id\":\"http:\/\/weizn.net\/?p=115#article\",\"isPartOf\":{\"@id\":\"http:\/\/weizn.net\/?p=115#webpage\"},\"author\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"headline\":\"[\\u8f6c]Linux epoll\\u4e8b\\u4ef6\\u6a21\\u578b\",\"datePublished\":\"2015-03-25T05:05:52+00:00\",\"dateModified\":\"2015-03-25T05:05:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/weizn.net\/?p=115#webpage\"},\"wordCount\":1822,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\"},\"articleSection\":[\"Linux\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/weizn.net\/?p=115#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264\",\"name\":\"zinan\",\"logo\":{\"@id\":\"http:\/\/weizn.net\/#personlogo\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b - Wayne&#039;s Blog","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":"http:\/\/weizn.net\/?p=115","og_locale":"zh_CN","og_type":"article","og_title":"[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b - Wayne&#039;s Blog","og_description":"\u4e00\u3001\u4ecb\u7ecd   &nbsp;&nbsp;&nbsp;&nbsp;epoll\u662fLinux(\u5185\u6838\u7248\u672c2.6\u53ca\u4ee5\u4e0a\u652f\u6301)\u4e0b\u591a\u8def\u590d\u7528IO\u63a5\u53e3select\/poll\u7684\u589e\u5f3a\u7248\u672c\uff0c\u5b83\u80fd\u663e\u8457\u63d0\u9ad8\u7a0b\u5e8f\u5728\u5927\u91cf\u5e76\u53d1\u8fde\u63a5\u4e2d\u53ea\u6709\u5c11\u91cf\u6d3b\u8dc3\u7684\u60c5\u51b5\u4e0b\u7684\u7cfb\u7edfCPU\u5229\u7528\u7387\uff0c\u56e0\u4e3a\u5b83\u4f1a\u590d\u7528\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u6765\u4f20\u9012\u7ed3\u679c\u800c\u4e0d\u7528\u8feb\u4f7f\u5f00\u53d1\u8005\u6bcf\u6b21\u7b49\u5f85\u4e8b\u4ef6\u4e4b\u524d\u90fd\u5fc5\u987b\u91cd\u65b0\u51c6\u5907\u8981\u88ab\u4fa6\u542c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\uff0c\u53e6\u4e00\u70b9\u539f\u56e0\u5c31\u662f\u83b7\u53d6\u4e8b\u4ef6\u7684\u65f6\u5019\uff0c\u5b83\u65e0\u987b\u904d\u5386\u6574\u4e2a\u88ab\u4fa6\u542c\u7684\u63cf\u8ff0\u7b26\u96c6\uff0c...","og_url":"http:\/\/weizn.net\/?p=115","og_site_name":"Wayne&#039;s Blog","article_published_time":"2015-03-25T05:05:52+00:00","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"zinan","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/weizn.net\/#website","url":"http:\/\/weizn.net\/","name":"Wayne&#039;s Blog","description":"","publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/weizn.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/weizn.net\/?p=115#webpage","url":"http:\/\/weizn.net\/?p=115","name":"[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b - Wayne&#039;s Blog","isPartOf":{"@id":"http:\/\/weizn.net\/#website"},"datePublished":"2015-03-25T05:05:52+00:00","dateModified":"2015-03-25T05:05:52+00:00","breadcrumb":{"@id":"http:\/\/weizn.net\/?p=115#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/weizn.net\/?p=115"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/weizn.net\/?p=115#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/weizn.net\/"},{"@type":"ListItem","position":2,"name":"[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b"}]},{"@type":"Article","@id":"http:\/\/weizn.net\/?p=115#article","isPartOf":{"@id":"http:\/\/weizn.net\/?p=115#webpage"},"author":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"headline":"[\u8f6c]Linux epoll\u4e8b\u4ef6\u6a21\u578b","datePublished":"2015-03-25T05:05:52+00:00","dateModified":"2015-03-25T05:05:52+00:00","mainEntityOfPage":{"@id":"http:\/\/weizn.net\/?p=115#webpage"},"wordCount":1822,"commentCount":0,"publisher":{"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264"},"articleSection":["Linux"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/weizn.net\/?p=115#respond"]}]},{"@type":["Person","Organization"],"@id":"http:\/\/weizn.net\/#\/schema\/person\/e88bc12c590502d8b6249326f960b264","name":"zinan","logo":{"@id":"http:\/\/weizn.net\/#personlogo"}}]}},"_links":{"self":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=115"}],"version-history":[{"count":0,"href":"http:\/\/weizn.net\/index.php?rest_route=\/wp\/v2\/posts\/115\/revisions"}],"wp:attachment":[{"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weizn.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}