diff options
author | apavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 09:45:44 +0000 |
---|---|---|
committer | apavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 09:45:44 +0000 |
commit | d732c98af766e644dc5df9edfe8ac1e8bd5c4696 (patch) | |
tree | 4c38cec352327fe956e98a0ee0195affbe8fce17 /chrome/browser/debugger | |
parent | e5d1c1e348df89c4c0640222249c1d62be46b1ff (diff) | |
download | chromium_src-d732c98af766e644dc5df9edfe8ac1e8bd5c4696.zip chromium_src-d732c98af766e644dc5df9edfe8ac1e8bd5c4696.tar.gz chromium_src-d732c98af766e644dc5df9edfe8ac1e8bd5c4696.tar.bz2 |
Handle partial sends over the ChromeDevToolsProtocol.
send() can send parts of the buffer fed in. We should send parts of the buffer until the entire buffer has been transferred.
Review URL: http://codereview.chromium.org/150229
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19902 0039d316-1c4b-4281-b951-d872f2087c98
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(); } } |