diff options
Diffstat (limited to 'chrome/browser/debugger')
-rw-r--r-- | chrome/browser/debugger/devtools_remote_listen_socket.cc | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/chrome/browser/debugger/devtools_remote_listen_socket.cc b/chrome/browser/debugger/devtools_remote_listen_socket.cc index bdc5203..54d71fd 100644 --- a/chrome/browser/debugger/devtools_remote_listen_socket.cc +++ b/chrome/browser/debugger/devtools_remote_listen_socket.cc @@ -245,19 +245,32 @@ void DevToolsRemoteListenSocket::Accept() { } void DevToolsRemoteListenSocket::SendInternal(const char* bytes, int len) { - int sent = HANDLE_EINTR(send(socket_, bytes, len, 0)); - if (sent == kSocketError) { + char* send_buf = const_cast<char *>(bytes); + int len_left = len; + while (true) { + int sent = HANDLE_EINTR(send(socket_, send_buf, len_left, 0)); + if (sent == len_left) { // A shortcut to avoid extraneous checks. + break; + } + if (sent == kSocketError) { #if defined(OS_WIN) - while (WSAGetLastError() == WSAEWOULDBLOCK) { + if (WSAGetLastError() != WSAEWOULDBLOCK) { + LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError(); #elif defined(OS_POSIX) - while (errno == EWOULDBLOCK || errno == EAGAIN) { + if (errno != EWOULDBLOCK && errno != EAGAIN) { + LOG(ERROR) << "send failed: errno==" << errno; #endif - PlatformThread::YieldCurrentThread(); - sent = HANDLE_EINTR(send(socket_, bytes, len, 0)); + break; + } + // Otherwise we would block, and now we have to wait for a retry. + // Fall through to PlatformThread::YieldCurrentThread() + } else { + // sent != len_left according to the shortcut above. + // Shift the buffer start and send the remainder after a short while. + send_buf += sent; + len_left -= sent; } - } - if (sent != len) { - LOG(ERROR) << "send failed: "; + PlatformThread::YieldCurrentThread(); } } |