{"id":3458,"date":"2011-10-28T11:42:42","date_gmt":"2011-10-28T03:42:42","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3458"},"modified":"2011-10-28T11:44:23","modified_gmt":"2011-10-28T03:44:23","slug":"recv%e4%b8%ad%e7%9a%84flags%e5%8f%82%e6%95%b0","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3458","title":{"rendered":"recv()\u4e2d\u7684flags\u53c2\u6570"},"content":{"rendered":"<p>\u4ece\u6628\u5929\u4e0a\u5348\u523010\u5206\u949f\u4e4b\u524d\u90fd\u5728\u8c03\u8bd5\u7a0b\u5e8f\u4e2d\u7684\u4e00\u4e2aBUG\uff0c\u95ee\u9898\u7684\u7cbe\u7b80\u63cf\u8ff0\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><strong>\u4e00\u4e2a\u7ecf\u5178\u7684C\/S\u6a21\u578b\uff0c\u5ba2\u6237\u7aef\u5f02\u6b65\u7684\u5411\u670d\u52a1\u5668\u7aef\u53d1\u9001\u4e00\u6761\u6307\u4ee4\uff0c\u670d\u52a1\u5668\u7aef\u63a5\u6536\u5230\u8be5\u6307\u4ee4\u540e\u5411\u5ba2\u6237\u7aef\u53d1\u9001\u4e00\u4e2aint\u578b\u6570\u636elen\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u91cd\u590d\u7684\u6b21\u6570\u662f\u968f\u673a\u7684\uff0c\u5e76\u4e14\u6709\u65f6\u5019\u64cd\u4f5c\u9891\u7e41\u3002<\/strong><\/p>\n<p>\u5bf9\u4e8e\u4e0a\u8ff0\u8fc7\u7a0b\u7684\u5b9e\u73b0\u5e76\u4e0d\u56f0\u96be\uff0c\u5728\u672c\u5730\u6d4b\u8bd5C\/S\u7aef\u4e5f\u5e76\u65e0\u5f02\u5e38\u3002\u4f46\u662f\u8fdb\u884c\u8fdc\u7a0b\u6d4b\u8bd5\u5c31\u51fa\u73b0\u5f02\u5e38\uff1a\u670d\u52a1\u5668\u7aef\u53d1\u9001\u7684len\u6b63\u5e38\uff0c\u4f46\u662f\u5ba2\u6237\u7aef\u63a5\u6536\u7684\u6570\u636e\u6709\u65f6\u5019\u4f1a\u4e3a0\u3002<\/p>\n<p>\u7ecf\u5386\u4e86\u957f\u65f6\u95f4\u7684\u8c03\u8bd5\u548c\u5206\u6790\u540e\uff0c\u7ec8\u5c06\u95ee\u9898\u9501\u5b9a\u5728recv()\u3002\u8be5\u51fd\u6570\u7684\u539f\u578b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:c\">       #include &lt; sys\/types.h &gt;\r\n       #include &lt; sys\/socket.h &gt;\r\n       ssize_t recv(int sockfd, void *buf, size_t len, int flags);<\/pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u524d\u4e09\u4e2a\u53c2\u6570\u7684\u542b\u4e49\u4e0eread()\u5927\u81f4\u76f8\u540c\uff0c\u53ea\u4e0d\u8fc7recv()\u4e2d\u7684sockfd\u4ee3\u8868\u5957\u63a5\u5b57\u63cf\u8ff0\u7b26\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709flags\u53c2\u6570\uff0c\u4e00\u822c\u88ab\u6307\u5b9a\u4e3a0\u3002\u800c\u6070\u6070\u6b63\u662f\u8fd9\u79cd\u9ed8\u8ba4\u8d4b\u503c\u624d\u5bfc\u81f4\u4e0a\u8ff0\u95ee\u9898\u7684\u4ea7\u751f\uff0c\u8be5\u6807\u5fd7\u53ef\u53d6\u591a\u4e2a\u503c\uff0c\u5176\u4e2d\u4e00\u4e2a\u503c\u4e3aMSG_WAITALL\u3002\u8fd9\u4e2a\u6807\u5fd7\u544a\u77e5\u5185\u6838\u5728\u672a\u8bfb\u5165\u6307\u5b9a\u5b57\u8282len\u5927\u5c0f\u7684\u6570\u636e\u4e4b\u524d\u4e0d\u8981\u5c06recv()\u8fd4\u56de\u3002\u5f53\u4e3a\u8fd9\u4e2aflags\u6307\u5b9a\u4e86\u8be5\u503c\u540e\uff0c\u7ed3\u679c\u6b63\u5e38\u3002\u4e0d\u8fc7\uff0c\u8be5\u51fd\u6570\u8fd8\u662f\u4f1a\u5728\u4e0b\u8ff0\u4e09\u79cd\u60c5\u51b5\u4e0b\u63d0\u524d\u8fd4\u56de\uff1a<\/p>\n<p>1.\u8fde\u63a5\u88ab\u7ec8\u6b62\u6216\u5957\u63a5\u5b57\u53d1\u751f\u5f02\u5e38<\/p>\n<p>2.\u63a5\u6536\u4e86\u4e00\u4e2a\u4e0e\u4e4b\u524d\u7c7b\u578b\u4e0d\u540c\u7684\u6570\u636e<\/p>\n<p>3.\u6355\u83b7\u4e86\u4e00\u4e2a\u4fe1\u53f7<\/p>\n<p>\u8fd9\u4e09\u79cd\u60c5\u51b5\u90fd\u5c5e\u4e8e\u5f02\u5e38\u60c5\u51b5\uff0c\u8ddf\u4e0a\u8ff0\u95ee\u9898\u65e0\u5173\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u6628\u5929\u4e0a\u5348\u523010\u5206\u949f\u4e4b\u524d\u90fd\u5728\u8c03\u8bd5\u7a0b\u5e8f\u4e2d\u7684\u4e00\u4e2aBUG\uff0c\u95ee\u9898\u7684\u7cbe\u7b80\u63cf\u8ff0\u662f\u8fd9\u6837\u7684\uff1a \u4e00\u4e2a\u7ecf\u5178\u7684C\/S\u6a21\u578b\uff0c\u5ba2\u6237\u7aef\u5f02\u6b65 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[208],"tags":[270,209],"class_list":["post-3458","post","type-post","status-publish","format-standard","hentry","category-208","tag-recv","tag-socket"],"views":7641,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=3458"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3458\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3458"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}