diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-05 03:52:22 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-05 03:52:22 +0000 |
commit | 27f82f41d1f44a33a87e50622c7012a81a343b40 (patch) | |
tree | bef9d33568018f9679482488628b88ad3ea523cc /net/udp | |
parent | 41b64e8a42afd40536aa9c06be8dff1196079c48 (diff) | |
download | chromium_src-27f82f41d1f44a33a87e50622c7012a81a343b40.zip chromium_src-27f82f41d1f44a33a87e50622c7012a81a343b40.tar.gz chromium_src-27f82f41d1f44a33a87e50622c7012a81a343b40.tar.bz2 |
make SetReceiveBufferSize and SetSendBufferSize return net error codes (instead of bools)
TBR=sergeyu,yzshen
R=wtc
BUG=355222
Review URL: https://codereview.chromium.org/217573002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261966 0039d316-1c4b-4281-b951-d872f2087c98
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 | 4 | ||||
-rw-r--r-- | net/udp/udp_server_socket.cc | 4 | ||||
-rw-r--r-- | net/udp/udp_server_socket.h | 4 | ||||
-rw-r--r-- | net/udp/udp_socket_libevent.cc | 14 | ||||
-rw-r--r-- | net/udp/udp_socket_libevent.h | 4 | ||||
-rw-r--r-- | net/udp/udp_socket_win.cc | 59 | ||||
-rw-r--r-- | net/udp/udp_socket_win.h | 6 |
9 files changed, 57 insertions, 48 deletions
diff --git a/net/udp/datagram_server_socket.h b/net/udp/datagram_server_socket.h index a7191d1..964883f 100644 --- a/net/udp/datagram_server_socket.h +++ b/net/udp/datagram_server_socket.h @@ -56,10 +56,12 @@ class NET_EXPORT DatagramServerSocket : public DatagramSocket { const CompletionCallback& callback) = 0; // Set the receive buffer size (in bytes) for the socket. - virtual bool SetReceiveBufferSize(int32 size) = 0; + // Returns a net error code. + virtual int SetReceiveBufferSize(int32 size) = 0; // Set the send buffer size (in bytes) for the socket. - virtual bool SetSendBufferSize(int32 size) = 0; + // Returns a net error code. + virtual int SetSendBufferSize(int32 size) = 0; // Allow the socket to share the local address to which the socket will // be bound with other processes. Should be called before Listen(). diff --git a/net/udp/udp_client_socket.cc b/net/udp/udp_client_socket.cc index bbc32d4..f6f904a 100644 --- a/net/udp/udp_client_socket.cc +++ b/net/udp/udp_client_socket.cc @@ -46,11 +46,11 @@ int UDPClientSocket::GetLocalAddress(IPEndPoint* address) const { return socket_.GetLocalAddress(address); } -bool UDPClientSocket::SetReceiveBufferSize(int32 size) { +int UDPClientSocket::SetReceiveBufferSize(int32 size) { return socket_.SetReceiveBufferSize(size); } -bool UDPClientSocket::SetSendBufferSize(int32 size) { +int UDPClientSocket::SetSendBufferSize(int32 size) { return socket_.SetSendBufferSize(size); } diff --git a/net/udp/udp_client_socket.h b/net/udp/udp_client_socket.h index e5cbdab..c5fc8c0 100644 --- a/net/udp/udp_client_socket.h +++ b/net/udp/udp_client_socket.h @@ -32,8 +32,8 @@ class NET_EXPORT_PRIVATE UDPClientSocket : public DatagramClientSocket { 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 int SetReceiveBufferSize(int32 size) OVERRIDE; + virtual int SetSendBufferSize(int32 size) OVERRIDE; virtual const BoundNetLog& NetLog() const OVERRIDE; private: diff --git a/net/udp/udp_server_socket.cc b/net/udp/udp_server_socket.cc index ad19655..796c04d 100644 --- a/net/udp/udp_server_socket.cc +++ b/net/udp/udp_server_socket.cc @@ -37,11 +37,11 @@ int UDPServerSocket::SendTo(IOBuffer* buf, return socket_.SendTo(buf, buf_len, address, callback); } -bool UDPServerSocket::SetReceiveBufferSize(int32 size) { +int UDPServerSocket::SetReceiveBufferSize(int32 size) { return socket_.SetReceiveBufferSize(size); } -bool UDPServerSocket::SetSendBufferSize(int32 size) { +int UDPServerSocket::SetSendBufferSize(int32 size) { return socket_.SetSendBufferSize(size); } diff --git a/net/udp/udp_server_socket.h b/net/udp/udp_server_socket.h index 46e8b78..4ce7354 100644 --- a/net/udp/udp_server_socket.h +++ b/net/udp/udp_server_socket.h @@ -31,8 +31,8 @@ class NET_EXPORT UDPServerSocket : public DatagramServerSocket { int buf_len, const IPEndPoint& address, const CompletionCallback& callback) OVERRIDE; - virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; - virtual bool SetSendBufferSize(int32 size) OVERRIDE; + virtual int SetReceiveBufferSize(int32 size) OVERRIDE; + virtual int SetSendBufferSize(int32 size) OVERRIDE; virtual void Close() OVERRIDE; virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc index 5646276..7db3f96 100644 --- a/net/udp/udp_socket_libevent.cc +++ b/net/udp/udp_socket_libevent.cc @@ -315,20 +315,22 @@ int UDPSocketLibevent::Bind(const IPEndPoint& address) { return rv; } -bool UDPSocketLibevent::SetReceiveBufferSize(int32 size) { +int 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; + int last_error = errno; + DCHECK(!rv) << "Could not set socket receive buffer size: " << last_error; + return rv == 0 ? OK : MapSystemError(last_error); } -bool UDPSocketLibevent::SetSendBufferSize(int32 size) { +int 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; + int last_error = errno; + DCHECK(!rv) << "Could not set socket send buffer size: " << last_error; + return rv == 0 ? OK : MapSystemError(last_error); } void UDPSocketLibevent::AllowAddressReuse() { diff --git a/net/udp/udp_socket_libevent.h b/net/udp/udp_socket_libevent.h index 130dcaf..8ec5c21 100644 --- a/net/udp/udp_socket_libevent.h +++ b/net/udp/udp_socket_libevent.h @@ -94,10 +94,10 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { const CompletionCallback& callback); // Set the receive buffer size (in bytes) for the socket. - bool SetReceiveBufferSize(int32 size); + int SetReceiveBufferSize(int32 size); // Set the send buffer size (in bytes) for the socket. - bool SetSendBufferSize(int32 size); + int 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 78f51c9..4f742b9 100644 --- a/net/udp/udp_socket_win.cc +++ b/net/udp/udp_socket_win.cc @@ -388,44 +388,47 @@ int UDPSocketWin::CreateSocket(int addr_family) { return OK; } -bool UDPSocketWin::SetReceiveBufferSize(int32 size) { +int UDPSocketWin::SetReceiveBufferSize(int32 size) { DCHECK(CalledOnValidThread()); - setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, - reinterpret_cast<const char*>(&size), sizeof(size)); - // If the setsockopt fails, but the buffer is big enough, we will return - // success. It is not worth testing the return value as we still need to check - // via getsockopt anyway according to Windows documentation. + int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, + reinterpret_cast<const char*>(&size), sizeof(size)); + if (rv != 0) + return MapSystemError(WSAGetLastError()); + + // According to documentation, setsockopt may succeed, but we need to check + // the results via getsockopt to be sure it works on Windows. int32 actual_size = 0; int option_size = sizeof(actual_size); - int rv = getsockopt(socket_, SOL_SOCKET, SO_RCVBUF, - reinterpret_cast<char*>(&actual_size), &option_size); + rv = getsockopt(socket_, SOL_SOCKET, SO_RCVBUF, + reinterpret_cast<char*>(&actual_size), &option_size); if (rv != 0) - return false; - if (actual_size < size) { - UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketReceiveBufferUnchangeable", - actual_size, 1000, 1000000, 50); - } - return actual_size >= size; + return MapSystemError(WSAGetLastError()); + if (actual_size >= size) + return OK; + UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableReceiveBuffer", + actual_size, 1000, 1000000, 50); + return ERR_SOCKET_RECEIVE_BUFFER_SIZE_UNCHANGEABLE; } -bool UDPSocketWin::SetSendBufferSize(int32 size) { +int UDPSocketWin::SetSendBufferSize(int32 size) { DCHECK(CalledOnValidThread()); - setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, - reinterpret_cast<const char*>(&size), sizeof(size)); - // If the setsockopt fails, but the buffer is big enough, we will return - // success. It is not worth testing the return value as we still need to check - // via getsockopt anyway according to Windows documentation. + int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, + reinterpret_cast<const char*>(&size), sizeof(size)); + if (rv != 0) + return MapSystemError(WSAGetLastError()); + // According to documentation, setsockopt may succeed, but we need to check + // the results via getsockopt to be sure it works on Windows. int32 actual_size = 0; int option_size = sizeof(actual_size); - int rv = getsockopt(socket_, SOL_SOCKET, SO_SNDBUF, - reinterpret_cast<char*>(&actual_size), &option_size); + rv = getsockopt(socket_, SOL_SOCKET, SO_SNDBUF, + reinterpret_cast<char*>(&actual_size), &option_size); if (rv != 0) - return false; - if (actual_size < size) { - UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableSendBuffer", - actual_size, 1000, 1000000, 50); - } - return actual_size >= size; + return MapSystemError(WSAGetLastError()); + if (actual_size >= size) + return OK; + UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableSendBuffer", + actual_size, 1000, 1000000, 50); + return ERR_SOCKET_SEND_BUFFER_SIZE_UNCHANGEABLE; } void UDPSocketWin::AllowAddressReuse() { diff --git a/net/udp/udp_socket_win.h b/net/udp/udp_socket_win.h index 28b7d4a..7ccb73f 100644 --- a/net/udp/udp_socket_win.h +++ b/net/udp/udp_socket_win.h @@ -95,10 +95,12 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) { const CompletionCallback& callback); // Set the receive buffer size (in bytes) for the socket. - bool SetReceiveBufferSize(int32 size); + // Returns a net error code. + int SetReceiveBufferSize(int32 size); // Set the send buffer size (in bytes) for the socket. - bool SetSendBufferSize(int32 size); + // Returns a net error code. + int SetSendBufferSize(int32 size); // Returns true if the socket is already connected or bound. bool is_connected() const { return socket_ != INVALID_SOCKET; } |