Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: net/udp/udp_socket_win.cc

Issue 217573002: make SetReceiveBufferSize and SetSendBufferSize return net error codes (instead of bools) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo on Linux Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4f742b93f03c1b475526bf4683ec86ec63721cc8 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());
Ryan Hamilton 2014/04/08 19:55:11 possibly here too.
jar (doing other things) 2014/04/08 23:16:26 Since Windows has not shown any problems, I'd rath
+
+ // 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() {

Powered by Google App Engine
This is Rietveld 408576698