{"id":1658,"date":"2015-01-03T07:03:07","date_gmt":"2015-01-02T23:03:07","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=1658"},"modified":"2015-01-03T07:03:07","modified_gmt":"2015-01-02T23:03:07","slug":"%e3%80%90diocp3-%e8%af%b4%e6%98%8e%e4%b9%a6%e3%80%91%e5%85%b3%e4%ba%8e%e6%9c%8d%e5%8a%a1%e7%ab%af%e7%9a%84keepalive%e5%b1%9e%e6%80%a7%e5%bf%83%e8%b7%b3","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=1658","title":{"rendered":"\u3010DIOCP3-\u8bf4\u660e\u4e66\u3011\u5173\u4e8e\u670d\u52a1\u7aef\u7684KeepAlive\u5c5e\u6027(\u5fc3\u8df3)"},"content":{"rendered":"<p>DIOCP3\u4e2d\u670d\u52a1\u7aef(IocpTcpServer)\u4e2d\u63d0\u4f9b\u4e00\u4e2aKeepAlive\u5c5e\u6027\uff0c\u4e4b\u524d\u7248\u672c\u9ed8\u8ba4\u5f00\u542f\uff0c2014-12-30\u4e4b\u540e\u7684\u7248\u672c\u9ed8\u8ba4\u662f\u5173\u95ed\u7684\u3002<\/p>\n<p>\u9996\u5148\u8981\u641e\u660e\u767dKeepAlive\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff0c\u670d\u52a1\u7aef\u5f00\u542fKeepAlive\u540e\u5728\u5efa\u7acb\u8fde\u63a5\u7684\u65f6\u5019\u4f1a\u8bbe\u7f6eSocket\u7684SO_KeepAlive\u9009\u9879<\/p>\n<p>&nbsp;<\/p>\n<p>MSDN\u7684\u89e3\u91ca\u662f\u8fd9\u6837\u7684:<\/p>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ee470551(v=vs.85).aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ee470551(v=vs.85).aspx<\/a><\/p>\n<h3>SO_KEEPALIVE socket option<\/h3>\n<p>The <strong>SO_KEEPALIVE<\/strong> socket option is designed to allow an application to enable keep-alive packets for a socket connection.  <\/p>\n<p>SO_KEEPALIVE \u5957\u63a5\u5b57\u9009\u9879\u662f\u88ab\u8bbe\u8ba1\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u5bf9\u4e00\u4e2a\u5957\u63a5\u5b57\u8fde\u63a5\u5f00\u542fkeep-alive\u5305(\u7ffb\u5f97\u4e0d\u597d\uff0c\u610f\u601d\u57fa\u672c\u4e0a\u5bf9\u4e86)  <\/p>\n<p>&nbsp; <\/p>\n<p><font color=\"#ff0000\">\u5f00\u542f\u540e\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u5173\u95ed(\u6216\u8005\u7f51\u7edc\u5f02\u5e38)\u7b49\u60c5\u51b5\uff0c\u670d\u52a1\u7aef\u5c31\u4f1a\u9a6c\u4e0a\u77e5\u9053\u3002\u8fd9\u6837\u670d\u52a1\u7aef\u5c31\u4f1a\u65ad\u5f00\u8be5\u8fde\u63a5\u3002\u4f46\u662f\u8be5\u9009\u9879\u5e76\u4e0d\u662f\u6240\u6709\u7684\u73af\u5883\u4e0b\u9762\u90fd\u80fd\u8fd0\u4f5c\u7684\u5f88\u597d\uff0c\u636e\u6211\u6240\u77e5\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u662fAndriod\uff0c\u5c31\u4e0d\u884c\uff0c\u8fd8\u6709\u4e00\u4e9b\u786c\u4ef6\u8bbe\u5907\uff0c\u4e5f\u662f\u4e0d\u884c\u7684\uff0c\u6240\u4ee5\u6211\u6539\u6210\u9ed8\u8ba4\u662f\u5173\u95ed\u72b6\u6001\u3002<\/font>  <\/p>\n<p><font color=\"#ff0000\">\u5173\u95ed\u540e\uff0c\u95ee\u9898\u5c31\u6765\u4e86\uff0c\u5ba2\u6237\u7aef\u5982\u679c\u65ad\u7ebf\uff0c\u53ef\u80fd\u670d\u52a1\u5668\u7aef\u5c31\u65e0\u6cd5\u53ca\u65f6\u53d1\u73b0\uff0c\u8fd9\u6837\u670d\u52a1\u7aef\u4f1a\u51fa\u73b0\u5f88\u591a\u6b7b\u94fe\u63a5\u3002\u53ea\u6709\u5f53\u8fdb\u884c\u5bf9socket\u8fdb\u884c\u64cd\u4f5c(\u6bd4\u5982\u53d1\u9001\u6570\u636esocket.send)\u65f6\u9047\u5230\u5f02\u5e38\u65f6\u624d\u4f1a\u53d1\u73b0\u8be5\u8fde\u63a5\u65e0\u6548\uff0c\u7136\u540e\u8fdb\u884c\u65ad\u5f00\u3002<\/font>  <\/p>\n<p>\u4e00\u822c\u5b9e\u9645\u5e94\u7528\uff0c\u5982\u679c\u8981\u4fdd\u6301\u957f\u8fde\u63a5\uff0c\u53ef\u4ee5\u5728\u5ba2\u6237\u7aef\u53d1\u9001\u5fc3\u8df3\u6570\u636e\u5305(\u8fd9\u4e2a\u6570\u636e\u5305\u56e0\u4e3a\u8981\u6839\u636e\u81ea\u5df1\u5b9a\u4e49\u7684\u534f\u8bae\u683c\u5f0f\u8fdb\u884c\u53d1\u9001\uff0c\u6240\u4ee5\u65e0\u6cd5\u5728\u5e95\u5c42\u5b8c\u6210\u3002\uff09\u7136\u540e\u5728\u670d\u52a1\u7aef\u505a\u8d85\u65f6\u68c0\u6d4b\uff0c\u5982\u679c\u8d85\u8fc7\u4e00\u5b9a\u7684\u65f6\u95f4(\u8fd9\u4e2a\u65f6\u95f4\u81ea\u5df1\u534f\u5b9a)\u5c31\u628a\u8be5\u8fde\u63a5\u4e3b\u52a8T\u6389\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DIOCP3\u4e2d\u670d\u52a1\u7aef(IocpTcpSe [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[43],"tags":[285,287,286],"class_list":["post-1658","post","type-post","status-publish","format-standard","hentry","category-diocp3","tag-delphi-iocp","tag-keepalive","tag-286"],"views":3507,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1658"}],"version-history":[{"count":1,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1658\/revisions"}],"predecessor-version":[{"id":1659,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/1658\/revisions\/1659"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}