diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-01 16:05:45 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-01 16:05:45 +0000 |
commit | 09ce873228b2e5dbc995ea58c21a2b3cab8bad66 (patch) | |
tree | 4203b0f4e4bee0b7232d923c51bbf910d7e2a9bb | |
parent | 05c9d4aae1662a37bf5fe572c2847cdb3e8b3edc (diff) | |
download | chromium_src-09ce873228b2e5dbc995ea58c21a2b3cab8bad66.zip chromium_src-09ce873228b2e5dbc995ea58c21a2b3cab8bad66.tar.gz chromium_src-09ce873228b2e5dbc995ea58c21a2b3cab8bad66.tar.bz2 |
DevTools: rollback r136953, make server socket blocking again.
BUG=125191
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159499 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/shell/shell_devtools_delegate_android.cc | 1 | ||||
-rw-r--r-- | net/base/stream_listen_socket.cc | 139 | ||||
-rw-r--r-- | net/base/stream_listen_socket.h | 15 |
3 files changed, 28 insertions, 127 deletions
diff --git a/content/shell/shell_devtools_delegate_android.cc b/content/shell/shell_devtools_delegate_android.cc index 7584c68..59098f9 100644 --- a/content/shell/shell_devtools_delegate_android.cc +++ b/content/shell/shell_devtools_delegate_android.cc @@ -4,6 +4,7 @@ #include "content/shell/shell_devtools_delegate.h" +#include "base/bind.h" #include "base/stringprintf.h" #include "content/public/browser/android/devtools_auth.h" #include "content/public/browser/devtools_http_handler.h" diff --git a/net/base/stream_listen_socket.cc b/net/base/stream_listen_socket.cc index 2382668..fc82b8a 100644 --- a/net/base/stream_listen_socket.cc +++ b/net/base/stream_listen_socket.cc @@ -32,7 +32,6 @@ using std::string; #if defined(OS_WIN) typedef int socklen_t; -#include "net/base/winsock_init.h" #endif // defined(OS_WIN) namespace net { @@ -40,33 +39,6 @@ namespace net { namespace { const int kReadBufSize = 4096; -const int kMaxSendBufSize = 1024 * 1024 * 5; // 5MB - -const net::BackoffEntry::Policy kSendBackoffPolicy = { - // Number of initial errors (in sequence) to ignore before applying - // exponential back-off rules. - 0, - - // Initial delay for exponential back-off in ms. - 25, - - // Factor by which the waiting time will be multiplied. - 2, - - // Fuzzing percentage. ex: 10% will spread requests randomly - // between 90%-100% of the calculated time. - 0, - - // Maximum amount of time we are willing to delay our request in ms. - 100, - - // Time to keep an entry from being discarded even when it - // has no significant state, -1 to never discard. - -1, - - // Don't use initial delay unless the last request was an error. - false, -}; } // namespace @@ -83,10 +55,7 @@ StreamListenSocket::StreamListenSocket(SocketDescriptor s, : socket_delegate_(del), socket_(s), reads_paused_(false), - has_pending_reads_(false), - send_pending_size_(0), - send_error_(false), - send_backoff_(&kSendBackoffPolicy) { + has_pending_reads_(false) { #if defined(OS_WIN) socket_event_ = WSACreateEvent(); // TODO(ibrar): error handling in case of socket_event_ == WSA_INVALID_EVENT. @@ -142,28 +111,33 @@ SocketDescriptor StreamListenSocket::AcceptSocket() { } void StreamListenSocket::SendInternal(const char* bytes, int len) { - DCHECK(bytes); - if (!bytes || len <= 0) - return; - - if (send_error_) - return; - - if (send_pending_size_ + len > kMaxSendBufSize) { - LOG(ERROR) << "send failed: buffer overrun"; - send_buffers_.clear(); - send_pending_size_ = 0; - send_error_ = true; - return; + 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) + if (WSAGetLastError() != WSAEWOULDBLOCK) { + LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError(); +#elif defined(OS_POSIX) + if (errno != EWOULDBLOCK && errno != EAGAIN) { + LOG(ERROR) << "send failed: errno==" << errno; +#endif + 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; + } + base::PlatformThread::YieldCurrentThread(); } - - scoped_refptr<IOBuffer> buffer(new IOBuffer(len)); - memcpy(buffer->data(), bytes, len); - send_buffers_.push_back(new DrainableIOBuffer(buffer, len)); - send_pending_size_ += len; - - if (!send_timer_.IsRunning()) - SendData(); } void StreamListenSocket::Listen() { @@ -326,63 +300,4 @@ void StreamListenSocket::ResumeReads() { } } -void StreamListenSocket::SendData() { - DCHECK(!send_buffers_.empty()); - - int total_sent = 0; - - // Send data until all buffers have been sent or a call would block. - while (!send_buffers_.empty()) { - scoped_refptr<DrainableIOBuffer> buffer = send_buffers_.front(); - - int len_left = buffer->BytesRemaining(); - int sent = HANDLE_EINTR(send(socket_, buffer->data(), len_left, 0)); - if (sent > 0) { - if (sent == len_left) - send_buffers_.pop_front(); - else - buffer->DidConsume(sent); - - total_sent += sent; - } else if (sent == kSocketError) { -#if defined(OS_WIN) - if (WSAGetLastError() != WSAEWOULDBLOCK) { - LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError(); -#elif defined(OS_POSIX) - if (errno != EWOULDBLOCK && errno != EAGAIN) { - LOG(ERROR) << "send failed: errno==" << errno; -#endif - // Don't try to re-send data after a socket error. - send_buffers_.clear(); - send_pending_size_ = 0; - send_error_ = true; - return; - } - - // The call would block. Don't send any more data at this time. - break; - } else { - NOTREACHED(); - break; - } - } - - if (total_sent > 0) { - send_pending_size_ -= total_sent; - DCHECK_GE(send_pending_size_, 0); - - // Clear the back-off delay. - send_backoff_.Reset(); - } else { - // Increase the back-off delay. - send_backoff_.InformOfRequest(false); - } - - if (!send_buffers_.empty()) { - DCHECK(!send_timer_.IsRunning()); - send_timer_.Start(FROM_HERE, send_backoff_.GetTimeUntilRelease(), - this, &StreamListenSocket::SendData); - } -} - } // namespace net diff --git a/net/base/stream_listen_socket.h b/net/base/stream_listen_socket.h index 54e9d2b..96e8952 100644 --- a/net/base/stream_listen_socket.h +++ b/net/base/stream_listen_socket.h @@ -16,8 +16,6 @@ #ifndef NET_BASE_STREAM_LISTEN_SOCKET_H_ #define NET_BASE_STREAM_LISTEN_SOCKET_H_ -#include <list> - #include "build/build_config.h" #if defined(OS_WIN) @@ -32,10 +30,6 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "base/timer.h" -#include "net/base/backoff_entry.h" -#include "net/base/io_buffer.h" #include "net/base/net_export.h" #include "net/base/stream_listen_socket.h" @@ -116,7 +110,6 @@ class NET_EXPORT StreamListenSocket friend class base::RefCountedThreadSafe<StreamListenSocket>; friend class TransportClientSocketTest; - void SendData(); void SendInternal(const char* bytes, int len); #if defined(OS_WIN) @@ -143,14 +136,6 @@ class NET_EXPORT StreamListenSocket bool reads_paused_; bool has_pending_reads_; - std::list<scoped_refptr<DrainableIOBuffer> > send_buffers_; - int send_pending_size_; - bool send_error_; - net::BackoffEntry send_backoff_; - - // Used to continue sending data asynchronously. - base::OneShotTimer<StreamListenSocket> send_timer_; - DISALLOW_COPY_AND_ASSIGN(StreamListenSocket); }; |