summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 22:38:04 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 22:38:04 +0000
commitd3f665783018ad6832b224d108640a0be2b1f248 (patch)
tree6634df109ace1c2df58fccf8ff4d9569ec3a5cd9 /net
parent87fce2b91c8fa1f10ec49e79c719159097a597c5 (diff)
downloadchromium_src-d3f665783018ad6832b224d108640a0be2b1f248.zip
chromium_src-d3f665783018ad6832b224d108640a0be2b1f248.tar.gz
chromium_src-d3f665783018ad6832b224d108640a0be2b1f248.tar.bz2
Add methods for setting socket buffers to the Socket
class. Also add a few stats counters for TCP read/write stats. BUG=none TEST=none Review URL: http://codereview.chromium.org/199048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25803 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc4
-rw-r--r--net/socket/socket.h10
-rw-r--r--net/socket/socket_test_util.h2
-rw-r--r--net/socket/socks5_client_socket.cc8
-rw-r--r--net/socket/socks5_client_socket.h3
-rw-r--r--net/socket/socks_client_socket.cc8
-rw-r--r--net/socket/socks_client_socket.h3
-rw-r--r--net/socket/ssl_client_socket_mac.cc8
-rw-r--r--net/socket/ssl_client_socket_mac.h2
-rw-r--r--net/socket/ssl_client_socket_nss.cc8
-rw-r--r--net/socket/ssl_client_socket_nss.h2
-rw-r--r--net/socket/ssl_client_socket_win.cc8
-rw-r--r--net/socket/ssl_client_socket_win.h3
-rw-r--r--net/socket/tcp_client_socket_libevent.cc17
-rw-r--r--net/socket/tcp_client_socket_libevent.h2
-rw-r--r--net/socket/tcp_client_socket_pool_unittest.cc6
-rw-r--r--net/socket/tcp_client_socket_win.cc43
-rw-r--r--net/socket/tcp_client_socket_win.h3
18 files changed, 130 insertions, 10 deletions
diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc
index 970b0ba..249d7e3 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -42,6 +42,8 @@ class MockClientSocket : public ClientSocket {
IOBuffer* /* buf */, int /* len */, CompletionCallback* /* callback */) {
return ERR_UNEXPECTED;
}
+ virtual bool SetReceiveBufferSize(int32 size) { return true; };
+ virtual bool SetSendBufferSize(int32 size) { return true; };
// ClientSocket methods:
@@ -1816,7 +1818,7 @@ TEST_F(ClientSocketPoolBaseTest_LateBinding, CleanupTimedOutIdleSockets) {
MessageLoop::current()->RunAllPending();
ASSERT_EQ(2, pool_->IdleSocketCount());
-
+
// Invoke the idle socket cleanup check. Only one socket should be left, the
// used socket. Request it to make sure that it's used.
diff --git a/net/socket/socket.h b/net/socket/socket.h
index 8e451d2..a0834bf 100644
--- a/net/socket/socket.h
+++ b/net/socket/socket.h
@@ -37,6 +37,16 @@ class Socket {
// buffer that is written to the socket.
virtual int Write(IOBuffer* buf, int buf_len,
CompletionCallback* callback) = 0;
+
+ // Set the receive buffer size (in bytes) for the socket.
+ // Note: changing this value can effect the TCP window size on some platforms.
+ // Returns true on success, or false on failure.
+ virtual bool SetReceiveBufferSize(int32 size) = 0;
+
+ // Set the send buffer size (in bytes) for the socket.
+ // Note: changing this value can effect the TCP window size on some platforms.
+ // Returns true on success, or false on failure.
+ virtual bool SetSendBufferSize(int32 size) = 0;
};
} // namespace net
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index c7c0e12..adfa3cb 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -247,6 +247,8 @@ class MockClientSocket : public net::SSLClientSocket {
net::CompletionCallback* callback) = 0;
virtual int Write(net::IOBuffer* buf, int buf_len,
net::CompletionCallback* callback) = 0;
+ virtual bool SetReceiveBufferSize(int32 size) { return true; };
+ virtual bool SetSendBufferSize(int32 size) { return true; };
#if defined(OS_LINUX)
virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen);
diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc
index a4fca1a..cc12a3c 100644
--- a/net/socket/socks5_client_socket.cc
+++ b/net/socket/socks5_client_socket.cc
@@ -102,6 +102,14 @@ int SOCKS5ClientSocket::Write(IOBuffer* buf, int buf_len,
return transport_->Write(buf, buf_len, callback);
}
+bool SOCKS5ClientSocket::SetReceiveBufferSize(int32 size) {
+ return transport_->SetReceiveBufferSize(size);
+}
+
+bool SOCKS5ClientSocket::SetSendBufferSize(int32 size) {
+ return transport_->SetSendBufferSize(size);
+}
+
void SOCKS5ClientSocket::DoCallback(int result) {
DCHECK_NE(ERR_IO_PENDING, result);
DCHECK(user_callback_);
diff --git a/net/socket/socks5_client_socket.h b/net/socket/socks5_client_socket.h
index 1a5672d..395d3e9 100644
--- a/net/socket/socks5_client_socket.h
+++ b/net/socket/socks5_client_socket.h
@@ -48,6 +48,9 @@ class SOCKS5ClientSocket : public ClientSocket {
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
+
#if defined(OS_LINUX)
virtual int GetPeerName(struct sockaddr* name, socklen_t* namelen);
#endif
diff --git a/net/socket/socks_client_socket.cc b/net/socket/socks_client_socket.cc
index 31f362e..ace53d9 100644
--- a/net/socket/socks_client_socket.cc
+++ b/net/socket/socks_client_socket.cc
@@ -136,6 +136,14 @@ int SOCKSClientSocket::Write(IOBuffer* buf, int buf_len,
return transport_->Write(buf, buf_len, callback);
}
+bool SOCKSClientSocket::SetReceiveBufferSize(int32 size) {
+ return transport_->SetReceiveBufferSize(size);
+}
+
+bool SOCKSClientSocket::SetSendBufferSize(int32 size) {
+ return transport_->SetSendBufferSize(size);
+}
+
void SOCKSClientSocket::DoCallback(int result) {
DCHECK_NE(ERR_IO_PENDING, result);
DCHECK(user_callback_);
diff --git a/net/socket/socks_client_socket.h b/net/socket/socks_client_socket.h
index 1b0cd79..9b53c11 100644
--- a/net/socket/socks_client_socket.h
+++ b/net/socket/socks_client_socket.h
@@ -47,6 +47,9 @@ class SOCKSClientSocket : public ClientSocket {
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
+
#if defined(OS_LINUX)
// Needed by ssl_client_socket_nss.
virtual int GetPeerName(struct sockaddr* name, socklen_t* namelen);
diff --git a/net/socket/ssl_client_socket_mac.cc b/net/socket/ssl_client_socket_mac.cc
index bb97762..23dfb60 100644
--- a/net/socket/ssl_client_socket_mac.cc
+++ b/net/socket/ssl_client_socket_mac.cc
@@ -495,6 +495,14 @@ int SSLClientSocketMac::Write(IOBuffer* buf, int buf_len,
return rv;
}
+bool SSLClientSocketMac::SetReceiveBufferSize(int32 size) {
+ return transport_->SetReceiveBufferSize(size);
+}
+
+bool SSLClientSocketMac::SetSendBufferSize(int32 size) {
+ return transport_->SetSendBufferSize(size);
+}
+
void SSLClientSocketMac::GetSSLInfo(SSLInfo* ssl_info) {
ssl_info->Reset();
diff --git a/net/socket/ssl_client_socket_mac.h b/net/socket/ssl_client_socket_mac.h
index 0c24e7a..89e2ed4 100644
--- a/net/socket/ssl_client_socket_mac.h
+++ b/net/socket/ssl_client_socket_mac.h
@@ -45,6 +45,8 @@ class SSLClientSocketMac : public SSLClientSocket {
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
private:
void DoCallback(int result);
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc
index e6b3e96..1f35728 100644
--- a/net/socket/ssl_client_socket_nss.cc
+++ b/net/socket/ssl_client_socket_nss.cc
@@ -434,6 +434,14 @@ int SSLClientSocketNSS::Write(IOBuffer* buf, int buf_len,
return rv;
}
+bool SSLClientSocketNSS::SetReceiveBufferSize(int32 size) {
+ return transport_->SetReceiveBufferSize(size);
+}
+
+bool SSLClientSocketNSS::SetSendBufferSize(int32 size) {
+ return transport_->SetSendBufferSize(size);
+}
+
X509Certificate *SSLClientSocketNSS::UpdateServerCert() {
// We set the server_cert_ from OwnAuthCertHandler(), but this handler
// does not necessarily get called if we are continuing a cached SSL
diff --git a/net/socket/ssl_client_socket_nss.h b/net/socket/ssl_client_socket_nss.h
index 2d93c5a..8cbdff6 100644
--- a/net/socket/ssl_client_socket_nss.h
+++ b/net/socket/ssl_client_socket_nss.h
@@ -51,6 +51,8 @@ class SSLClientSocketNSS : public SSLClientSocket {
// Socket methods:
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
private:
void InvalidateSessionIfBadCertificate();
diff --git a/net/socket/ssl_client_socket_win.cc b/net/socket/ssl_client_socket_win.cc
index 474f630..1f168fe 100644
--- a/net/socket/ssl_client_socket_win.cc
+++ b/net/socket/ssl_client_socket_win.cc
@@ -580,6 +580,14 @@ int SSLClientSocketWin::Write(IOBuffer* buf, int buf_len,
return rv;
}
+bool SSLClientSocketWin::SetReceiveBufferSize(int32 size) {
+ return transport_->SetReceiveBufferSize(size);
+}
+
+bool SSLClientSocketWin::SetSendBufferSize(int32 size) {
+ return transport_->SetSendBufferSize(size);
+}
+
void SSLClientSocketWin::DoCallback(int rv) {
DCHECK(rv != ERR_IO_PENDING);
DCHECK(user_callback_);
diff --git a/net/socket/ssl_client_socket_win.h b/net/socket/ssl_client_socket_win.h
index 461047c..678678a 100644
--- a/net/socket/ssl_client_socket_win.h
+++ b/net/socket/ssl_client_socket_win.h
@@ -49,6 +49,9 @@ class SSLClientSocketWin : public SSLClientSocket {
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
+
private:
void DoCallback(int result);
void OnIOComplete(int result);
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index f417f80..8ad5ef3 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -262,6 +262,23 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf,
return ERR_IO_PENDING;
}
+bool TCPClientSocketLibevent::SetReceiveBufferSize(int32 size) {
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
+ reinterpret_cast<const char*>(&size),
+ sizeof(size));
+ DCHECK(!rv) << "Could not set socket receive buffer size: " << errno;
+ return rv == 0;
+}
+
+bool TCPClientSocketLibevent::SetSendBufferSize(int32 size) {
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
+ reinterpret_cast<const char*>(&size),
+ sizeof(size));
+ DCHECK(!rv) << "Could not set socket send buffer size: " << errno;
+ return rv == 0;
+}
+
+
int TCPClientSocketLibevent::CreateSocket(const addrinfo* ai) {
socket_ = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (socket_ == kInvalidSocket)
diff --git a/net/socket/tcp_client_socket_libevent.h b/net/socket/tcp_client_socket_libevent.h
index c644a5f..bfb5767 100644
--- a/net/socket/tcp_client_socket_libevent.h
+++ b/net/socket/tcp_client_socket_libevent.h
@@ -40,6 +40,8 @@ class TCPClientSocketLibevent : public ClientSocket {
// Full duplex mode (reading and writing at the same time) is supported
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
private:
class ReadWatcher : public MessageLoopForIO::Watcher {
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc
index 86388f5..f66fdb7 100644
--- a/net/socket/tcp_client_socket_pool_unittest.cc
+++ b/net/socket/tcp_client_socket_pool_unittest.cc
@@ -51,6 +51,8 @@ class MockClientSocket : public ClientSocket {
CompletionCallback* callback) {
return ERR_FAILED;
}
+ virtual bool SetReceiveBufferSize(int32 size) { return true; }
+ virtual bool SetSendBufferSize(int32 size) { return true; }
private:
bool connected_;
@@ -84,6 +86,8 @@ class MockFailingClientSocket : public ClientSocket {
CompletionCallback* callback) {
return ERR_FAILED;
}
+ virtual bool SetReceiveBufferSize(int32 size) { return true; }
+ virtual bool SetSendBufferSize(int32 size) { return true; }
};
class MockPendingClientSocket : public ClientSocket {
@@ -121,6 +125,8 @@ class MockPendingClientSocket : public ClientSocket {
CompletionCallback* callback) {
return ERR_FAILED;
}
+ virtual bool SetReceiveBufferSize(int32 size) { return true; }
+ virtual bool SetSendBufferSize(int32 size) { return true; }
private:
void DoCallback(CompletionCallback* callback) {
diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc
index de3cac6..a7a8094 100644
--- a/net/socket/tcp_client_socket_win.cc
+++ b/net/socket/tcp_client_socket_win.cc
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory_debug.h"
+#include "base/stats_counters.h"
#include "base/string_util.h"
#include "base/sys_info.h"
#include "base/trace_event.h"
@@ -239,6 +240,9 @@ int TCPClientSocketWin::Connect(CompletionCallback* callback) {
if (socket_ != INVALID_SOCKET)
return OK;
+ static StatsCounter connects("tcp.connect");
+ connects.Increment();
+
TRACE_EVENT_BEGIN("socket.connect", this, "");
const struct addrinfo* ai = current_ai_;
DCHECK(ai);
@@ -386,6 +390,8 @@ int TCPClientSocketWin::Read(IOBuffer* buf,
// false error reports.
// See bug 5297.
base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num);
+ static StatsCounter read_bytes("tcp.read_bytes");
+ read_bytes.Add(num);
return static_cast<int>(num);
}
} else {
@@ -409,6 +415,9 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
DCHECK_GT(buf_len, 0);
DCHECK(!core_->write_iobuffer_);
+ static StatsCounter reads("tcp.writes");
+ reads.Increment();
+
core_->write_buffer_.len = buf_len;
core_->write_buffer_.buf = buf->data();
@@ -422,6 +431,8 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
if (rv == 0) {
if (ResetEventIfSignaled(core_->write_overlapped_.hEvent)) {
TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", num));
+ static StatsCounter write_bytes("tcp.write_bytes");
+ write_bytes.Add(num);
return static_cast<int>(num);
}
} else {
@@ -436,6 +447,20 @@ int TCPClientSocketWin::Write(IOBuffer* buf,
return ERR_IO_PENDING;
}
+bool TCPClientSocketWin::SetReceiveBufferSize(int32 size) {
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
+ reinterpret_cast<const char*>(&size), sizeof(size));
+ DCHECK(!rv) << "Could not set socket receive buffer size: " << GetLastError();
+ return rv == 0;
+}
+
+bool TCPClientSocketWin::SetSendBufferSize(int32 size) {
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
+ reinterpret_cast<const char*>(&size), sizeof(size));
+ DCHECK(!rv) << "Could not set socket send buffer size: " << GetLastError();
+ return rv == 0;
+}
+
int TCPClientSocketWin::CreateSocket(const struct addrinfo* ai) {
socket_ = WSASocket(ai->ai_family, ai->ai_socktype, ai->ai_protocol, NULL, 0,
WSA_FLAG_OVERLAPPED);
@@ -459,15 +484,9 @@ int TCPClientSocketWin::CreateSocket(const struct addrinfo* ai) {
base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version,
&fix_version);
if (major_version < 6) {
- const int kSocketBufferSize = 64 * 1024;
- int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
- reinterpret_cast<const char*>(&kSocketBufferSize),
- sizeof(kSocketBufferSize));
- DCHECK(!rv) << "Could not set socket send buffer size";
- rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
- reinterpret_cast<const char*>(&kSocketBufferSize),
- sizeof(kSocketBufferSize));
- DCHECK(!rv) << "Could not set socket receive buffer size";
+ const int32 kSocketBufferSize = 64 * 1024;
+ SetReceiveBufferSize(kSocketBufferSize);
+ SetSendBufferSize(kSocketBufferSize);
}
// Disable Nagle.
@@ -504,6 +523,9 @@ void TCPClientSocketWin::DoReadCallback(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
DCHECK(read_callback_);
+ static StatsCounter read_bytes("tcp.read_bytes");
+ read_bytes.Add(rv);
+
// since Run may result in Read being called, clear read_callback_ up front.
CompletionCallback* c = read_callback_;
read_callback_ = NULL;
@@ -514,6 +536,9 @@ void TCPClientSocketWin::DoWriteCallback(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
DCHECK(write_callback_);
+ static StatsCounter write_bytes("tcp.write_bytes");
+ write_bytes.Add(rv);
+
// since Run may result in Write being called, clear write_callback_ up front.
CompletionCallback* c = write_callback_;
write_callback_ = NULL;
diff --git a/net/socket/tcp_client_socket_win.h b/net/socket/tcp_client_socket_win.h
index 492b106..6bc63fc 100644
--- a/net/socket/tcp_client_socket_win.h
+++ b/net/socket/tcp_client_socket_win.h
@@ -35,6 +35,9 @@ class TCPClientSocketWin : public ClientSocket {
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual bool SetReceiveBufferSize(int32 size);
+ virtual bool SetSendBufferSize(int32 size);
+
private:
class Core;