| Index: chrome/browser/debugger/devtools_remote_listen_socket.cc
|
| ===================================================================
|
| --- chrome/browser/debugger/devtools_remote_listen_socket.cc (revision 19109)
|
| +++ chrome/browser/debugger/devtools_remote_listen_socket.cc (working copy)
|
| @@ -245,20 +245,33 @@
|
| }
|
|
|
| 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;
|
| }
|
| + PlatformThread::YieldCurrentThread();
|
| }
|
| - if (sent != len) {
|
| - LOG(ERROR) << "send failed: ";
|
| - }
|
| }
|
|
|
| void DevToolsRemoteListenSocket::Close() {
|
|
|