diff options
Diffstat (limited to 'net/udp')
-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 |
9 files changed, 82 insertions, 18 deletions
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; } |