{"id":200504,"date":"2020-11-15T14:35:23","date_gmt":"2020-11-15T06:35:23","guid":{"rendered":"http:\/\/4563.org\/?p=200504"},"modified":"2020-11-15T14:35:23","modified_gmt":"2020-11-15T06:35:23","slug":"golang-%e5%b0%b1%e6%b2%a1%e6%9c%89%e6%8f%90%e4%be%9b%e4%b8%80%e4%b8%aa%e5%8f%af%e4%bb%a5%e8%a2%ab-cancel-%e7%9a%84-read-%e6%8e%a5%e5%8f%a3%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=200504","title":{"rendered":"golang \u5c31\u6ca1\u6709\u63d0\u4f9b\u4e00\u4e2a\u53ef\u4ee5\u88ab cancel \u7684 read \u63a5\u53e3\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  golang \u5c31\u6ca1\u6709\u63d0\u4f9b\u4e00\u4e2a\u53ef\u4ee5\u88ab cancel \u7684 read \u63a5\u53e3\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : howellz <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6b63\u5728\u4f7f\u7528<code>net.Conn.Read()<\/code>\uff0c\u53d1\u73b0\u8fd9\u8d27\u9664\u4e86<code>net.close()<\/code>\uff0c\u4f3c\u4e4e\u6ca1\u6709\u5176\u4ed6\u529e\u6cd5\u628a<code>read()<\/code>\u51fd\u6570\u7ed9\u4e3b\u52a8\u8fd4\u56de\u3002<\/p>\n<p>\u8fd9\u6837\u4e5f\u592a\u626f\u6de1\u4e86\u5427\uff0c\u81f3\u5c11\u63d0\u4f9b\u4e2a<code>select readset<\/code>\u6216\u8005<code>epoll readset<\/code>\uff0c\u8fd9\u6837\u7c7b\u4f3c\u7684\u64cd\u4f5c\u5427\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>16<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4282003\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3a\u5565\u8981\u53d6\u6d88\uff1f\u662f\u4f60\u7406\u89e3\u6709\u95ee\u9898\u5427\uff0c\u9664\u975e\u8fde\u63a5\u5173\u95ed\uff0c\u5426\u5219\u786e\u5b9e\u65e0\u9700\u8fd4\u56de\u554a\uff0c\u5982\u679c\u4f60\u6709\u5176\u4ed6\u4e8b\u60c5\u8981\u5e72\uff0c\u90a3\u4e48\u518d\u5f00\u4e2a\u643a\u7a0b\u5c31\u662f\u4e86\u554a\uff0c\u5982\u679c\u9700\u8981\u8bfb\u8d85\u65f6\u5565\u7684\uff0c\u8fd9\u4e2a\u8d85\u65f6\u672c\u6765\u5c31\u9700\u8981\u65b0\u5f00\u534f\u7a0b\u6765\u5e72\u7684\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282004\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lwch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u4ee5\u8bbe timeout                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282005\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nuk <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u662f\u6709 setdeadline \u5565\u7684\u4e48\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282006\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : howellz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lwch @nuk setdeadline<br \/>timeout \u6bd5\u7adf\u662f\u4e00\u79cd\u8f6e\u8be2\u673a\u5236\uff0c\u592a\u957f\u54cd\u5e94\u53d8\u5dee\uff0c\u592a\u77ed\u5f00\u9500\u53d8\u5927\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282007\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lwch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             io.Read \u7684\u963b\u585e\u64cd\u4f5c\u672c\u6765\u5c31\u662f\u4e3a\u4e86\u8ba9\u51fa\u65f6\u95f4\u7247\u7ed9\u522b\u7684\u534f\u7a0b\u505a\u8c03\u5ea6\u7528\u7684\uff0c\u6240\u4ee5 go \u91cc\u9762\u4e0d\u5b58\u5728 noblock \u7684 io \u64cd\u4f5c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282008\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : howellz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sujin190 \u53d6\u6d88\u662f\u4e00\u4e2a\u592a\u5e38\u89c1\u7684\u573a\u666f\u4e86\uff0c\u6700\u6781\u7aef\u7684\u5c31\u6211\u60f3\u4e2d\u6b62\u8fd9\u4e2a\u643a\u7a0b\uff0c\u4f46\u662f\u6211\u73b0\u5728\u4e0d\u80fd\u5173\u95ed\u8fd9\u4e2a conn \u3002\u5f53\u7136\u60a8\u4e5f\u8bb8\u4f1a\u7ee7\u7eed\u8d28\u7591\u6211\u4e3a\u4ec0\u4e48\u8981\u5173\u95ed\u8fd9\u4e2a\u643a\u7a0b\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282009\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nuk <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @howellz syscall \u53ef\u4ee5 select \u4e5f\u53ef\u4ee5 epoll\uff0c\u4e2d\u65ad\u534f\u7a0b\u7684\u8bdd\u76f4\u63a5 close \u6389 read \u5c31\u4f1a\u9000\u51fa\u554a\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282010\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mepwang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7ed9\u5b83\u7684 socket \u53d1\u70b9\u4e1c\u897f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282011\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : icexin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5728\u53e6\u5916\u4e00\u4e2a\u5730\u65b9\u8c03\u7528 conn. SetReadDeadline\uff0c\u53c2\u6570\u8bbe\u7f6e\u4e00\u4e2a\u8ddd\u79bb\u5f88\u77ed\u7684 deadline \u5c31\u53ef\u4ee5\u7acb\u9a6c\u8ba9 Read \u8fd4\u56de\u9519\u8bef\u3002<br \/>\u6bd4\u5982 conn.SetReadDeadline(time.Now())                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282012\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : howellz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @icexin \u8fd9\u542c\u8d77\u6765\u4e0d\u9519\uff0c\u6211\u770b\u4e0b\u9519\u8bef\u662f\u5426\u4f1a\u6709 confuse \u7684\u5730\u65b9\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282013\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jokefun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bfb\u4e86\u4e00\u534a cancel \u4e86\u4e4b\u540e\u8fd9\u4e2a net.Conn \u600e\u4e48\u529e\u5462\uff1f\u6ca1\u8bfb\u5b8c\u7684 bytes \u4e0b\u6b21\u63a5\u7740\u8bfb\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282014\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lxz6597863 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u628a chan \u548c net.Conn \u5c01\u88c5\u4e2a Reader                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282015\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @howellz #6 \u8fd9\u4e2a\u573a\u666f\u786e\u5b9e\u6709\uff0c\u4f46\u662f\u4e0d\u662f\u8fd9\u4e48\u7528\u7684\uff0c\u6309\u4f60\u8fd9\u4e48\u8bf4\u5176\u5b9e\u5c31\u662f\u6570\u636e\u5904\u7406\u903b\u8f91\u548c\u8bfb\u5199\u903b\u8f91\u88ab\u5206\u79bb\u4e86\uff0c\u6309 go \u7684\u8bbe\u8ba1\u548c\u4e60\u60ef\u7528\u6cd5\uff0c\u90a3\u4e48\u5e94\u8be5\u662f read \u8fde\u63a5\u8fd9\u4e2a\u534f\u7a0b\u53ea\u8d1f\u8d23\u5904\u7406\u8bfb\uff0c\u8bfb\u5904\u7406\u7684\u6570\u636e\u901a\u8fc7 channl \u4f20\u7ed9\u53e6\u5916\u903b\u8f91\u5904\u7406\u534f\u7a0b\u6765\u5b8c\u6210\uff0c\u90a3\u4e48\u8fd9\u4e2a\u534f\u7a0b\u624d\u5e94\u8be5\u4f9d\u636e\u662f\u5426\u8d85\u65f6\u7b49\u5176\u4ed6\u60c5\u51b5\u89c9\u5f97\u662f\u5426\u53d6\u6d88\u5904\u7406\uff0c\u8bfb\u5199\u672c\u6765\u5c31\u5e94\u8be5\u548c\u8fde\u63a5\u7ed1\u5b9a\uff0c\u800c\u6570\u636e\u903b\u8f91\u5904\u7406\u624d\u5e94\u8be5\u8003\u8651\u4e2d\u9014\u9000\u51fa\uff0c\u8fd9\u624d\u662f\u7b26\u5408 go \u7684\u4e60\u60ef\u5904\u7406\u65b9\u5f0f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282016\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wellsc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             gmp \u8fd9\u73a9\u610f\u513f\u5c31\u662f\u628a\u534f\u7a0b schedulder \u5c01\u88c5\u8fdb\u4e86\u4e00\u4e2a\u6846\u67b6\u91cc\u9762\uff0c\u7ed9\u534f\u7a0b\u5c01\u88c5\u6846\u67b6\u7684\u8bed\u8a00\u9664\u4e86 golang \u8fd8\u6709 erlang \u7cfb\uff0c\u53cd\u6b63\u6846\u67b6\u6709\u6846\u67b6\u7684\u597d\u5904\uff0c\u4e5f\u6709\u6846\u67b6\u7684\u574f\u5904\uff0c\u574f\u5904\u5c31\u662f\u81ea\u5df1\u8c03\u5ea6\u8d77\u6765\u6709\u70b9\u9ebb\u70e6\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282017\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             conn.SetReadDeadline(time.Now().Add(-time.Hour))                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4282018\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : howellz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sujin190 \u60a8\u8bbe\u8ba1\u7684\u573a\u666f\u4e0d\u662f\u6ca1\u6709\u8003\u8651\u8fc7.\u4f46\u8fd9\u79cd\u5f02\u6b65\u4f20\u9012\u6d88\u606f\u7684\u65b9\u5f0f\uff0c\u9700\u8981\u591a\u6b21\u5206\u914d`buf []byte`\u3002\u5982\u679c\u662f\u540c\u6b65\u5904\u7406\uff0c\u5728`read`\u540e\u5904\u7406\u5b8c\u4e86\uff0c`buf`\u53ef\u4ee5\u8ba9\u4e0b\u4e00\u6b21`read`\u91cd\u7528\u3002\u5728\u8d1f\u8377\u975e\u5e38\u5927\u7684\u573a\u666f\uff0c\u5c3d\u91cf\u5c11\u62f7\u8d1d\u3001\u5c11\u5206\u914d\u3001\u5c11\u4f20\u9012\u662f\u6211\u9700\u8981\u8003\u8651\u7684\u4e00\u4e2a\u91cd\u8981\u95ee\u9898\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>golang \u5c31\u6ca1\u6709\u63d0\u4f9b\u4e00\u4e2a\u53ef\u4ee5\u88ab&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200504"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200504"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/200504\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200504"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}