{"id":30071,"date":"2024-11-25T11:40:58","date_gmt":"2024-11-25T03:40:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/30071\/"},"modified":"2024-11-25T11:40:58","modified_gmt":"2024-11-25T03:40:58","slug":"%e6%95%99%e4%bd%a0libco%e6%98%af%e5%a6%82%e4%bd%95%e6%94%af%e6%92%91%e5%b7%a8%e5%a4%a7%e6%95%b0%e6%8d%ae%e4%bf%a1%e6%81%af%e9%87%8f%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/30071\/","title":{"rendered":"\u6559\u4f60libco\u662f\u5982\u4f55\u652f\u6491\u5de8\u5927\u6570\u636e\u4fe1\u606f\u91cf\u7684"},"content":{"rendered":"<p>ibco\u662f\u5fae\u4fe1\u540e\u53f0\u5927\u89c4\u6a21\u4f7f\u7528\u7684c\/c++\u534f\u7a0b\u5e93\uff0c2013\u5e74\u81f3\u4eca\u7a33\u5b9a\u8fd0\u884c\u5728\u5fae\u4fe1\u540e\u53f0\u7684\u6570\u4e07\u53f0\u673a\u5668\u4e0a\u3002libco\u57282013\u5e74\u7684\u65f6\u5019\u4f5c\u4e3a\u817e\u8baf\u516d\u5927\u5f00\u6e90\u9879\u76ee\u9996\u6b21\u5f00\u6e90\uff0c\u6211\u4eec\u6700\u8fd1\u505a\u4e86\u4e00\u6b21\u8f83\u5927\u7684\u66f4\u65b0\uff0c\u540c\u6b65\u66f4\u65b0\u5728github.com\/tencent\/libco&nbsp;\u4e0a\u3002libco\u652f\u6301\u540e\u53f0\u654f\u6377\u7684\u540c\u6b65\u98ce\u683c\u7f16\u7a0b\u6a21\u5f0f\uff0c\u540c\u65f6\u63d0\u4f9b\u7cfb\u7edf\u7684\u9ad8\u5e76\u53d1\u80fd\u529b\u3002<\/p>\n<p>\u3000\u3000libco\u652f\u6301\u7684\u7279\u6027<\/p>\n<p>\u3000\u3000\u65e0\u9700\u4fb5\u5165\u4e1a\u52a1\u903b\u8f91\uff0c\u628a\u591a\u8fdb\u7a0b\u3001\u591a\u7ebf\u7a0b\u670d\u52a1\u6539\u9020\u6210\u534f\u7a0b\u670d\u52a1\uff0c\u5e76\u53d1\u80fd\u529b\u5f97\u5230\u767e\u500d\u63d0\u5347;<\/p>\n<p>\u3000\u3000\u652f\u6301cgi\uff0c\u8f7b\u677e\u6784\u5efaweb\u670d\u52a1(new);<\/p>\n<p>\u3000\u3000\u652f\u6301gethostbyname\u3001mysqlclient\u3001ssl\u7b49\u5e38\u7528\u7b2c\u4e09\u5e93(new);<\/p>\n<p>\u3000\u3000\u53ef\u9009\u7684\u5171\u4eab\u6808\u6a21\u5f0f\uff0c\u5355\u673a\u8f7b\u677e\u63a5\u5165\u5343\u4e07\u8fde\u63a5(new);<\/p>\n<p>\u3000\u3000\u5b8c\u5584\u7b80\u6d01\u7684\u534f\u7a0b\u7f16\u7a0b<\/p>\n<p>\u3000\u3000\u2013 \u7c7bpthread\u63a5\u53e3\u8bbe\u8ba1\uff0c\u901a\u8fc7co_create\u3001co_resume\u7b49\u7b80\u5355\u6e05\u6670\u63a5\u53e3\u5373\u53ef\u5b8c\u6210\u534f\u7a0b\u7684\u521b\u5efa\u4e0e\u6062\u590d; \u2013 \u7c7bthread\u7684\u534f\u7a0b\u79c1\u6709\u3001\u534f\u7a0b\u95f4\u901a\u4fe1\u7684\u534f\u7a0b\u4fe1\u53f7\u91cfco_signal (new); \u2013 \u975e\u8bed\u8a00\u7ea7\u522b\u7684lambda\u5b9e\u73b0\uff0c\u7ed3\u5408\u534f\u7a0b\u539f\u5730\u7f16\u5199\u5e76\u6267\u884c\u540e\u53f0\u5f02\u6b65\u4efb\u52a1 (new); \u2013 \u57fa\u4e8eepoll\/kqueue\u5b9e\u73b0\u7684\u5c0f\u800c\u8f7b\u7684\u7f51\u7edc\u6846\u67b6\uff0c\u57fa\u4e8e\u65f6\u95f4\u8f6e\u76d8\u5b9e\u73b0\u7684\u9ad8\u6027\u80fd;<\/p>\n<p>\u3000\u3000libco\u4ea7\u751f\u7684\u80cc\u666f<\/p>\n<p>\u3000\u3000\u65e9\u671f\u5fae\u4fe1\u540e\u53f0\u56e0\u4e3a\u4e1a\u52a1\u9700\u6c42\u590d\u6742\u591a\u53d8\u3001\u4ea7\u54c1\u8981\u6c42\u5feb\u901f\u8fed\u4ee3\u7b49\u9700\u6c42\uff0c\u5927\u90e8\u5206\u6a21\u5757\u90fd\u91c7\u7528\u4e86\u534a\u540c\u6b65\u534a\u5f02\u6b65\u3002\u63a5\u5165\u5c42\u4e3a\u5f02\u6b65\u6a21\u578b\uff0c\u4e1a\u52a1\u903b\u8f91\u5c42\u5219\u662f\u540c\u6b65\u7684\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u6a21\u578b\uff0c\u4e1a\u52a1\u903b\u8f91\u7684\u5e76\u53d1\u80fd\u529b\u53ea\u6709\u51e0\u5341\u5230\u51e0\u767e\u3002\u968f\u7740\u5fae\u4fe1\u4e1a\u52a1\u7684\u589e\u957f\uff0c\u7cfb\u7edf\u89c4\u6a21\u53d8\u5f97\u8d8a\u6765\u8d8a\u5e9e\u5927\uff0c\u6bcf\u4e2a\u6a21\u5757\u5f88\u5bb9\u6613\u53d7\u5230\u540e\u7aef\u670d\u52a1\/\u7f51\u7edc\u6296\u52a8\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u3000\u3000\u5f02\u6b65\u5316\u6539\u9020\u7684\u9009\u62e9<\/p>\n<p>\u3000\u3000\u4e3a\u4e86\u63d0\u5347\u5fae\u4fe1\u540e\u53f0\u7684\u5e76\u53d1\u80fd\u529b\uff0c\u4e00\u822c\u7684\u505a\u6cd5\u662f\u628a\u73b0\u7f51\u7684\u6240\u6709\u670d\u52a1\u6539\u6210\u5f02\u6b65\u6a21\u578b\u3002\u8fd9\u79cd\u505a\u6cd5\u5de5\u7a0b\u91cf\u5de8\u5927\uff0c\u4ece\u6846\u67b6\u5230\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u5747\u9700\u8981\u505a\u4e00\u6b21\u5f7b\u5e95\u7684\u6539\u9020\uff0c\u8017\u65f6\u8017\u529b\u800c\u4e14\u98ce\u9669\u5de8\u5927\u3002\u4e8e\u662f\u6211\u4eec\u5f00\u59cb\u8003\u8651\u4f7f\u7528\u534f\u7a0b\u3002<\/p>\n<p>\u3000\u3000\u4f46\u4f7f\u7528\u534f\u7a0b\u4f1a\u9762\u4e34\u4ee5\u4e0b\u6311\u6218\uff1a<\/p>\n<p>\u3000\u3000\u4e1a\u754c\u534f\u7a0b\u5728c\/c++\u73af\u5883\u4e0b\u6ca1\u6709\u5927\u89c4\u6a21\u5e94\u7528\u7684\u7ecf\u9a8c;<\/p>\n<p>\u3000\u3000\u5982\u4f55\u63a7\u5236\u534f\u7a0b\u8c03\u5ea6;<\/p>\n<p>\u3000\u3000\u5982\u4f55\u5904\u7406\u540c\u6b65\u98ce\u683c\u7684\u8c03\u7528\uff0c\u5982socket\u3001mysqlclient\u7b49;<\/p>\n<p>\u3000\u3000\u5982\u4f55\u5904\u7406\u5df2\u6709\u5168\u5c40\u53d8\u91cf\u3001\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\u7684\u4f7f\u7528;<\/p>\n<p>\u3000\u3000\u6700\u7ec8\u6211\u4eec\u901a\u8fc7libco\u89e3\u51b3\u4e86\u4e0a\u8ff0\u7684\u6240\u6709\u95ee\u9898\uff0c\u5b9e\u73b0\u4e86\u5bf9\u4e1a\u52a1\u903b\u8f91\u975e\u4fb5\u5165\u7684\u5f02\u6b65\u5316\u6539\u9020\u3002\u6211\u4eec\u4f7f\u7528libco\u5bf9\u5fae\u4fe1\u540e\u53f0\u4e0a\u767e\u4e2a\u6a21\u5757\u8fdb\u884c\u4e86\u534f\u7a0b\u5f02\u6b65\u5316\u6539\u9020\uff0c\u6539\u9020\u8fc7\u7a0b\u4e2d\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u57fa\u672c\u65e0\u4fee\u6539\u3002\u81f3\u4eca\uff0c\u5fae\u4fe1\u540e\u53f0\u7edd\u5927\u90e8\u5206\u670d\u52a1\u90fd\u5df2\u662f\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u534f\u7a0b\u6a21\u578b\uff0c\u5e76\u53d1\u80fd\u529b\u76f8\u6bd4\u4e4b\u524d\u6709\u4e86\u8d28\u7684\u63d0\u5347\uff0c\u800clibco\u4e5f\u6210\u4e3a\u4e86\u5fae\u4fe1\u540e\u53f0\u6846\u67b6\u7684\u57fa\u77f3\u3002<\/p>\n<p>\u3000\u3000libco\u6846\u67b6<\/p>\n<p>\u3000\u3000libco\u5728\u6846\u67b6\u5206\u4e3a\u4e09\u5c42\uff0c\u5206\u522b\u662f\u63a5\u53e3\u5c42\u3001\u7cfb\u7edfhook\u5c42\u4ee5\u53ca\u5c42\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/739\/499\/304\/1494474613352325.jpg\" class=\"aligncenter\" title=\"\u6559\u4f60libco\u662f\u5982\u4f55\u652f\u6491\u5de8\u5927\u6570\u636e\u4fe1\u606f\u91cf\u7684\u63d2\u56fe\" alt=\"\u6559\u4f60libco\u662f\u5982\u4f55\u652f\u6491\u5de8\u5927\u6570\u636e\u4fe1\u606f\u91cf\u7684\u63d2\u56fe\" \/><\/p>\n<p>\u3000\u3000\u540c\u6b65\u98ce\u683cAPI\u7684\u5904\u7406<\/p>\n<p>\u3000\u3000\u5bf9\u4e8e\u540c\u6b65\u98ce\u683c\u7684API\uff0c\u4e3b\u8981\u662f\u540c\u6b65\u7684\u7f51\u7edc\u8c03\u7528\uff0clibco\u7684\u9996\u8981\u4efb\u52a1\u662f\u6d88\u9664\u8fd9\u4e9b\u7b49\u5f85\u5bf9\u8d44\u6e90\u7684\u5360\u7528\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u5e76\u53d1\u6027\u80fd\u3002\u4e00\u4e2a\u5e38\u89c4\u7684\u7f51\u7edc\u540e\u53f0\u670d\u52a1\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u7ecf\u5386connect\u3001write\u3001read\u7b49\u6b65\u9aa4\uff0c\u5b8c\u6210\u4e00\u6b21\u5b8c\u6574\u7684\u7f51\u7edc\u4ea4\u4e92\u3002\u5f53\u540c\u6b65\u7684\u8c03\u7528\u8fd9\u4e9bAPI\u7684\u65f6\u5019\uff0c\u6574\u4e2a\u7ebf\u7a0b\u4f1a\u56e0\u4e3a\u7b49\u5f85\u7f51\u7edc\u4ea4\u4e92\u800c\u6302\u8d77\u3002<\/p>\n<p>\u3000\u3000\u867d\u7136\u540c\u6b65\u7f16\u7a0b\u98ce\u683c\u7684\u5e76\u53d1\u6027\u80fd\u5e76\u4e0d\u597d\uff0c\u4f46\u662f\u5b83\u5177\u6709\u4ee3\u7801\u903b\u8f91\u6e05\u6670\u3001\u6613\u4e8e\u7f16\u5199\u7684\u4f18\u70b9\uff0c\u5e76\u53ef\u652f\u6301\u4e1a\u52a1\u5feb\u901f\u8fed\u4ee3\u654f\u6377\u5f00\u53d1\u3002\u4e3a\u4e86\u7ee7\u7eed\u4fdd\u6301\u540c\u6b65\u7f16\u7a0b\u7684\u4f18\u70b9\uff0c\u5e76\u4e14\u4e0d\u9700\u4fee\u6539\u7ebf\u4e0a\u5df2\u6709\u7684\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\uff0clibco\u521b\u65b0\u5730\u63a5\u7ba1\u4e86\u7f51\u7edc\u8c03\u7528\u63a5\u53e3(Hook)\uff0c\u628a\u534f\u7a0b\u7684\u8ba9\u51fa\u4e0e\u6062\u590d\u4f5c\u4e3a\u5f02\u6b65\u7f51\u7edcIO\u4e2d\u7684\u4e00\u6b21\u4e8b\u4ef6\u6ce8\u518c\u4e0e\u56de\u8c03\u3002\u5f53\u4e1a\u52a1\u5904\u7406\u9047\u5230\u540c\u6b65\u7f51\u7edc\u8bf7\u6c42\u7684\u65f6\u5019\uff0clibco\u5c42\u4f1a\u628a\u672c\u6b21\u7f51\u7edc\u8bf7\u6c42\u6ce8\u518c\u4e3a\u5f02\u6b65\u4e8b\u4ef6\uff0c\u672c\u534f\u7a0b\u8ba9\u51faCPU\u5360\u7528\uff0cCPU\u4ea4\u7ed9\u534f\u7a0b\u6267\u884c\u3002libco\u4f1a\u5728\u7f51\u7edc\u4e8b\u4ef6\u53d1\u751f\u6216\u8005\u8d85\u65f6\u7684\u65f6\u5019\uff0c\u81ea\u52a8\u7684\u6062\u590d\u534f\u7a0b\u6267\u884c\u3002<\/p>\n<p>\u3000\u3000\u5927\u90e8\u5206\u540c\u6b65\u98ce\u683c\u7684API\u6211\u4eec\u90fd\u901a\u8fc7Hook\u7684\u65b9\u6cd5\u6765\u63a5\u7ba1\u4e86\uff0clibco\u4f1a\u5728\u6070\u5f53\u7684\u65f6\u673a\u8c03\u5ea6\u534f\u7a0b\u6062\u590d\u6267\u884c\u3002<\/p>\n<p>\u3000\u3000\u5343\u4e07\u7ea7\u534f\u7a0b\u652f\u6301<br \/>\u3000\u3000libco\u9ed8\u8ba4\u662f\u6bcf\u4e00\u4e2a\u534f\u7a0b\u72ec\u4eab\u4e00\u4e2a\u8fd0\u884c\u6808\uff0c\u5728\u534f\u7a0b\u521b\u5efa\u7684\u65f6\u5019\uff0c\u4ece\u5806\u5185\u5b58\u5206\u914d\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u4f5c\u4e3a\u8be5\u534f\u7a0b\u7684\u8fd0\u884c\u6808\u3002\u5982\u679c\u6211\u4eec\u7528\u4e00\u4e2a\u534f\u7a0b\u5904\u7406\u524d\u7aef\u7684\u4e00\u4e2a\u63a5\u5165\u8fde\u63a5\uff0c\u90a3\u5bf9\u4e8e\u4e00\u4e2a\u6d77\u91cf\u63a5\u5165\u670d\u52a1\u6765\u8bf4\uff0c\u6211\u4eec\u7684\u670d\u52a1\u7684\u5e76\u53d1\u4e0a\u9650\u5c31\u5f88\u5bb9\u6613\u53d7\u9650\u4e8e\u5185\u5b58\u3002\u4e3a\u6b64\uff0clibco\u4e5f\u63d0\u4f9b\u4e86stackless\u7684\u534f\u7a0b\u5171\u4eab\u6808\u6a21\u5f0f\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u82e5\u5e72\u4e2a\u534f\u7a0b\u5171\u4eab\u540c\u4e00\u4e2a\u8fd0\u884c\u6808\u3002\u540c\u4e00\u4e2a\u5171\u4eab\u6808\u4e0b\u7684\u534f\u7a0b\u95f4\u5207\u6362\u7684\u65f6\u5019\uff0c\u9700\u8981\u628a\u5f53\u524d\u7684\u8fd0\u884c\u6808\u5185\u5bb9\u62f7\u8d1d\u5230\u534f\u7a0b\u7684\u79c1\u6709\u5185\u5b58\u4e2d\u3002\u4e3a\u4e86\u51cf\u5c11\u8fd9\u79cd\u5185\u5b58\u62f7\u8d1d\u6b21\u6570\uff0c\u5171\u4eab\u6808\u7684\u5185\u5b58\u62f7\u8d1d\u53ea\u53d1\u751f\u5728\u4e0d\u540c\u534f\u7a0b\u95f4\u7684\u5207\u6362\u3002\u5f53\u5171\u4eab\u6808\u7684\u5360\u7528\u8005\u4e00\u76f4\u6ca1\u6709\u6539\u53d8\u7684\u65f6\u5019\uff0c\u5219\u4e0d\u9700\u8981\u62f7\u8d1d\u8fd0\u884c\u6808\u3002<\/p>\n<p>\u3000\u3000libco\u534f\u7a0b\u7684\u5171\u4eab\u534f\u7a0b\u6808\u6a21\u5f0f\u4f7f\u5f97\u5355\u673a\u5f88\u5bb9\u6613\u63a5\u5165\u5343\u4e07\u8fde\u63a5\uff0c\u53ea\u9700\u521b\u5efa\u8db3\u591f\u591a\u7684\u534f\u7a0b\u5373\u53ef\u3002\u6211\u4eec\u901a\u8fc7libco\u5171\u4eab\u6808\u6a21\u5f0f\u521b\u5efa1\u5343\u4e07\u7684\u534f\u7a0b(E5-2670 v3 @ 2.30GHz * 2, 128G\u5185\u5b58)\uff0c\u6bcf10\u4e07\u4e2a\u534f\u7a0b\u5171\u4eab\u7684\u4f7f\u7528128k\u5185\u5b58\uff0c\u6574\u4e2a\u7a33\u5b9a\u670d\u52a1\u7684\u65f6\u5019\u603b\u5185\u5b58\u6d88\u8017\u5927\u6982\u4e3a66G\u3002<br \/>\u3000\u3000\u534f\u7a0b\u79c1\u6709\u53d8\u91cf<br \/>\u3000\u3000\u591a\u8fdb\u7a0b\u7a0b\u5e8f\u6539\u9020\u4e3a\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u7528thread\u6765\u5bf9\u5168\u5c40\u53d8\u91cf\u8fdb\u884c\u5feb\u901f\u4fee\u6539\uff0c\u800c\u5728\u534f\u7a0b\u73af\u5883\u4e0b\uff0c\u6211\u4eec\u521b\u9020\u4e86\u534f\u7a0b\u53d8\u91cfROUTINE_VAR\uff0c\u6781\u5927\u7b80\u5316\u4e86\u534f\u7a0b\u7684\u6539\u9020\u5de5\u4f5c\u91cf\u3002<br \/>\u3000\u3000\u56e0\u4e3a\u534f\u7a0b\u5b9e\u8d28\u4e0a\u662f\u7ebf\u7a0b\u5185\u4e32\u884c\u6267\u884c\u7684\uff0c\u6240\u4ee5\u5f53\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u6709\u91cd\u5165\u7684\u95ee\u9898\u3002\u6bd4\u5982\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2athread\u7684\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u539f\u672c\u662f\u5e0c\u671b\u6bcf\u4e00\u4e2a\u6267\u884c\u903b\u8f91\u72ec\u4eab\u8fd9\u4e2a\u53d8\u91cf\u7684\u3002\u4f46\u5f53\u6211\u4eec\u7684\u6267\u884c\u73af\u5883\u8fc1\u79fb\u5230\u534f\u7a0b\u4e86\u4e4b\u540e\uff0c\u540c\u4e00\u4e2a\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u534f\u7a0b\u4f1a\u64cd\u4f5c\u5b83\uff0c\u8fd9\u5c31\u5bfc\u81f4\u4e86\u53d8\u91cf\u51b2\u5165\u7684\u95ee\u9898\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5728\u505alibco\u5f02\u6b65\u5316\u6539\u9020\u7684\u65f6\u5019\uff0c\u628a\u5927\u90e8\u5206\u7684\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\u6539\u6210\u4e86\u534f\u7a0b\u7ea7\u79c1\u6709\u53d8\u91cf\u3002\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u5177\u6709\u8fd9\u6837\u7684\u7279\u6027\uff1a\u5f53\u4ee3\u7801\u8fd0\u884c\u5728\u591a\u7ebf\u7a0b\u975e\u534f\u7a0b\u73af\u5883\u4e0b\u65f6\uff0c\u8be5\u53d8\u91cf\u662f\u7ebf\u7a0b\u79c1\u6709\u7684;\u5f53\u4ee3\u7801\u8fd0\u884c\u5728\u534f\u7a0b\u73af\u5883\u7684\u65f6\u5019\uff0c\u6b64\u53d8\u91cf\u662f\u534f\u7a0b\u79c1\u6709\u7684\u3002\u5e95\u5c42\u7684\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u4f1a\u8fd0\u884c\u73af\u5883\u7684\u5224\u65ad\u5e76\u6b63\u786e\u8fd4\u56de\u6240\u9700\u7684\u503c\u3002<br \/>\u3000\u3000\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u5bf9\u4e8e\u73b0\u6709\u73af\u5883\u540c\u6b65\u5230\u5f02\u6b65\u5316\u6539\u9020\u8d77\u4e86\u4e3e\u8db3\u8f7b\u91cd\u7684\u4f5c\u7528\uff0c\u540c\u65f6\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u65b9\u4fbf\u7684\u65b9\u6cd5\u5b9a\u4e49\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u7b80\u5355\u5230\u53ea\u9700\u4e00\u884c\u58f0\u660e\u4ee3\u7801\u5373\u53ef\u3002<br \/>\u3000\u3000gethostbyname\u7684Hook\u65b9\u6cd5<br \/>\u3000\u3000\u5bf9\u4e8e\u73b0\u7f51\u670d\u52a1\uff0c\u6709\u53ef\u80fd\u9700\u8981\u901a\u8fc7\u7cfb\u7edf\u7684gethostbyname API\u63a5\u53e3\u53bbDNS\u83b7\u53d6\u771f\u5b9e\u5730\u5740\u3002\u6211\u4eec\u5728\u534f\u7a0b\u5316\u6539\u9020\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u6211\u4eechook\u7684socket\u65cf\u51fd\u6570\u5bf9gethostbyname\u4e0d\u9002\u7528\uff0c\u5f53\u4e00\u4e2a\u534f\u7a0b\u8c03\u7528\u4e86gethostbyname\u65f6\u4f1a\u540c\u6b65\u7b49\u5f85\u7ed3\u679c\uff0c\u8fd9\u5c31\u5bfc\u81f4\u4e86\u540c\u7ebf\u7a0b\u5185\u7684\u5176\u5b83\u534f\u7a0b\u88ab\u5ef6\u65f6\u6267\u884c\u3002\u6211\u4eec\u5bf9glibc\u7684gethostbyname\u6e90\u7801\u8fdb\u884c\u4e86\u7814\u7a76\uff0c\u53d1\u73b0hook\u4e0d\u751f\u6548\u4e3b\u8981\u662f\u7531\u4e8eglibc\u5185\u90e8\u662f\u5b9a\u4e49\u4e86poll\u65b9\u6cd5\u6765\u7b49\u5f85\u4e8b\u4ef6\uff0c\u800c\u4e0d\u662f\u901a\u7528\u7684poll\u65b9\u6cd5;\u540c\u65f6glibc\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u4e0d\u540c\u534f\u7a0b\u7684\u5207\u6362\u53ef\u80fd\u4f1a\u91cd\u5165\u5bfc\u81f4\u6570\u636e\u4e0d\u51c6\u786e\u3002\u6700\u7ec8gethostbyname\u534f\u7a0b\u5f02\u6b65\u5316\u662f\u901a\u8fc7Hook poll\u65b9\u6cd5\u4ee5\u53ca\u5b9a\u4e49\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u89e3\u51b3\u7684\u3002<br \/>\u3000\u3000gethostbyname\u662fglibc\u63d0\u4f9b\u7684\u540c\u6b65\u67e5\u8be2dns\u63a5\u53e3\uff0c\u4e1a\u754c\u8fd8\u6709\u5f88\u591a\u4f18\u79c0\u7684gethostbyname\u7684\u5f02\u6b65\u5316\u89e3\u51b3\u65b9\u6848\uff0c\u4f46\u662f\u8fd9\u4e9b\u5b9e\u73b0\u90fd\u9700\u8981\u5f15\u5165\u4e00\u4e2a\u7b2c\u4e09\u65b9\u5e93\u5e76\u4e14\u8981\u6c42\u5e95\u5c42\u63d0\u4f9b\u5f02\u6b65\u56de\u8c03\u901a\u77e5\u673a\u5236\u3002libco\u901a\u8fc7hook\u65b9\u6cd5\uff0c\u5728\u4e0d\u4fee\u6539glibc\u6e90\u7801\u7684\u524d\u63d0\u4e0b\u5b9e\u73b0\u4e86\u7684gethostbyname\u7684\u5f02\u6b65\u5316\u3002<br \/>\u3000\u3000\u534f\u7a0b\u4fe1\u53f7\u91cf<br \/>\u3000\u3000\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\uff0c\u6211\u4eec\u4f1a\u6709\u7ebf\u7a0b\u95f4\u540c\u6b65\u7684\u9700\u6c42\uff0c\u6bd4\u5982\u4e00\u4e2a\u7ebf\u7a0b\u7684\u6267\u884c\u9700\u8981\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u7684\u4fe1\u53f7\uff0c\u5bf9\u4e8e\u8fd9\u79cd\u9700\u6c42\uff0c\u6211\u4eec\u901a\u5e38\u662f\u4f7f\u7528pthread_signal \u6765\u89e3\u51b3\u7684\u3002\u5728libco\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u534f\u7a0b\u4fe1\u53f7\u91cfco_signal\u7528\u4e8e\u5904\u7406\u534f\u7a0b\u95f4\u7684\u5e76\u53d1\u9700\u6c42\uff0c\u4e00\u4e2a\u534f\u7a0b\u53ef\u4ee5\u901a\u8fc7co_cond_signal\u4e0eco_cond_broadcast\u6765\u51b3\u5b9a\u901a\u77e5\u4e00\u4e2a\u7b49\u5f85\u7684\u534f\u7a0b\u6216\u8005\u5524\u9192\u6240\u6709\u7b49\u5f85\u534f\u7a0b\u3002<br \/>\u3000\u3000\u603b\u7ed3<br \/>\u3000\u3000libco\u662f\u4e00\u4e2a\u9ad8\u6548\u7684c\/c++\u534f\u7a0b\u5e93\uff0c\u63d0\u4f9b\u4e86\u5b8c\u5584\u7684\u534f\u7a0b\u7f16\u7a0b\u63a5\u53e3\u3001\u5e38\u7528\u7684Socket\u65cf\u51fd\u6570Hook\u7b49\uff0c\u4f7f\u5f97\u4e1a\u52a1\u53ef\u7528\u540c\u6b65\u7f16\u7a0b\u6a21\u578b\u5feb\u901f\u8fed\u4ee3\u5f00\u53d1\u3002\u968f\u7740\u51e0\u5e74\u6765\u7684\u7a33\u5b9a\u8fd0\u884c\uff0clibco\u4f5c\u4e3a\u5fae\u4fe1\u540e\u53f0\u6846\u67b6\u7684\u57fa\u77f3\u53d1\u6325\u4e86\u4e3e\u8db3\u8f7b\u91cd\u7684\u4f5c\u7528\u3002<\/p>\n<p>\u3010\u76f8\u5173\u63a8\u8350\u3011<\/p>\n<p>1. <\/p>\n<p>2. <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6559\u4f60libco\u662f\u5982\u4f55\u652f\u6491\u5de8\u5927\u6570\u636e\u4fe1\u606f\u91cf\u7684\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ibco\u662f\u5fae\u4fe1\u540e\u53f0\u5927\u89c4\u6a21\u4f7f\u7528\u7684c\/c++\u534f\u7a0b\u5e93\uff0c2013\u5e74\u81f3\u4eca\u7a33\u5b9a\u8fd0\u884c\u5728\u5fae\u4fe1\u540e\u53f0\u7684\u6570\u4e07\u53f0\u673a\u5668\u4e0a\u3002libco\u57282013\u5e74\u7684\u65f6\u5019\u4f5c\u4e3a\u817e\u8baf\u516d\u5927\u5f00\u6e90\u9879\u76ee\u9996\u6b21\u5f00\u6e90\uff0c\u6211\u4eec\u6700\u8fd1\u505a\u4e86\u4e00\u6b21\u8f83\u5927\u7684\u66f4\u65b0\uff0c\u540c\u6b65\u66f4\u65b0\u5728github.com\/tencent\/libco&nbsp;\u4e0a\u3002libco\u652f\u6301\u540e\u53f0\u654f\u6377\u7684\u540c\u6b65\u98ce\u683c\u7f16\u7a0b\u6a21\u5f0f\uff0c\u540c\u65f6\u63d0\u4f9b\u7cfb\u7edf\u7684\u9ad8\u5e76\u53d1\u80fd\u529b\u3002 \u3000\u3000libco\u652f\u6301\u7684\u7279\u6027 \u3000\u3000\u65e0\u9700\u4fb5\u5165\u4e1a\u52a1\u903b\u8f91\uff0c\u628a\u591a\u8fdb\u7a0b\u3001\u591a\u7ebf\u7a0b\u670d\u52a1\u6539\u9020\u6210\u534f\u7a0b\u670d\u52a1\uff0c\u5e76\u53d1\u80fd\u529b\u5f97\u5230\u767e\u500d\u63d0\u5347; \u3000\u3000\u652f\u6301cgi\uff0c\u8f7b\u677e\u6784\u5efaweb\u670d\u52a1(new); \u3000\u3000\u652f\u6301gethostbyname\u3001mysqlclient\u3001ssl\u7b49\u5e38\u7528\u7b2c\u4e09\u5e93(new); \u3000\u3000\u53ef\u9009\u7684\u5171\u4eab\u6808\u6a21\u5f0f\uff0c\u5355\u673a\u8f7b\u677e\u63a5\u5165\u5343\u4e07\u8fde\u63a5(new); \u3000\u3000\u5b8c\u5584\u7b80\u6d01\u7684\u534f\u7a0b\u7f16\u7a0b \u3000\u3000\u2013 \u7c7bpthread\u63a5\u53e3\u8bbe\u8ba1\uff0c\u901a\u8fc7co_create\u3001co_resume\u7b49\u7b80\u5355\u6e05\u6670\u63a5\u53e3\u5373\u53ef\u5b8c\u6210\u534f\u7a0b\u7684\u521b\u5efa\u4e0e\u6062\u590d; \u2013 \u7c7bthread\u7684\u534f\u7a0b\u79c1\u6709\u3001\u534f\u7a0b\u95f4\u901a\u4fe1\u7684\u534f\u7a0b\u4fe1\u53f7\u91cfco_signal (new); \u2013 \u975e\u8bed\u8a00\u7ea7\u522b\u7684lambda\u5b9e\u73b0\uff0c\u7ed3\u5408\u534f\u7a0b\u539f\u5730\u7f16\u5199\u5e76\u6267\u884c\u540e\u53f0\u5f02\u6b65\u4efb\u52a1 (new); \u2013 \u57fa\u4e8eepoll\/kqueue\u5b9e\u73b0\u7684\u5c0f\u800c\u8f7b\u7684\u7f51\u7edc\u6846\u67b6\uff0c\u57fa\u4e8e\u65f6\u95f4\u8f6e\u76d8\u5b9e\u73b0\u7684\u9ad8\u6027\u80fd; \u3000\u3000libco\u4ea7\u751f\u7684\u80cc\u666f \u3000\u3000\u65e9\u671f\u5fae\u4fe1\u540e\u53f0\u56e0\u4e3a\u4e1a\u52a1\u9700\u6c42\u590d\u6742\u591a\u53d8\u3001\u4ea7\u54c1\u8981\u6c42\u5feb\u901f\u8fed\u4ee3\u7b49\u9700\u6c42\uff0c\u5927\u90e8\u5206\u6a21\u5757\u90fd\u91c7\u7528\u4e86\u534a\u540c\u6b65\u534a\u5f02\u6b65\u3002\u63a5\u5165\u5c42\u4e3a\u5f02\u6b65\u6a21\u578b\uff0c\u4e1a\u52a1\u903b\u8f91\u5c42\u5219\u662f\u540c\u6b65\u7684\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u6a21\u578b\uff0c\u4e1a\u52a1\u903b\u8f91\u7684\u5e76\u53d1\u80fd\u529b\u53ea\u6709\u51e0\u5341\u5230\u51e0\u767e\u3002\u968f\u7740\u5fae\u4fe1\u4e1a\u52a1\u7684\u589e\u957f\uff0c\u7cfb\u7edf\u89c4\u6a21\u53d8\u5f97\u8d8a\u6765\u8d8a\u5e9e\u5927\uff0c\u6bcf\u4e2a\u6a21\u5757\u5f88\u5bb9\u6613\u53d7\u5230\u540e\u7aef\u670d\u52a1\/\u7f51\u7edc\u6296\u52a8\u7684\u5f71\u54cd\u3002 \u3000\u3000\u5f02\u6b65\u5316\u6539\u9020\u7684\u9009\u62e9 \u3000\u3000\u4e3a\u4e86\u63d0\u5347\u5fae\u4fe1\u540e\u53f0\u7684\u5e76\u53d1\u80fd\u529b\uff0c\u4e00\u822c\u7684\u505a\u6cd5\u662f\u628a\u73b0\u7f51\u7684\u6240\u6709\u670d\u52a1\u6539\u6210\u5f02\u6b65\u6a21\u578b\u3002\u8fd9\u79cd\u505a\u6cd5\u5de5\u7a0b\u91cf\u5de8\u5927\uff0c\u4ece\u6846\u67b6\u5230\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u5747\u9700\u8981\u505a\u4e00\u6b21\u5f7b\u5e95\u7684\u6539\u9020\uff0c\u8017\u65f6\u8017\u529b\u800c\u4e14\u98ce\u9669\u5de8\u5927\u3002\u4e8e\u662f\u6211\u4eec\u5f00\u59cb\u8003\u8651\u4f7f\u7528\u534f\u7a0b\u3002 \u3000\u3000\u4f46\u4f7f\u7528\u534f\u7a0b\u4f1a\u9762\u4e34\u4ee5\u4e0b\u6311\u6218\uff1a \u3000\u3000\u4e1a\u754c\u534f\u7a0b\u5728c\/c++\u73af\u5883\u4e0b\u6ca1\u6709\u5927\u89c4\u6a21\u5e94\u7528\u7684\u7ecf\u9a8c; \u3000\u3000\u5982\u4f55\u63a7\u5236\u534f\u7a0b\u8c03\u5ea6; \u3000\u3000\u5982\u4f55\u5904\u7406\u540c\u6b65\u98ce\u683c\u7684\u8c03\u7528\uff0c\u5982socket\u3001mysqlclient\u7b49; \u3000\u3000\u5982\u4f55\u5904\u7406\u5df2\u6709\u5168\u5c40\u53d8\u91cf\u3001\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\u7684\u4f7f\u7528; \u3000\u3000\u6700\u7ec8\u6211\u4eec\u901a\u8fc7libco\u89e3\u51b3\u4e86\u4e0a\u8ff0\u7684\u6240\u6709\u95ee\u9898\uff0c\u5b9e\u73b0\u4e86\u5bf9\u4e1a\u52a1\u903b\u8f91\u975e\u4fb5\u5165\u7684\u5f02\u6b65\u5316\u6539\u9020\u3002\u6211\u4eec\u4f7f\u7528libco\u5bf9\u5fae\u4fe1\u540e\u53f0\u4e0a\u767e\u4e2a\u6a21\u5757\u8fdb\u884c\u4e86\u534f\u7a0b\u5f02\u6b65\u5316\u6539\u9020\uff0c\u6539\u9020\u8fc7\u7a0b\u4e2d\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u57fa\u672c\u65e0\u4fee\u6539\u3002\u81f3\u4eca\uff0c\u5fae\u4fe1\u540e\u53f0\u7edd\u5927\u90e8\u5206\u670d\u52a1\u90fd\u5df2\u662f\u591a\u8fdb\u7a0b\u6216\u591a\u7ebf\u7a0b\u534f\u7a0b\u6a21\u578b\uff0c\u5e76\u53d1\u80fd\u529b\u76f8\u6bd4\u4e4b\u524d\u6709\u4e86\u8d28\u7684\u63d0\u5347\uff0c\u800clibco\u4e5f\u6210\u4e3a\u4e86\u5fae\u4fe1\u540e\u53f0\u6846\u67b6\u7684\u57fa\u77f3\u3002 \u3000\u3000libco\u6846\u67b6 \u3000\u3000libco\u5728\u6846\u67b6\u5206\u4e3a\u4e09\u5c42\uff0c\u5206\u522b\u662f\u63a5\u53e3\u5c42\u3001\u7cfb\u7edfhook\u5c42\u4ee5\u53ca\u5c42\u3002 \u3000\u3000\u540c\u6b65\u98ce\u683cAPI\u7684\u5904\u7406 \u3000\u3000\u5bf9\u4e8e\u540c\u6b65\u98ce\u683c\u7684API\uff0c\u4e3b\u8981\u662f\u540c\u6b65\u7684\u7f51\u7edc\u8c03\u7528\uff0clibco\u7684\u9996\u8981\u4efb\u52a1\u662f\u6d88\u9664\u8fd9\u4e9b\u7b49\u5f85\u5bf9\u8d44\u6e90\u7684\u5360\u7528\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u5e76\u53d1\u6027\u80fd\u3002\u4e00\u4e2a\u5e38\u89c4\u7684\u7f51\u7edc\u540e\u53f0\u670d\u52a1\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u7ecf\u5386connect\u3001write\u3001read\u7b49\u6b65\u9aa4\uff0c\u5b8c\u6210\u4e00\u6b21\u5b8c\u6574\u7684\u7f51\u7edc\u4ea4\u4e92\u3002\u5f53\u540c\u6b65\u7684\u8c03\u7528\u8fd9\u4e9bAPI\u7684\u65f6\u5019\uff0c\u6574\u4e2a\u7ebf\u7a0b\u4f1a\u56e0\u4e3a\u7b49\u5f85\u7f51\u7edc\u4ea4\u4e92\u800c\u6302\u8d77\u3002 \u3000\u3000\u867d\u7136\u540c\u6b65\u7f16\u7a0b\u98ce\u683c\u7684\u5e76\u53d1\u6027\u80fd\u5e76\u4e0d\u597d\uff0c\u4f46\u662f\u5b83\u5177\u6709\u4ee3\u7801\u903b\u8f91\u6e05\u6670\u3001\u6613\u4e8e\u7f16\u5199\u7684\u4f18\u70b9\uff0c\u5e76\u53ef\u652f\u6301\u4e1a\u52a1\u5feb\u901f\u8fed\u4ee3\u654f\u6377\u5f00\u53d1\u3002\u4e3a\u4e86\u7ee7\u7eed\u4fdd\u6301\u540c\u6b65\u7f16\u7a0b\u7684\u4f18\u70b9\uff0c\u5e76\u4e14\u4e0d\u9700\u4fee\u6539\u7ebf\u4e0a\u5df2\u6709\u7684\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\uff0clibco\u521b\u65b0\u5730\u63a5\u7ba1\u4e86\u7f51\u7edc\u8c03\u7528\u63a5\u53e3(Hook)\uff0c\u628a\u534f\u7a0b\u7684\u8ba9\u51fa\u4e0e\u6062\u590d\u4f5c\u4e3a\u5f02\u6b65\u7f51\u7edcIO\u4e2d\u7684\u4e00\u6b21\u4e8b\u4ef6\u6ce8\u518c\u4e0e\u56de\u8c03\u3002\u5f53\u4e1a\u52a1\u5904\u7406\u9047\u5230\u540c\u6b65\u7f51\u7edc\u8bf7\u6c42\u7684\u65f6\u5019\uff0clibco\u5c42\u4f1a\u628a\u672c\u6b21\u7f51\u7edc\u8bf7\u6c42\u6ce8\u518c\u4e3a\u5f02\u6b65\u4e8b\u4ef6\uff0c\u672c\u534f\u7a0b\u8ba9\u51faCPU\u5360\u7528\uff0cCPU\u4ea4\u7ed9\u534f\u7a0b\u6267\u884c\u3002libco\u4f1a\u5728\u7f51\u7edc\u4e8b\u4ef6\u53d1\u751f\u6216\u8005\u8d85\u65f6\u7684\u65f6\u5019\uff0c\u81ea\u52a8\u7684\u6062\u590d\u534f\u7a0b\u6267\u884c\u3002 \u3000\u3000\u5927\u90e8\u5206\u540c\u6b65\u98ce\u683c\u7684API\u6211\u4eec\u90fd\u901a\u8fc7Hook\u7684\u65b9\u6cd5\u6765\u63a5\u7ba1\u4e86\uff0clibco\u4f1a\u5728\u6070\u5f53\u7684\u65f6\u673a\u8c03\u5ea6\u534f\u7a0b\u6062\u590d\u6267\u884c\u3002 \u3000\u3000\u5343\u4e07\u7ea7\u534f\u7a0b\u652f\u6301\u3000\u3000libco\u9ed8\u8ba4\u662f\u6bcf\u4e00\u4e2a\u534f\u7a0b\u72ec\u4eab\u4e00\u4e2a\u8fd0\u884c\u6808\uff0c\u5728\u534f\u7a0b\u521b\u5efa\u7684\u65f6\u5019\uff0c\u4ece\u5806\u5185\u5b58\u5206\u914d\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u4f5c\u4e3a\u8be5\u534f\u7a0b\u7684\u8fd0\u884c\u6808\u3002\u5982\u679c\u6211\u4eec\u7528\u4e00\u4e2a\u534f\u7a0b\u5904\u7406\u524d\u7aef\u7684\u4e00\u4e2a\u63a5\u5165\u8fde\u63a5\uff0c\u90a3\u5bf9\u4e8e\u4e00\u4e2a\u6d77\u91cf\u63a5\u5165\u670d\u52a1\u6765\u8bf4\uff0c\u6211\u4eec\u7684\u670d\u52a1\u7684\u5e76\u53d1\u4e0a\u9650\u5c31\u5f88\u5bb9\u6613\u53d7\u9650\u4e8e\u5185\u5b58\u3002\u4e3a\u6b64\uff0clibco\u4e5f\u63d0\u4f9b\u4e86stackless\u7684\u534f\u7a0b\u5171\u4eab\u6808\u6a21\u5f0f\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u82e5\u5e72\u4e2a\u534f\u7a0b\u5171\u4eab\u540c\u4e00\u4e2a\u8fd0\u884c\u6808\u3002\u540c\u4e00\u4e2a\u5171\u4eab\u6808\u4e0b\u7684\u534f\u7a0b\u95f4\u5207\u6362\u7684\u65f6\u5019\uff0c\u9700\u8981\u628a\u5f53\u524d\u7684\u8fd0\u884c\u6808\u5185\u5bb9\u62f7\u8d1d\u5230\u534f\u7a0b\u7684\u79c1\u6709\u5185\u5b58\u4e2d\u3002\u4e3a\u4e86\u51cf\u5c11\u8fd9\u79cd\u5185\u5b58\u62f7\u8d1d\u6b21\u6570\uff0c\u5171\u4eab\u6808\u7684\u5185\u5b58\u62f7\u8d1d\u53ea\u53d1\u751f\u5728\u4e0d\u540c\u534f\u7a0b\u95f4\u7684\u5207\u6362\u3002\u5f53\u5171\u4eab\u6808\u7684\u5360\u7528\u8005\u4e00\u76f4\u6ca1\u6709\u6539\u53d8\u7684\u65f6\u5019\uff0c\u5219\u4e0d\u9700\u8981\u62f7\u8d1d\u8fd0\u884c\u6808\u3002 \u3000\u3000libco\u534f\u7a0b\u7684\u5171\u4eab\u534f\u7a0b\u6808\u6a21\u5f0f\u4f7f\u5f97\u5355\u673a\u5f88\u5bb9\u6613\u63a5\u5165\u5343\u4e07\u8fde\u63a5\uff0c\u53ea\u9700\u521b\u5efa\u8db3\u591f\u591a\u7684\u534f\u7a0b\u5373\u53ef\u3002\u6211\u4eec\u901a\u8fc7libco\u5171\u4eab\u6808\u6a21\u5f0f\u521b\u5efa1\u5343\u4e07\u7684\u534f\u7a0b(E5-2670 v3 @ 2.30GHz * 2, 128G\u5185\u5b58)\uff0c\u6bcf10\u4e07\u4e2a\u534f\u7a0b\u5171\u4eab\u7684\u4f7f\u7528128k\u5185\u5b58\uff0c\u6574\u4e2a\u7a33\u5b9a\u670d\u52a1\u7684\u65f6\u5019\u603b\u5185\u5b58\u6d88\u8017\u5927\u6982\u4e3a66G\u3002\u3000\u3000\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u3000\u3000\u591a\u8fdb\u7a0b\u7a0b\u5e8f\u6539\u9020\u4e3a\u591a\u7ebf\u7a0b\u7a0b\u5e8f\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u7528thread\u6765\u5bf9\u5168\u5c40\u53d8\u91cf\u8fdb\u884c\u5feb\u901f\u4fee\u6539\uff0c\u800c\u5728\u534f\u7a0b\u73af\u5883\u4e0b\uff0c\u6211\u4eec\u521b\u9020\u4e86\u534f\u7a0b\u53d8\u91cfROUTINE_VAR\uff0c\u6781\u5927\u7b80\u5316\u4e86\u534f\u7a0b\u7684\u6539\u9020\u5de5\u4f5c\u91cf\u3002\u3000\u3000\u56e0\u4e3a\u534f\u7a0b\u5b9e\u8d28\u4e0a\u662f\u7ebf\u7a0b\u5185\u4e32\u884c\u6267\u884c\u7684\uff0c\u6240\u4ee5\u5f53\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u6709\u91cd\u5165\u7684\u95ee\u9898\u3002\u6bd4\u5982\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2athread\u7684\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u539f\u672c\u662f\u5e0c\u671b\u6bcf\u4e00\u4e2a\u6267\u884c\u903b\u8f91\u72ec\u4eab\u8fd9\u4e2a\u53d8\u91cf\u7684\u3002\u4f46\u5f53\u6211\u4eec\u7684\u6267\u884c\u73af\u5883\u8fc1\u79fb\u5230\u534f\u7a0b\u4e86\u4e4b\u540e\uff0c\u540c\u4e00\u4e2a\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u534f\u7a0b\u4f1a\u64cd\u4f5c\u5b83\uff0c\u8fd9\u5c31\u5bfc\u81f4\u4e86\u53d8\u91cf\u51b2\u5165\u7684\u95ee\u9898\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5728\u505alibco\u5f02\u6b65\u5316\u6539\u9020\u7684\u65f6\u5019\uff0c\u628a\u5927\u90e8\u5206\u7684\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\u6539\u6210\u4e86\u534f\u7a0b\u7ea7\u79c1\u6709\u53d8\u91cf\u3002\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u5177\u6709\u8fd9\u6837\u7684\u7279\u6027\uff1a\u5f53\u4ee3\u7801\u8fd0\u884c\u5728\u591a\u7ebf\u7a0b\u975e\u534f\u7a0b\u73af\u5883\u4e0b\u65f6\uff0c\u8be5\u53d8\u91cf\u662f\u7ebf\u7a0b\u79c1\u6709\u7684;\u5f53\u4ee3\u7801\u8fd0\u884c\u5728\u534f\u7a0b\u73af\u5883\u7684\u65f6\u5019\uff0c\u6b64\u53d8\u91cf\u662f\u534f\u7a0b\u79c1\u6709\u7684\u3002\u5e95\u5c42\u7684\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u4f1a\u8fd0\u884c\u73af\u5883\u7684\u5224\u65ad\u5e76\u6b63\u786e\u8fd4\u56de\u6240\u9700\u7684\u503c\u3002\u3000\u3000\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u5bf9\u4e8e\u73b0\u6709\u73af\u5883\u540c\u6b65\u5230\u5f02\u6b65\u5316\u6539\u9020\u8d77\u4e86\u4e3e\u8db3\u8f7b\u91cd\u7684\u4f5c\u7528\uff0c\u540c\u65f6\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u65b9\u4fbf\u7684\u65b9\u6cd5\u5b9a\u4e49\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u7b80\u5355\u5230\u53ea\u9700\u4e00\u884c\u58f0\u660e\u4ee3\u7801\u5373\u53ef\u3002\u3000\u3000gethostbyname\u7684Hook\u65b9\u6cd5\u3000\u3000\u5bf9\u4e8e\u73b0\u7f51\u670d\u52a1\uff0c\u6709\u53ef\u80fd\u9700\u8981\u901a\u8fc7\u7cfb\u7edf\u7684gethostbyname API\u63a5\u53e3\u53bbDNS\u83b7\u53d6\u771f\u5b9e\u5730\u5740\u3002\u6211\u4eec\u5728\u534f\u7a0b\u5316\u6539\u9020\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u6211\u4eechook\u7684socket\u65cf\u51fd\u6570\u5bf9gethostbyname\u4e0d\u9002\u7528\uff0c\u5f53\u4e00\u4e2a\u534f\u7a0b\u8c03\u7528\u4e86gethostbyname\u65f6\u4f1a\u540c\u6b65\u7b49\u5f85\u7ed3\u679c\uff0c\u8fd9\u5c31\u5bfc\u81f4\u4e86\u540c\u7ebf\u7a0b\u5185\u7684\u5176\u5b83\u534f\u7a0b\u88ab\u5ef6\u65f6\u6267\u884c\u3002\u6211\u4eec\u5bf9glibc\u7684gethostbyname\u6e90\u7801\u8fdb\u884c\u4e86\u7814\u7a76\uff0c\u53d1\u73b0hook\u4e0d\u751f\u6548\u4e3b\u8981\u662f\u7531\u4e8eglibc\u5185\u90e8\u662f\u5b9a\u4e49\u4e86poll\u65b9\u6cd5\u6765\u7b49\u5f85\u4e8b\u4ef6\uff0c\u800c\u4e0d\u662f\u901a\u7528\u7684poll\u65b9\u6cd5;\u540c\u65f6glibc\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u4e0d\u540c\u534f\u7a0b\u7684\u5207\u6362\u53ef\u80fd\u4f1a\u91cd\u5165\u5bfc\u81f4\u6570\u636e\u4e0d\u51c6\u786e\u3002\u6700\u7ec8gethostbyname\u534f\u7a0b\u5f02\u6b65\u5316\u662f\u901a\u8fc7Hook poll\u65b9\u6cd5\u4ee5\u53ca\u5b9a\u4e49\u534f\u7a0b\u79c1\u6709\u53d8\u91cf\u89e3\u51b3\u7684\u3002\u3000\u3000gethostbyname\u662fglibc\u63d0\u4f9b\u7684\u540c\u6b65\u67e5\u8be2dns\u63a5\u53e3\uff0c\u4e1a\u754c\u8fd8\u6709\u5f88\u591a\u4f18\u79c0\u7684gethostbyname\u7684\u5f02\u6b65\u5316\u89e3\u51b3\u65b9\u6848\uff0c\u4f46\u662f\u8fd9\u4e9b\u5b9e\u73b0\u90fd\u9700\u8981\u5f15\u5165\u4e00\u4e2a\u7b2c\u4e09\u65b9\u5e93\u5e76\u4e14\u8981\u6c42\u5e95\u5c42\u63d0\u4f9b\u5f02\u6b65\u56de\u8c03\u901a\u77e5\u673a\u5236\u3002libco\u901a\u8fc7hook\u65b9\u6cd5\uff0c\u5728\u4e0d\u4fee\u6539glibc\u6e90\u7801\u7684\u524d\u63d0\u4e0b\u5b9e\u73b0\u4e86\u7684gethostbyname\u7684\u5f02\u6b65\u5316\u3002\u3000\u3000\u534f\u7a0b\u4fe1\u53f7\u91cf\u3000\u3000\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\uff0c\u6211\u4eec\u4f1a\u6709\u7ebf\u7a0b\u95f4\u540c\u6b65\u7684\u9700\u6c42\uff0c\u6bd4\u5982\u4e00\u4e2a\u7ebf\u7a0b\u7684\u6267\u884c\u9700\u8981\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u7684\u4fe1\u53f7\uff0c\u5bf9\u4e8e\u8fd9\u79cd\u9700\u6c42\uff0c\u6211\u4eec\u901a\u5e38\u662f\u4f7f\u7528pthread_signal \u6765\u89e3\u51b3\u7684\u3002\u5728libco\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u534f\u7a0b\u4fe1\u53f7\u91cfco_signal\u7528\u4e8e\u5904\u7406\u534f\u7a0b\u95f4\u7684\u5e76\u53d1\u9700\u6c42\uff0c\u4e00\u4e2a\u534f\u7a0b\u53ef\u4ee5\u901a\u8fc7co_cond_signal\u4e0eco_cond_broadcast\u6765\u51b3\u5b9a\u901a\u77e5\u4e00\u4e2a\u7b49\u5f85\u7684\u534f\u7a0b\u6216\u8005\u5524\u9192\u6240\u6709\u7b49\u5f85\u534f\u7a0b\u3002\u3000\u3000\u603b\u7ed3\u3000\u3000libco\u662f\u4e00\u4e2a\u9ad8\u6548\u7684c\/c++\u534f\u7a0b\u5e93\uff0c\u63d0\u4f9b\u4e86\u5b8c\u5584\u7684\u534f\u7a0b\u7f16\u7a0b\u63a5\u53e3\u3001\u5e38\u7528\u7684Socket\u65cf\u51fd\u6570Hook\u7b49\uff0c\u4f7f\u5f97\u4e1a\u52a1\u53ef\u7528\u540c\u6b65\u7f16\u7a0b\u6a21\u578b\u5feb\u901f\u8fed\u4ee3\u5f00\u53d1\u3002\u968f\u7740\u51e0\u5e74\u6765\u7684\u7a33\u5b9a\u8fd0\u884c\uff0clibco\u4f5c\u4e3a\u5fae\u4fe1\u540e\u53f0\u6846\u67b6\u7684\u57fa\u77f3\u53d1\u6325\u4e86\u4e3e\u8db3\u8f7b\u91cd\u7684\u4f5c\u7528\u3002 \u3010\u76f8\u5173\u63a8\u8350\u3011 1. 2. \u4ee5\u4e0a\u5c31\u662f\u6559\u4f60libco\u662f\u5982\u4f55\u652f\u6491\u5de8\u5927\u6570\u636e\u4fe1\u606f\u91cf\u7684\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-30071","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=30071"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30071\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=30071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=30071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=30071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}