Chromium Code Reviews| Index: net/udp/udp_socket_win.cc |
| diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc |
| index 78f51c97231c95b9c3e12a0b3116c30ba13687fc..6773f3001e524d4ea8add73aeaa54b7b76abd685 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.SocketReceiveBufferUnchangeable", |
| + actual_size, 1000, 1000000, 50); |
| + return ERR_SOCKET_SET_RECEIVE_BUFFER_SIZE_ERROR; |
|
wtc
2014/03/29 13:30:12
Please rename this error ERR_SOCKET_RECEIVE_BUFFER
jar (doing other things)
2014/04/01 23:50:39
Done.
|
| } |
| -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", |
|
wtc
2014/03/29 13:30:12
Nit: the two histogram names are not symmetric:
jar (doing other things)
2014/04/01 23:50:39
Yes... this was a mistake I made, where I updated
|
| + actual_size, 1000, 1000000, 50); |
| + return ERR_SOCKET_SET_SEND_BUFFER_SIZE_ERROR; |
|
wtc
2014/03/29 13:30:12
Please rename this error ERR_SOCKET_SEND_BUFFER_SI
jar (doing other things)
2014/04/01 23:50:39
Done.
|
| } |
| void UDPSocketWin::AllowAddressReuse() { |