Revision: 11609
Author:   [email protected]
Date:     Mon May 21 05:58:48 2012
Log:      Handle EINTR in socket functions and continue incomplete sends.

Based on a patch by Ben Noordhuis <[email protected]>.

BUG=v8:2098
TEST=

Review URL: https://chromiumcodereview.appspot.com/10416006
http://code.google.com/p/v8/source/detail?r=11609

Modified:
 /branches/bleeding_edge/src/platform-posix.cc
 /branches/bleeding_edge/src/platform-win32.cc

=======================================
--- /branches/bleeding_edge/src/platform-posix.cc       Mon May 21 03:02:49 2012
+++ /branches/bleeding_edge/src/platform-posix.cc       Mon May 21 05:58:48 2012
@@ -421,7 +421,11 @@
     return NULL;
   }

-  int socket = accept(socket_, NULL, NULL);
+  int socket;
+  do {
+    socket = accept(socket_, NULL, NULL);
+  } while (socket == -1 && errno == EINTR);
+
   if (socket == -1) {
     return NULL;
   } else {
@@ -448,7 +452,9 @@
   }

   // Connect.
-  status = connect(socket_, result->ai_addr, result->ai_addrlen);
+  do {
+    status = connect(socket_, result->ai_addr, result->ai_addrlen);
+  } while (status == -1 && errno == EINTR);
   freeaddrinfo(result);
   return status == 0;
 }
@@ -468,14 +474,27 @@

 int POSIXSocket::Send(const char* data, int len) const {
   if (len <= 0) return 0;
-  int status = send(socket_, data, len, 0);
-  return (status < 0) ? 0 : status;
+  int written = 0;
+  while (written < len) {
+    int status = send(socket_, data + written, len - written, 0);
+    if (status == 0) {
+      break;
+    } else if (status > 0) {
+      written += status;
+    } else if (errno != EINTR) {
+      return 0;
+    }
+  }
+  return written;
 }


 int POSIXSocket::Receive(char* data, int len) const {
   if (len <= 0) return 0;
-  int status = recv(socket_, data, len, 0);
+  int status;
+  do {
+    status = recv(socket_, data, len, 0);
+  } while (status == -1 && errno == EINTR);
   return (status < 0) ? 0 : status;
 }

=======================================
--- /branches/bleeding_edge/src/platform-win32.cc       Mon May 21 03:02:49 2012
+++ /branches/bleeding_edge/src/platform-win32.cc       Mon May 21 05:58:48 2012
@@ -1849,8 +1849,18 @@

 int Win32Socket::Send(const char* data, int len) const {
   if (len <= 0) return 0;
-  int status = send(socket_, data, len, 0);
-  return (status == SOCKET_ERROR) ? 0 : status;
+  int written = 0;
+  while (written < len) {
+    int status = send(socket_, data + written, len - written, 0);
+    if (status == 0) {
+      break;
+    } else if (status > 0) {
+      written += status;
+    } else {
+      return 0;
+    }
+  }
+  return written;
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to