diff --git a/content/browser/renderer_host/p2p/socket_host_udp.cc b/content/browser/renderer_host/p2p/socket_host_udp.cc index 1e082729ad7b3b..388eb92d149de3 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 bcc6716ec875dd..a33bc83d2e4f56 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 data) { if (recv_callback_) { int size = std::min(recv_size_, static_cast(data.size())); diff --git a/net/udp/datagram_server_socket.h b/net/udp/datagram_server_socket.h index 9b43f3680e279f..cd20191a0c0488 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 96c4c335dd256a..e5cef3e2a3f205 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 7aa4a7f00d15d0..cf37a736017c21 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 54391c56b0167c..79584637405a26 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 92dfef3a65f33b..bb6ac5c8aa86fb 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 33f9edd6d92506..1e790df5294de4 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(&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(&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 d6a99b1754f79b..6bdf4d4cd4e7b6 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 49f2f446e11cbe..d0242d477d55c1 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(&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(&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 a3ed37ef3a94a2..ca4ecb16aff457 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; }