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

Side by Side Diff: net/socket/tcp_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/socket/tcp_socket_win.h" 5 #include "net/socket/tcp_socket_win.h"
6 6
7 #include <mstcpip.h> 7 #include <mstcpip.h>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 #include "net/base/winsock_util.h" 21 #include "net/base/winsock_util.h"
22 #include "net/socket/socket_descriptor.h" 22 #include "net/socket/socket_descriptor.h"
23 #include "net/socket/socket_net_log_params.h" 23 #include "net/socket/socket_net_log_params.h"
24 24
25 namespace net { 25 namespace net {
26 26
27 namespace { 27 namespace {
28 28
29 const int kTCPKeepAliveSeconds = 45; 29 const int kTCPKeepAliveSeconds = 45;
30 30
31 bool SetSocketReceiveBufferSize(SOCKET socket, int32 size) { 31 int SetSocketReceiveBufferSize(SOCKET socket, int32 size) {
32 int rv = setsockopt(socket, SOL_SOCKET, SO_RCVBUF, 32 int rv = setsockopt(socket, SOL_SOCKET, SO_RCVBUF,
33 reinterpret_cast<const char*>(&size), sizeof(size)); 33 reinterpret_cast<const char*>(&size), sizeof(size));
34 DCHECK(!rv) << "Could not set socket receive buffer size: " << GetLastError(); 34 int net_error = (rv == 0) ? OK : MapSystemError(WSAGetLastError());
Ryan Hamilton 2014/04/08 19:55:11 Possibly again here with the map error code.
jar (doing other things) 2014/04/08 23:16:26 Since I'm not seeing any problems on Windows... I'
35 return rv == 0; 35 DCHECK(!rv) << "Could not set socket receive buffer size: " << net_error;
36 return net_error;
36 } 37 }
37 38
38 bool SetSocketSendBufferSize(SOCKET socket, int32 size) { 39 int SetSocketSendBufferSize(SOCKET socket, int32 size) {
39 int rv = setsockopt(socket, SOL_SOCKET, SO_SNDBUF, 40 int rv = setsockopt(socket, SOL_SOCKET, SO_SNDBUF,
40 reinterpret_cast<const char*>(&size), sizeof(size)); 41 reinterpret_cast<const char*>(&size), sizeof(size));
41 DCHECK(!rv) << "Could not set socket send buffer size: " << GetLastError(); 42 int net_error = (rv == 0) ? OK : MapSystemError(WSAGetLastError());
Ryan Hamilton 2014/04/08 19:55:11 we could consider doing the DCHECK here too.
jar (doing other things) 2014/04/08 23:16:26 See above.
42 return rv == 0; 43 DCHECK(!rv) << "Could not set socket send buffer size: " << net_error;
44 return net_error;
43 } 45 }
44 46
45 // Disable Nagle. 47 // Disable Nagle.
46 // The Nagle implementation on windows is governed by RFC 896. The idea 48 // The Nagle implementation on windows is governed by RFC 896. The idea
47 // behind Nagle is to reduce small packets on the network. When Nagle is 49 // behind Nagle is to reduce small packets on the network. When Nagle is
48 // enabled, if a partial packet has been sent, the TCP stack will disallow 50 // enabled, if a partial packet has been sent, the TCP stack will disallow
49 // further *partial* packets until an ACK has been received from the other 51 // further *partial* packets until an ACK has been received from the other
50 // side. Good applications should always strive to send as much data as 52 // side. Good applications should always strive to send as much data as
51 // possible and avoid partial-packet sends. However, in most real world 53 // possible and avoid partial-packet sends. However, in most real world
52 // applications, there are edge cases where this does not happen, and two 54 // applications, there are edge cases where this does not happen, and two
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 594
593 BOOL true_value = 1; 595 BOOL true_value = 1;
594 int rv = setsockopt(socket_, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, 596 int rv = setsockopt(socket_, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
595 reinterpret_cast<const char*>(&true_value), 597 reinterpret_cast<const char*>(&true_value),
596 sizeof(true_value)); 598 sizeof(true_value));
597 if (rv < 0) 599 if (rv < 0)
598 return MapSystemError(errno); 600 return MapSystemError(errno);
599 return OK; 601 return OK;
600 } 602 }
601 603
602 bool TCPSocketWin::SetReceiveBufferSize(int32 size) { 604 int TCPSocketWin::SetReceiveBufferSize(int32 size) {
603 DCHECK(CalledOnValidThread()); 605 DCHECK(CalledOnValidThread());
604 return SetSocketReceiveBufferSize(socket_, size); 606 return SetSocketReceiveBufferSize(socket_, size);
605 } 607 }
606 608
607 bool TCPSocketWin::SetSendBufferSize(int32 size) { 609 int TCPSocketWin::SetSendBufferSize(int32 size) {
608 DCHECK(CalledOnValidThread()); 610 DCHECK(CalledOnValidThread());
609 return SetSocketSendBufferSize(socket_, size); 611 return SetSocketSendBufferSize(socket_, size);
610 } 612 }
611 613
612 bool TCPSocketWin::SetKeepAlive(bool enable, int delay) { 614 bool TCPSocketWin::SetKeepAlive(bool enable, int delay) {
613 return SetTCPKeepAlive(socket_, enable, delay); 615 return SetTCPKeepAlive(socket_, enable, delay);
614 } 616 }
615 617
616 bool TCPSocketWin::SetNoDelay(bool no_delay) { 618 bool TCPSocketWin::SetNoDelay(bool no_delay) {
617 return DisableNagle(socket_, no_delay); 619 return DisableNagle(socket_, no_delay);
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 waiting_read_ = false; 994 waiting_read_ = false;
993 core_->read_iobuffer_ = NULL; 995 core_->read_iobuffer_ = NULL;
994 core_->read_buffer_length_ = 0; 996 core_->read_buffer_length_ = 0;
995 997
996 DCHECK_NE(rv, ERR_IO_PENDING); 998 DCHECK_NE(rv, ERR_IO_PENDING);
997 base::ResetAndReturn(&read_callback_).Run(rv); 999 base::ResetAndReturn(&read_callback_).Run(rv);
998 } 1000 }
999 1001
1000 } // namespace net 1002 } // namespace net
1001 1003
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698