OLD | NEW |
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 Loading... |
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 int SetSocketReceiveBufferSize(SOCKET socket, int32 size) { | 31 bool 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 int net_error = (rv == 0) ? OK : MapSystemError(WSAGetLastError()); | 34 DCHECK(!rv) << "Could not set socket receive buffer size: " << GetLastError(); |
35 DCHECK(!rv) << "Could not set socket receive buffer size: " << net_error; | 35 return rv == 0; |
36 return net_error; | |
37 } | 36 } |
38 | 37 |
39 int SetSocketSendBufferSize(SOCKET socket, int32 size) { | 38 bool SetSocketSendBufferSize(SOCKET socket, int32 size) { |
40 int rv = setsockopt(socket, SOL_SOCKET, SO_SNDBUF, | 39 int rv = setsockopt(socket, SOL_SOCKET, SO_SNDBUF, |
41 reinterpret_cast<const char*>(&size), sizeof(size)); | 40 reinterpret_cast<const char*>(&size), sizeof(size)); |
42 int net_error = (rv == 0) ? OK : MapSystemError(WSAGetLastError()); | 41 DCHECK(!rv) << "Could not set socket send buffer size: " << GetLastError(); |
43 DCHECK(!rv) << "Could not set socket send buffer size: " << net_error; | 42 return rv == 0; |
44 return net_error; | |
45 } | 43 } |
46 | 44 |
47 // Disable Nagle. | 45 // Disable Nagle. |
48 // The Nagle implementation on windows is governed by RFC 896. The idea | 46 // The Nagle implementation on windows is governed by RFC 896. The idea |
49 // behind Nagle is to reduce small packets on the network. When Nagle is | 47 // behind Nagle is to reduce small packets on the network. When Nagle is |
50 // enabled, if a partial packet has been sent, the TCP stack will disallow | 48 // enabled, if a partial packet has been sent, the TCP stack will disallow |
51 // further *partial* packets until an ACK has been received from the other | 49 // further *partial* packets until an ACK has been received from the other |
52 // side. Good applications should always strive to send as much data as | 50 // side. Good applications should always strive to send as much data as |
53 // possible and avoid partial-packet sends. However, in most real world | 51 // possible and avoid partial-packet sends. However, in most real world |
54 // applications, there are edge cases where this does not happen, and two | 52 // applications, there are edge cases where this does not happen, and two |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 592 |
595 BOOL true_value = 1; | 593 BOOL true_value = 1; |
596 int rv = setsockopt(socket_, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, | 594 int rv = setsockopt(socket_, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, |
597 reinterpret_cast<const char*>(&true_value), | 595 reinterpret_cast<const char*>(&true_value), |
598 sizeof(true_value)); | 596 sizeof(true_value)); |
599 if (rv < 0) | 597 if (rv < 0) |
600 return MapSystemError(errno); | 598 return MapSystemError(errno); |
601 return OK; | 599 return OK; |
602 } | 600 } |
603 | 601 |
604 int TCPSocketWin::SetReceiveBufferSize(int32 size) { | 602 bool TCPSocketWin::SetReceiveBufferSize(int32 size) { |
605 DCHECK(CalledOnValidThread()); | 603 DCHECK(CalledOnValidThread()); |
606 return SetSocketReceiveBufferSize(socket_, size); | 604 return SetSocketReceiveBufferSize(socket_, size); |
607 } | 605 } |
608 | 606 |
609 int TCPSocketWin::SetSendBufferSize(int32 size) { | 607 bool TCPSocketWin::SetSendBufferSize(int32 size) { |
610 DCHECK(CalledOnValidThread()); | 608 DCHECK(CalledOnValidThread()); |
611 return SetSocketSendBufferSize(socket_, size); | 609 return SetSocketSendBufferSize(socket_, size); |
612 } | 610 } |
613 | 611 |
614 bool TCPSocketWin::SetKeepAlive(bool enable, int delay) { | 612 bool TCPSocketWin::SetKeepAlive(bool enable, int delay) { |
615 return SetTCPKeepAlive(socket_, enable, delay); | 613 return SetTCPKeepAlive(socket_, enable, delay); |
616 } | 614 } |
617 | 615 |
618 bool TCPSocketWin::SetNoDelay(bool no_delay) { | 616 bool TCPSocketWin::SetNoDelay(bool no_delay) { |
619 return DisableNagle(socket_, no_delay); | 617 return DisableNagle(socket_, no_delay); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 waiting_read_ = false; | 992 waiting_read_ = false; |
995 core_->read_iobuffer_ = NULL; | 993 core_->read_iobuffer_ = NULL; |
996 core_->read_buffer_length_ = 0; | 994 core_->read_buffer_length_ = 0; |
997 | 995 |
998 DCHECK_NE(rv, ERR_IO_PENDING); | 996 DCHECK_NE(rv, ERR_IO_PENDING); |
999 base::ResetAndReturn(&read_callback_).Run(rv); | 997 base::ResetAndReturn(&read_callback_).Run(rv); |
1000 } | 998 } |
1001 | 999 |
1002 } // namespace net | 1000 } // namespace net |
1003 | 1001 |
OLD | NEW |