| 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.h" | 5 #include "net/socket/tcp_socket.h" |
| 6 #include "net/socket/tcp_socket_win.h" | 6 #include "net/socket/tcp_socket_win.h" |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <mstcpip.h> | 9 #include <mstcpip.h> |
| 10 | 10 |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
| 16 #include "base/win/windows_version.h" | |
| 17 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
| 18 #include "net/base/connection_type_histograms.h" | 17 #include "net/base/connection_type_histograms.h" |
| 19 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 20 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
| 21 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 22 #include "net/base/network_activity_monitor.h" | 21 #include "net/base/network_activity_monitor.h" |
| 23 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
| 24 #include "net/base/sockaddr_storage.h" | 23 #include "net/base/sockaddr_storage.h" |
| 25 #include "net/base/winsock_init.h" | 24 #include "net/base/winsock_init.h" |
| 26 #include "net/base/winsock_util.h" | 25 #include "net/base/winsock_util.h" |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 return ERR_SOCKET_NOT_CONNECTED; | 572 return ERR_SOCKET_NOT_CONNECTED; |
| 574 *address = *peer_address_; | 573 *address = *peer_address_; |
| 575 return OK; | 574 return OK; |
| 576 } | 575 } |
| 577 | 576 |
| 578 int TCPSocketWin::SetDefaultOptionsForServer() { | 577 int TCPSocketWin::SetDefaultOptionsForServer() { |
| 579 return SetExclusiveAddrUse(); | 578 return SetExclusiveAddrUse(); |
| 580 } | 579 } |
| 581 | 580 |
| 582 void TCPSocketWin::SetDefaultOptionsForClient() { | 581 void TCPSocketWin::SetDefaultOptionsForClient() { |
| 583 // Increase the socket buffer sizes from the default sizes for WinXP. In | |
| 584 // performance testing, there is substantial benefit by increasing from 8KB | |
| 585 // to 64KB. | |
| 586 // See also: | |
| 587 // http://support.microsoft.com/kb/823764/EN-US | |
| 588 // On Vista, if we manually set these sizes, Vista turns off its receive | |
| 589 // window auto-tuning feature. | |
| 590 // http://blogs.msdn.com/wndp/archive/2006/05/05/Winhec-blog-tcpip-2.aspx | |
| 591 // Since Vista's auto-tune is better than any static value we can could set, | |
| 592 // only change these on pre-vista machines. | |
| 593 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | |
| 594 const int32_t kSocketBufferSize = 64 * 1024; | |
| 595 SetSocketReceiveBufferSize(socket_, kSocketBufferSize); | |
| 596 SetSocketSendBufferSize(socket_, kSocketBufferSize); | |
| 597 } | |
| 598 | |
| 599 DisableNagle(socket_, true); | 582 DisableNagle(socket_, true); |
| 600 SetTCPKeepAlive(socket_, true, kTCPKeepAliveSeconds); | 583 SetTCPKeepAlive(socket_, true, kTCPKeepAliveSeconds); |
| 601 } | 584 } |
| 602 | 585 |
| 603 int TCPSocketWin::SetExclusiveAddrUse() { | 586 int TCPSocketWin::SetExclusiveAddrUse() { |
| 604 // On Windows, a bound end point can be hijacked by another process by | 587 // On Windows, a bound end point can be hijacked by another process by |
| 605 // setting SO_REUSEADDR. Therefore a Windows-only option SO_EXCLUSIVEADDRUSE | 588 // setting SO_REUSEADDR. Therefore a Windows-only option SO_EXCLUSIVEADDRUSE |
| 606 // was introduced in Windows NT 4.0 SP4. If the socket that is bound to the | 589 // was introduced in Windows NT 4.0 SP4. If the socket that is bound to the |
| 607 // end point has SO_EXCLUSIVEADDRUSE enabled, it is not possible for another | 590 // end point has SO_EXCLUSIVEADDRUSE enabled, it is not possible for another |
| 608 // socket to forcibly bind to the end point until the end point is unbound. | 591 // socket to forcibly bind to the end point until the end point is unbound. |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 } | 1034 } |
| 1052 | 1035 |
| 1053 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { | 1036 bool TCPSocketWin::GetEstimatedRoundTripTime(base::TimeDelta* out_rtt) const { |
| 1054 DCHECK(out_rtt); | 1037 DCHECK(out_rtt); |
| 1055 // TODO(bmcquade): Consider implementing using | 1038 // TODO(bmcquade): Consider implementing using |
| 1056 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats. | 1039 // GetPerTcpConnectionEStats/GetPerTcp6ConnectionEStats. |
| 1057 return false; | 1040 return false; |
| 1058 } | 1041 } |
| 1059 | 1042 |
| 1060 } // namespace net | 1043 } // namespace net |
| OLD | NEW |