Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: net/base/listen_socket.cc

Issue 2868036: Brushed up listen socket: (Closed)
Patch Set: Lint. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/listen_socket.h ('k') | net/base/listen_socket_unittest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
}
« no previous file with comments | « net/base/listen_socket.h ('k') | net/base/listen_socket_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698