diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 01:44:40 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 01:44:40 +0000 |
commit | df31da4e2dd3d87ebf45ea8c67fe739b5a680f74 (patch) | |
tree | 4b9fa243597bc37955b10ec10b15971daa9c23af | |
parent | 46b78da34109059413e43febbe1b48385f1f92f1 (diff) | |
download | chromium_src-df31da4e2dd3d87ebf45ea8c67fe739b5a680f74.zip chromium_src-df31da4e2dd3d87ebf45ea8c67fe739b5a680f74.tar.gz chromium_src-df31da4e2dd3d87ebf45ea8c67fe739b5a680f74.tar.bz2 |
Set send buffer size for P2P UDP sockets.
On windows the default send buffer is too small. Set it explicitly to prevent packets from being lost when sending.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/8304008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105995 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/renderer_host/p2p/socket_host_udp.cc | 7 | ||||
-rw-r--r-- | content/browser/renderer_host/p2p/socket_host_udp_unittest.cc | 8 | ||||
-rw-r--r-- | net/udp/datagram_server_socket.h | 6 | ||||
-rw-r--r-- | net/udp/udp_client_socket.cc | 4 | ||||
-rw-r--r-- | net/udp/udp_client_socket.h | 20 | ||||
-rw-r--r-- | net/udp/udp_server_socket.cc | 8 | ||||
-rw-r--r-- | net/udp/udp_server_socket.h | 16 | ||||
-rw-r--r-- | net/udp/udp_socket_libevent.cc | 18 | ||||
-rw-r--r-- | net/udp/udp_socket_libevent.h | 6 | ||||
-rw-r--r-- | net/udp/udp_socket_win.cc | 16 | ||||
-rw-r--r-- | net/udp/udp_socket_win.h | 6 |
11 files changed, 96 insertions, 19 deletions
diff --git a/content/browser/renderer_host/p2p/socket_host_udp.cc b/content/browser/renderer_host/p2p/socket_host_udp.cc index 1e08272..388eb92 100644 --- a/content/browser/renderer_host/p2p/socket_host_udp.cc +++ b/content/browser/renderer_host/p2p/socket_host_udp.cc @@ -14,6 +14,9 @@ namespace { // UDP packets cannot be bigger than 64k. const int kReadBufferSize = 65536; +// Send buffer size for the socket. +const int kSendBufferSize = 65536; + } // namespace namespace content { @@ -47,6 +50,9 @@ bool P2PSocketHostUdp::Init(const net::IPEndPoint& local_address, return false; } + if (!socket_->SetSendBufferSize(kSendBufferSize)) + LOG(WARNING) << "Failed to set send buffer size for UDP socket."; + net::IPEndPoint address; result = socket_->GetLocalAddress(&address); if (result < 0) { @@ -55,7 +61,6 @@ bool P2PSocketHostUdp::Init(const net::IPEndPoint& local_address, OnError(); return false; } - VLOG(1) << "Local address: " << address.ToString(); state_ = STATE_OPEN; diff --git a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc index bcc6716..a33bc83 100644 --- a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc +++ b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc @@ -81,6 +81,14 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket { return buf_len; } + virtual bool SetReceiveBufferSize(int32 size) OVERRIDE { + return true; + } + + virtual bool SetSendBufferSize(int32 size) OVERRIDE { + return true; + } + void ReceivePacket(const net::IPEndPoint& address, std::vector<char> data) { if (recv_callback_) { int size = std::min(recv_size_, static_cast<int>(data.size())); diff --git a/net/udp/datagram_server_socket.h b/net/udp/datagram_server_socket.h index 9b43f36..cd20191 100644 --- a/net/udp/datagram_server_socket.h +++ b/net/udp/datagram_server_socket.h @@ -54,6 +54,12 @@ class NET_EXPORT DatagramServerSocket : public DatagramSocket { int buf_len, const IPEndPoint& address, OldCompletionCallback* callback) = 0; + + // Set the receive buffer size (in bytes) for the socket. + virtual bool SetReceiveBufferSize(int32 size) = 0; + + // Set the send buffer size (in bytes) for the socket. + virtual bool SetSendBufferSize(int32 size) = 0; }; } // namespace net diff --git a/net/udp/udp_client_socket.cc b/net/udp/udp_client_socket.cc index 96c4c33..e5cef3e 100644 --- a/net/udp/udp_client_socket.cc +++ b/net/udp/udp_client_socket.cc @@ -47,11 +47,11 @@ int UDPClientSocket::GetLocalAddress(IPEndPoint* address) const { } bool UDPClientSocket::SetReceiveBufferSize(int32 size) { - return true; + return socket_.SetReceiveBufferSize(size); } bool UDPClientSocket::SetSendBufferSize(int32 size) { - return true; + return socket_.SetSendBufferSize(size); } const BoundNetLog& UDPClientSocket::NetLog() const { diff --git a/net/udp/udp_client_socket.h b/net/udp/udp_client_socket.h index 7aa4a7f..cf37a736 100644 --- a/net/udp/udp_client_socket.h +++ b/net/udp/udp_client_socket.h @@ -25,15 +25,17 @@ class NET_EXPORT_PRIVATE UDPClientSocket : public DatagramClientSocket { virtual ~UDPClientSocket(); // Implement DatagramClientSocket: - virtual int Connect(const IPEndPoint& address); - virtual int Read(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); - virtual int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); - virtual void Close(); - virtual int GetPeerAddress(IPEndPoint* address) const; - virtual int GetLocalAddress(IPEndPoint* address) const; - virtual bool SetReceiveBufferSize(int32 size); - virtual bool SetSendBufferSize(int32 size); - virtual const BoundNetLog& NetLog() const; + virtual int Connect(const IPEndPoint& address) OVERRIDE; + virtual int Read(IOBuffer* buf, int buf_len, + OldCompletionCallback* callback) OVERRIDE; + virtual int Write(IOBuffer* buf, int buf_len, + OldCompletionCallback* callback) OVERRIDE; + virtual void Close() OVERRIDE; + virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; + virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; + virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; + virtual bool SetSendBufferSize(int32 size) OVERRIDE; + virtual const BoundNetLog& NetLog() const OVERRIDE; private: UDPSocket socket_; diff --git a/net/udp/udp_server_socket.cc b/net/udp/udp_server_socket.cc index 54391c5..7958463 100644 --- a/net/udp/udp_server_socket.cc +++ b/net/udp/udp_server_socket.cc @@ -37,6 +37,14 @@ int UDPServerSocket::SendTo(IOBuffer* buf, return socket_.SendTo(buf, buf_len, address, callback); } +bool UDPServerSocket::SetReceiveBufferSize(int32 size) { + return socket_.SetReceiveBufferSize(size); +} + +bool UDPServerSocket::SetSendBufferSize(int32 size) { + return socket_.SetSendBufferSize(size); +} + void UDPServerSocket::Close() { socket_.Close(); } diff --git a/net/udp/udp_server_socket.h b/net/udp/udp_server_socket.h index 92dfef3..bb6ac5c 100644 --- a/net/udp/udp_server_socket.h +++ b/net/udp/udp_server_socket.h @@ -23,19 +23,21 @@ class NET_EXPORT UDPServerSocket : public DatagramServerSocket { virtual ~UDPServerSocket(); // Implement DatagramServerSocket: - virtual int Listen(const IPEndPoint& address); + virtual int Listen(const IPEndPoint& address) OVERRIDE; virtual int RecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address, - OldCompletionCallback* callback); + OldCompletionCallback* callback) OVERRIDE; virtual int SendTo(IOBuffer* buf, int buf_len, const IPEndPoint& address, - OldCompletionCallback* callback); - virtual void Close(); - virtual int GetPeerAddress(IPEndPoint* address) const; - virtual int GetLocalAddress(IPEndPoint* address) const; - virtual const BoundNetLog& NetLog() const; + OldCompletionCallback* callback) OVERRIDE; + virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; + virtual bool SetSendBufferSize(int32 size) OVERRIDE; + virtual void Close() OVERRIDE; + virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; + virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; + virtual const BoundNetLog& NetLog() const OVERRIDE; private: UDPSocket socket_; diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc index 33f9edd..1e790df 100644 --- a/net/udp/udp_socket_libevent.cc +++ b/net/udp/udp_socket_libevent.cc @@ -218,6 +218,7 @@ int UDPSocketLibevent::SendToOrWrite(IOBuffer* buf, } int UDPSocketLibevent::Connect(const IPEndPoint& address) { + DCHECK(CalledOnValidThread()); DCHECK(!is_connected()); DCHECK(!remote_address_.get()); int rv = CreateSocket(address); @@ -246,6 +247,7 @@ int UDPSocketLibevent::Connect(const IPEndPoint& address) { } int UDPSocketLibevent::Bind(const IPEndPoint& address) { + DCHECK(CalledOnValidThread()); DCHECK(!is_connected()); int rv = CreateSocket(address); if (rv < 0) @@ -257,6 +259,22 @@ int UDPSocketLibevent::Bind(const IPEndPoint& address) { return rv; } +bool UDPSocketLibevent::SetReceiveBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); + 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 UDPSocketLibevent::SetSendBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); + 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; +} + void UDPSocketLibevent::DoReadCallback(int rv) { DCHECK_NE(rv, ERR_IO_PENDING); DCHECK(read_callback_); diff --git a/net/udp/udp_socket_libevent.h b/net/udp/udp_socket_libevent.h index d6a99b1..6bdf4d4 100644 --- a/net/udp/udp_socket_libevent.h +++ b/net/udp/udp_socket_libevent.h @@ -94,6 +94,12 @@ class UDPSocketLibevent : public base::NonThreadSafe { const IPEndPoint& address, OldCompletionCallback* callback); + // Set the receive buffer size (in bytes) for the socket. + bool SetReceiveBufferSize(int32 size); + + // Set the send buffer size (in bytes) for the socket. + bool SetSendBufferSize(int32 size); + // Returns true if the socket is already connected or bound. bool is_connected() const { return socket_ != kInvalidSocket; } diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc index 49f2f44..d0242d4 100644 --- a/net/udp/udp_socket_win.cc +++ b/net/udp/udp_socket_win.cc @@ -239,6 +239,22 @@ int UDPSocketWin::CreateSocket(const IPEndPoint& address) { return OK; } +bool UDPSocketWin::SetReceiveBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); + 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 UDPSocketWin::SetSendBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); + 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; +} + void UDPSocketWin::DoReadCallback(int rv) { DCHECK_NE(rv, ERR_IO_PENDING); DCHECK(read_callback_); diff --git a/net/udp/udp_socket_win.h b/net/udp/udp_socket_win.h index a3ed37e..ca4ecb1 100644 --- a/net/udp/udp_socket_win.h +++ b/net/udp/udp_socket_win.h @@ -96,6 +96,12 @@ class UDPSocketWin : public base::NonThreadSafe { const IPEndPoint& address, OldCompletionCallback* callback); + // Set the receive buffer size (in bytes) for the socket. + bool SetReceiveBufferSize(int32 size); + + // Set the send buffer size (in bytes) for the socket. + bool SetSendBufferSize(int32 size); + // Returns true if the socket is already connected or bound. bool is_connected() const { return socket_ != INVALID_SOCKET; } |