{"id":2357,"date":"2011-02-22T19:54:26","date_gmt":"2011-02-22T10:54:26","guid":{"rendered":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=2357"},"modified":"2011-02-22T19:56:00","modified_gmt":"2011-02-22T10:56:00","slug":"%e3%83%8e%e3%83%b3%e3%83%96%e3%83%ad%e3%83%83%e3%82%ad%e3%83%b3%e3%82%b0%e3%82%bd%e3%82%b1%e3%83%83%e3%83%88%e3%81%a7-recv-%e3%81%ab-msg_waitall-%e3%82%92%e6%b8%a1%e3%81%97%e3%81%9f%e5%a0%b4","status":"publish","type":"post","link":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=2357","title":{"rendered":"\u30ce\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u30bd\u30b1\u30c3\u30c8\u3067 recv() \u306b MSG_WAITALL \u3092\u6e21\u3057\u305f\u5834\u5408\u306e\u6319\u52d5"},"content":{"rendered":"<p>BSD\u30bd\u30b1\u30c3\u30c8\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u8a71\u3067\u3059\u304c\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u3092\u30ce\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u306b\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u8aad\u3081\u308b\u30c7\u30fc\u30bf\u304c\u306a\u3044\uff08\u53d7\u4fe1\u30d0\u30c3\u30d5\u30a1\u306b\u30c7\u30fc\u30bf\u304c\u306a\u3044\uff09\u5834\u5408\u306f read() \/ recv() \u304b\u3089 -1 \u304c\u8fd4\u3063\u3066\u304d\u3066\u3001errno \u304c EAGAIN \u306b\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u3002\u4e00\u65b9\u3053\u308c\u3068\u306f\u5225\u306b\u3001\u30bd\u30b1\u30c3\u30c8\u306b\u5bfe\u3057\u3066 recv() \u3059\u308b\u5834\u5408\u3001\u7b2c4\u5f15\u6570\uff08\u30d5\u30e9\u30b0\uff09\u306b MSG_WAITALL \u3092\u6307\u5b9a\u3059\u308b\u3068\u3001\u7b2c3\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u5206\u3060\u3051\u8aad\u3081\u308b\u307e\u3067\u8fd4\u3063\u3066\u304d\u307e\u305b\u3093\uff08\u57fa\u672c\u7684\u306b\u306f\uff09\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u3058\u3083\u3042\u4e21\u65b9\u3084\u308b\u3068\u3069\u3046\u306a\u308b\u306e\uff1f\u3068\u3044\u3046\u308f\u3051\u3067\u4ee5\u4e0b\u306e\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u3002<\/p>\n<pre>#include &lt;sys\/ioctl.h&gt;\r\n#include &lt;sys\/socket.h&gt;\r\n#include &lt;errno.h&gt;\r\n#include &lt;netdb.h&gt;\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n#include &lt;unistd.h&gt;\r\n#include &lt;netinet\/in.h&gt;\r\n\r\nint main(int argc, char **argv)\r\n{\r\n        struct addrinfo *ai;\r\n        int fd;\r\n        int on = 1;\r\n        char buf[1000];\r\n        ssize_t n;\r\n\r\n        getaddrinfo(argv[1], argv[2], NULL, &ai);\r\n        fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);\r\n        ioctl(fd, FIONBIO, &on);\r\n        connect(fd, ai->ai_addr, ai->ai_addrlen);\r\n        sleep(1);\r\n        errno = 0;\r\n        n = recv(fd, buf, 1000, MSG_WAITALL);\r\n        printf(\"ret=%d errno=%d %s\\n\", n, errno, strerror(errno));\r\n\r\n        return 0;\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u9069\u5f53\u306a\u30b5\u30fc\u30d0\u306b\u3064\u306a\u3044\u3067\u52d5\u4f5c\u3092\u898b\u307e\u3059\u3002sleep() \u304c\u631f\u307e\u3063\u3066\u3044\u308b\u306e\u306f\u3001\u53d7\u4fe1\u30d0\u30c3\u30d5\u30a1\u306b\u30c7\u30fc\u30bf\u304c\u6e9c\u307e\u308b\u306e\u3092\u5f85\u3064\u305f\u3081\u3067\u3059\u3002SMTP\u30b5\u30fc\u30d0\u306f\u30b5\u30fc\u30d0\u304b\u3089\u8a71\u3057\u59cb\u3081\u308b\u306e\u3067\u3001\u30c7\u30fc\u30bf\u304c\u6e9c\u307e\u308a\u3001HTTP\u30b5\u30fc\u30d0\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u8a71\u3057\u59cb\u3081\u308b\u306e\u3067\u30c7\u30fc\u30bf\u306f\u6e9c\u307e\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u307e\u305a CentOS 5 (kernel-2.6.18-194.32.1.el5) \u3067\u306e\u5b9f\u884c\u4f8b\u3002<\/p>\n<pre>[umezawa@nyx:pts\/1 ~]$ .\/recv_nonblocking_waitall localhost 25\r\nret=29 errno=0 Success\r\n[umezawa@nyx:pts\/1 ~]$ .\/recv_nonblocking_waitall localhost 80\r\nret=-1 errno=11 Resource temporarily unavailable\r\n[umezawa@nyx:pts\/1 ~]$<\/pre>\n<p>\u3069\u3046\u3084\u3089\u30ce\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u6307\u5b9a\u306e\u307b\u3046\u304c\u300c\u4e00\u65b9\u7684\u306b\u5f37\u3044\u300d\u3088\u3046\u3067\u3001MSG_WAITALL \u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3068\u540c\u3058\u6319\u52d5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e00\u65b9\u3001FreeBSD 8.1-RELEASE \u3067\u306f<\/p>\n<pre>[umezawa@devfreebsd ~]$ .\/recv_nonblocking_waitall localhost 25\r\nret=-1 errno=35 Resource temporarily unavailable\r\n[umezawa@devfreebsd ~]$ .\/recv_nonblocking_waitall nyx.local 80\r\nret=-1 errno=35 Resource temporarily unavailable\r\n[umezawa@devfreebsd ~]$<\/pre>\n<p>\u3068\u306a\u308a\u3001\u30ce\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u306e\u6307\u5b9a\u3068 MSG_WAITALL \u306e\u6307\u5b9a\u304c\u77db\u76fe\u306a\u304f\u7d44\u307f\u5408\u308f\u3055\u3063\u3066\u3044\u308b\u2026\u3064\u307e\u308a\u3001\u6307\u5b9a\u3057\u305f\u5206\u3060\u3051\u8aad\u3081\u306a\u3044\u5834\u5408\u306f\u5373\u5ea7\u306b EAGAIN \u3067\u5931\u6557\u3059\u308b\u3088\u3046\u306b\u898b\u3048\u307e\u3059\u3002<\/p>\n<p>\u7d50\u8ad6\u3068\u3057\u3066\u306f\u300c\u79fb\u690d\u6027\u304c\u306a\u3044\u306e\u3067\u4f7f\u308f\u306a\u3044\u307b\u3046\u304c\u3044\u3044\u300d\u3068\u3044\u3046\u3068\u3053\u308d\u306b\u843d\u3061\u7740\u304d\u305d\u3046\u3067\u3059\u3002\u4ee5\u4e0a\u3001\u8ab0\u5f97\u60c5\u5831\u3067\u3057\u305f\uff08\u3041<\/p>\n","protected":false},"excerpt":{"rendered":"<p>BSD\u30bd\u30b1\u30c3\u30c8\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u8a71\u3067\u3059\u304c\u3002 \u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u3092\u30ce\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0\u306b\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u8aad\u3081\u308b\u30c7\u30fc\u30bf\u304c\u306a\u3044\uff08\u53d7\u4fe1\u30d0\u30c3\u30d5\u30a1\u306b\u30c7\u30fc\u30bf\u304c\u306a\u3044\uff09\u5834\u5408\u306f read() \/ recv() \u304b\u3089 -1 \u304c\u8fd4\u3063\u3066\u304d\u3066\u3001errn [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-2357","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2357"}],"version-history":[{"count":3,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2357\/revisions"}],"predecessor-version":[{"id":2359,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2357\/revisions\/2359"}],"wp:attachment":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2357"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}