From 48cdbffd24f7357b997e96b6ed4e5d27a999d9dd Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 24 Apr 2012 04:01:28 +0200 Subject: [PATCH] v8: posix: try to send() whole buffer Retry the send() syscall after a partial write. --- deps/v8/src/platform-posix.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/deps/v8/src/platform-posix.cc b/deps/v8/src/platform-posix.cc index 9c574937b3..1f87e70972 100644 --- a/deps/v8/src/platform-posix.cc +++ b/deps/v8/src/platform-posix.cc @@ -472,13 +472,22 @@ bool POSIXSocket::Shutdown() { int POSIXSocket::Send(const char* data, int len) const { - int status; - - do - status = send(socket_, data, len, 0); - while (status == -1 && errno == EINTR); + int written; + + for (written = 0; written < len; /* empty */) { + int status = send(socket_, data + written, len - written, 0); + if (status == 0) { + break; + } else if (status > 0) { + written += status; + } else if (errno == EINTR) { + /* interrupted by signal, retry */ + } else { + return -1; + } + } - return status; + return written; }