| Index: net/base/listen_socket.cc
|
| diff --git a/net/base/listen_socket.cc b/net/base/listen_socket.cc
|
| index c2eb00394d65fc2c0b8010dbdb44ed5312228029..0cb529d8e1b0ab70b614352435776ec976050c92 100644
|
| --- a/net/base/listen_socket.cc
|
| +++ b/net/base/listen_socket.cc
|
| @@ -31,7 +31,7 @@ typedef int socklen_t;
|
|
|
| namespace {
|
|
|
| -const int kReadBufSize = 200;
|
| +const int kReadBufSize = 4096;
|
|
|
| } // namespace
|
|
|
| @@ -160,7 +160,7 @@ void ListenSocket::Read() {
|
| // TODO(ibrar): maybe change DidRead to take a length instead
|
| DCHECK(len > 0 && len <= kReadBufSize);
|
| buf[len] = 0; // already create a buffer with +1 length
|
| - socket_delegate_->DidRead(this, buf);
|
| + socket_delegate_->DidRead(this, buf, len);
|
| }
|
| } while (len == kReadBufSize);
|
| }
|
| @@ -206,19 +206,32 @@ void ListenSocket::WatchSocket(WaitState state) {
|
| }
|
|
|
| void ListenSocket::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)
|
| - int err = WSAGetLastError();
|
| - if (err == WSAEWOULDBLOCK) {
|
| + if (WSAGetLastError() != WSAEWOULDBLOCK) {
|
| + LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError();
|
| #elif defined(OS_POSIX)
|
| - if (errno == EWOULDBLOCK || errno == EAGAIN) {
|
| + if (errno != EWOULDBLOCK && errno != EAGAIN) {
|
| + LOG(ERROR) << "send failed: errno==" << errno;
|
| #endif
|
| - // TODO(ibrar): there should be logic here to handle this because
|
| - // it is not an error
|
| + 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;
|
| }
|
| - } else if (sent != len) {
|
| - LOG(ERROR) << "send failed: ";
|
| + PlatformThread::YieldCurrentThread();
|
| }
|
| }
|
|
|
|
|