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