Commit d732c98a authored by apavlov@chromium.org's avatar apavlov@chromium.org

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
parent e5d1c1e3
...@@ -245,19 +245,32 @@ void DevToolsRemoteListenSocket::Accept() { ...@@ -245,19 +245,32 @@ void DevToolsRemoteListenSocket::Accept() {
} }
void DevToolsRemoteListenSocket::SendInternal(const char* bytes, int len) { void DevToolsRemoteListenSocket::SendInternal(const char* bytes, int len) {
int sent = HANDLE_EINTR(send(socket_, bytes, len, 0)); char* send_buf = const_cast<char *>(bytes);
if (sent == kSocketError) { 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) #if defined(OS_WIN)
while (WSAGetLastError() == WSAEWOULDBLOCK) { if (WSAGetLastError() != WSAEWOULDBLOCK) {
LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError();
#elif defined(OS_POSIX) #elif defined(OS_POSIX)
while (errno == EWOULDBLOCK || errno == EAGAIN) { if (errno != EWOULDBLOCK && errno != EAGAIN) {
LOG(ERROR) << "send failed: errno==" << errno;
#endif #endif
PlatformThread::YieldCurrentThread(); break;
sent = HANDLE_EINTR(send(socket_, bytes, len, 0)); }
// 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;
} }
} PlatformThread::YieldCurrentThread();
if (sent != len) {
LOG(ERROR) << "send failed: ";
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment