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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/udp/udp_socket_win.h" 5 #include "net/udp/udp_socket_win.h"
6 6
7 #include <mstcpip.h> 7 #include <mstcpip.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 int UDPSocketWin::CreateSocket(int addr_family) { 382 int UDPSocketWin::CreateSocket(int addr_family) {
383 addr_family_ = addr_family; 383 addr_family_ = addr_family;
384 socket_ = CreatePlatformSocket(addr_family_, SOCK_DGRAM, IPPROTO_UDP); 384 socket_ = CreatePlatformSocket(addr_family_, SOCK_DGRAM, IPPROTO_UDP);
385 if (socket_ == INVALID_SOCKET) 385 if (socket_ == INVALID_SOCKET)
386 return MapSystemError(WSAGetLastError()); 386 return MapSystemError(WSAGetLastError());
387 core_ = new Core(this); 387 core_ = new Core(this);
388 return OK; 388 return OK;
389 } 389 }
390 390
391 bool UDPSocketWin::SetReceiveBufferSize(int32 size) { 391 int UDPSocketWin::SetReceiveBufferSize(int32 size) {
392 DCHECK(CalledOnValidThread()); 392 DCHECK(CalledOnValidThread());
393 setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, 393 int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
394 reinterpret_cast<const char*>(&size), sizeof(size)); 394 reinterpret_cast<const char*>(&size), sizeof(size));
395 // If the setsockopt fails, but the buffer is big enough, we will return 395 if (rv != 0)
396 // success. It is not worth testing the return value as we still need to check 396 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
397 // via getsockopt anyway according to Windows documentation. 397
398 // According to documentation, setsockopt may succeed, but we need to check
399 // the results via getsockopt to be sure it works on Windows.
398 int32 actual_size = 0; 400 int32 actual_size = 0;
399 int option_size = sizeof(actual_size); 401 int option_size = sizeof(actual_size);
400 int rv = getsockopt(socket_, SOL_SOCKET, SO_RCVBUF, 402 rv = getsockopt(socket_, SOL_SOCKET, SO_RCVBUF,
401 reinterpret_cast<char*>(&actual_size), &option_size); 403 reinterpret_cast<char*>(&actual_size), &option_size);
402 if (rv != 0) 404 if (rv != 0)
403 return false; 405 return MapSystemError(WSAGetLastError());
404 if (actual_size < size) { 406 if (actual_size >= size)
405 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketReceiveBufferUnchangeable", 407 return OK;
406 actual_size, 1000, 1000000, 50); 408 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableReceiveBuffer",
407 } 409 actual_size, 1000, 1000000, 50);
408 return actual_size >= size; 410 return ERR_SOCKET_RECEIVE_BUFFER_SIZE_UNCHANGEABLE;
409 } 411 }
410 412
411 bool UDPSocketWin::SetSendBufferSize(int32 size) { 413 int UDPSocketWin::SetSendBufferSize(int32 size) {
412 DCHECK(CalledOnValidThread()); 414 DCHECK(CalledOnValidThread());
413 setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, 415 int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
414 reinterpret_cast<const char*>(&size), sizeof(size)); 416 reinterpret_cast<const char*>(&size), sizeof(size));
415 // If the setsockopt fails, but the buffer is big enough, we will return 417 if (rv != 0)
416 // success. It is not worth testing the return value as we still need to check 418 return MapSystemError(WSAGetLastError());
417 // via getsockopt anyway according to Windows documentation. 419 // According to documentation, setsockopt may succeed, but we need to check
420 // the results via getsockopt to be sure it works on Windows.
418 int32 actual_size = 0; 421 int32 actual_size = 0;
419 int option_size = sizeof(actual_size); 422 int option_size = sizeof(actual_size);
420 int rv = getsockopt(socket_, SOL_SOCKET, SO_SNDBUF, 423 rv = getsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
421 reinterpret_cast<char*>(&actual_size), &option_size); 424 reinterpret_cast<char*>(&actual_size), &option_size);
422 if (rv != 0) 425 if (rv != 0)
423 return false; 426 return MapSystemError(WSAGetLastError());
424 if (actual_size < size) { 427 if (actual_size >= size)
425 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableSendBuffer", 428 return OK;
426 actual_size, 1000, 1000000, 50); 429 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SocketUnchangeableSendBuffer",
427 } 430 actual_size, 1000, 1000000, 50);
428 return actual_size >= size; 431 return ERR_SOCKET_SEND_BUFFER_SIZE_UNCHANGEABLE;
429 } 432 }
430 433
431 void UDPSocketWin::AllowAddressReuse() { 434 void UDPSocketWin::AllowAddressReuse() {
432 DCHECK(CalledOnValidThread()); 435 DCHECK(CalledOnValidThread());
433 DCHECK(!is_connected()); 436 DCHECK(!is_connected());
434 437
435 socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS; 438 socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS;
436 } 439 }
437 440
438 void UDPSocketWin::AllowBroadcast() { 441 void UDPSocketWin::AllowBroadcast() {
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // Note: setsockopt(IP_TOS) does not work on windows XP and later. 835 // Note: setsockopt(IP_TOS) does not work on windows XP and later.
833 int UDPSocketWin::SetDiffServCodePoint(DiffServCodePoint dscp) { 836 int UDPSocketWin::SetDiffServCodePoint(DiffServCodePoint dscp) {
834 return ERR_NOT_IMPLEMENTED; 837 return ERR_NOT_IMPLEMENTED;
835 } 838 }
836 839
837 void UDPSocketWin::DetachFromThread() { 840 void UDPSocketWin::DetachFromThread() {
838 base::NonThreadSafe::DetachFromThread(); 841 base::NonThreadSafe::DetachFromThread();
839 } 842 }
840 843
841 } // namespace net 844 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698