| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_client_socket_win.h" | 5 #include "net/socket/tcp_client_socket_win.h" |
| 6 | 6 |
| 7 #include <mstcpip.h> | |
| 8 | |
| 9 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 11 #include "base/memory_debug.h" | 9 #include "base/memory_debug.h" |
| 12 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
| 13 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 14 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 15 #include "base/win/object_watcher.h" | 13 #include "base/win/object_watcher.h" |
| 16 #include "net/base/address_list_net_log_param.h" | 14 #include "net/base/address_list_net_log_param.h" |
| 17 #include "net/base/connection_type_histograms.h" | 15 #include "net/base/connection_type_histograms.h" |
| 18 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 // Client writes 50 bytes of POST data (partial packet #2) | 724 // Client writes 50 bytes of POST data (partial packet #2) |
| 727 // In the above example, with Nagle, a RTT delay is inserted between these | 725 // In the above example, with Nagle, a RTT delay is inserted between these |
| 728 // two sends due to nagle. RTTs can easily be 100ms or more. The best | 726 // two sends due to nagle. RTTs can easily be 100ms or more. The best |
| 729 // fix is to make sure that for POSTing data, we write as much data as | 727 // fix is to make sure that for POSTing data, we write as much data as |
| 730 // possible and minimize partial packets. We will fix that. But disabling | 728 // possible and minimize partial packets. We will fix that. But disabling |
| 731 // Nagle also ensure we don't run into this delay in other edge cases. | 729 // Nagle also ensure we don't run into this delay in other edge cases. |
| 732 // See also: | 730 // See also: |
| 733 // http://technet.microsoft.com/en-us/library/bb726981.aspx | 731 // http://technet.microsoft.com/en-us/library/bb726981.aspx |
| 734 const BOOL kDisableNagle = TRUE; | 732 const BOOL kDisableNagle = TRUE; |
| 735 int rv = setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, | 733 int rv = setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, |
| 736 reinterpret_cast<const char*>(&kDisableNagle), | 734 reinterpret_cast<const char*>(&kDisableNagle), sizeof(kDisableNagle)); |
| 737 sizeof(kDisableNagle)); | |
| 738 DCHECK(!rv) << "Could not disable nagle"; | 735 DCHECK(!rv) << "Could not disable nagle"; |
| 739 | 736 |
| 740 // Enable TCP Keep-Alive to prevent NAT routers from timing out TCP | 737 // Disregard any failure in disabling nagle. |
| 741 // connections. See http://crbug.com/27400 for details. | |
| 742 | |
| 743 struct tcp_keepalive keepalive_vals = { | |
| 744 1, // TCP keep-alive on. | |
| 745 45000, // Wait 45s until sending first TCP keep-alive packet. | |
| 746 45000, // Wait 45s between sending TCP keep-alive packets. | |
| 747 }; | |
| 748 DWORD bytes_returned = 0xABAB; | |
| 749 rv = WSAIoctl(socket_, SIO_KEEPALIVE_VALS, &keepalive_vals, | |
| 750 sizeof(keepalive_vals), NULL, 0, | |
| 751 &bytes_returned, NULL, NULL); | |
| 752 DCHECK_EQ(0u, bytes_returned); | |
| 753 DCHECK(!rv) << "Could not enable TCP Keep-Alive for socket: " << socket_ | |
| 754 << " [error: " << WSAGetLastError() << "]."; | |
| 755 | |
| 756 // Disregard any failure in disabling nagle or enabling TCP Keep-Alive. | |
| 757 return 0; | 738 return 0; |
| 758 } | 739 } |
| 759 | 740 |
| 760 void TCPClientSocketWin::LogConnectCompletion(int net_error) { | 741 void TCPClientSocketWin::LogConnectCompletion(int net_error) { |
| 761 scoped_refptr<NetLog::EventParameters> params; | 742 scoped_refptr<NetLog::EventParameters> params; |
| 762 if (net_error != OK) | 743 if (net_error != OK) |
| 763 params = new NetLogIntegerParameter("net_error", net_error); | 744 params = new NetLogIntegerParameter("net_error", net_error); |
| 764 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, params); | 745 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, params); |
| 765 if (net_error == OK) | 746 if (net_error == OK) |
| 766 UpdateConnectionTypeHistograms(CONNECTION_ANY); | 747 UpdateConnectionTypeHistograms(CONNECTION_ANY); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 use_history_.set_was_used_to_convey_data(); | 841 use_history_.set_was_used_to_convey_data(); |
| 861 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, | 842 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
| 862 core_->write_buffer_.buf); | 843 core_->write_buffer_.buf); |
| 863 } | 844 } |
| 864 } | 845 } |
| 865 core_->write_iobuffer_ = NULL; | 846 core_->write_iobuffer_ = NULL; |
| 866 DoWriteCallback(rv); | 847 DoWriteCallback(rv); |
| 867 } | 848 } |
| 868 | 849 |
| 869 } // namespace net | 850 } // namespace net |
| OLD | NEW |