In the portability implementation of sendmsg return a partial message send if it...
authorChristopher Dykes <cdykes@fb.com>
Mon, 31 Oct 2016 18:59:37 +0000 (11:59 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Mon, 31 Oct 2016 19:08:34 +0000 (12:08 -0700)
Summary: If multiple iovs are passed to sendmsg, sendmsg is supposed to return the number of bytes sent if it would block, but only if the number of bytes sent is greater than 0.

Reviewed By: yfeldblum

Differential Revision: D4099691

fbshipit-source-id: e58fa71604966129b1fbd418c24b1bf012060428

folly/portability/Sockets.cpp

index 14f31fd0065d0a76dd1e779e0e9a8dc57d2b0a1c..5af387507ee153e732a3d3dffbd8db6c8ef045f7 100755 (executable)
@@ -338,6 +338,10 @@ ssize_t sendmsg(int s, const struct msghdr* message, int fl) {
           message->msg_flags);
     }
     if (r == -1 || r != message->msg_iov[i].iov_len) {
+      errno = translate_wsa_error(WSAGetLastError());
+      if (WSAGetLastError() == WSAEWOULDBLOCK && bytesSent > 0) {
+        return bytesSent;
+      }
       return -1;
     }
     bytesSent += r;