Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/transport_client_socket_pool.h" | 5 #include "net/socket/transport_client_socket_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_log.h" | 20 #include "net/base/net_log.h" |
| 21 #include "net/socket/client_socket_factory.h" | 21 #include "net/socket/client_socket_factory.h" |
| 22 #include "net/socket/client_socket_handle.h" | 22 #include "net/socket/client_socket_handle.h" |
| 23 #include "net/socket/client_socket_pool_base.h" | 23 #include "net/socket/client_socket_pool_base.h" |
| 24 #include "net/socket/socket_net_log_params.h" | 24 #include "net/socket/socket_net_log_params.h" |
| 25 #include "net/socket/tcp_client_socket.h" | 25 #include "net/socket/tcp_client_socket.h" |
| 26 | 26 |
| 27 using base::TimeDelta; | 27 using base::TimeDelta; |
| 28 extern bool g_tcp_fastopen_user_enabled; | |
| 29 extern bool g_tcp_fastopen_supported; | |
| 28 | 30 |
| 29 namespace net { | 31 namespace net { |
| 30 | 32 |
| 31 // TODO(willchan): Base this off RTT instead of statically setting it. Note we | 33 // TODO(willchan): Base this off RTT instead of statically setting it. Note we |
| 32 // choose a timeout that is different from the backup connect job timer so they | 34 // choose a timeout that is different from the backup connect job timer so they |
| 33 // don't synchronize. | 35 // don't synchronize. |
| 34 const int TransportConnectJobHelper::kIPv6FallbackTimerInMs = 300; | 36 const int TransportConnectJobHelper::kIPv6FallbackTimerInMs = 300; |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 53 g_last_connect_time_lock = LAZY_INSTANCE_INITIALIZER; | 55 g_last_connect_time_lock = LAZY_INSTANCE_INITIALIZER; |
| 54 | 56 |
| 55 // |g_last_connect_time| has the last time a connect() call is made. | 57 // |g_last_connect_time| has the last time a connect() call is made. |
| 56 static base::LazyInstance<base::TimeTicks>::Leaky | 58 static base::LazyInstance<base::TimeTicks>::Leaky |
| 57 g_last_connect_time = LAZY_INSTANCE_INITIALIZER; | 59 g_last_connect_time = LAZY_INSTANCE_INITIALIZER; |
| 58 | 60 |
| 59 TransportSocketParams::TransportSocketParams( | 61 TransportSocketParams::TransportSocketParams( |
| 60 const HostPortPair& host_port_pair, | 62 const HostPortPair& host_port_pair, |
| 61 bool disable_resolver_cache, | 63 bool disable_resolver_cache, |
| 62 bool ignore_limits, | 64 bool ignore_limits, |
| 63 const OnHostResolutionCallback& host_resolution_callback) | 65 const OnHostResolutionCallback& host_resolution_callback, |
| 66 CombineConnectAndWritePolicy combine_connect_and_write_if_supported) | |
| 64 : destination_(host_port_pair), | 67 : destination_(host_port_pair), |
| 65 ignore_limits_(ignore_limits), | 68 ignore_limits_(ignore_limits), |
| 66 host_resolution_callback_(host_resolution_callback) { | 69 host_resolution_callback_(host_resolution_callback), |
| 70 combine_connect_and_write_(combine_connect_and_write_if_supported) { | |
| 67 if (disable_resolver_cache) | 71 if (disable_resolver_cache) |
| 68 destination_.set_allow_cached_response(false); | 72 destination_.set_allow_cached_response(false); |
| 73 // combine_connect_and_write currently translates to TCP FastOpen. | |
| 74 // Enable TCP FastOpen if user wants it and system supports it. | |
| 75 if (!g_tcp_fastopen_supported) { | |
| 76 combine_connect_and_write_ = COMBINE_CONNECT_AND_WRITE_PROHIBITED; | |
| 77 } else { | |
| 78 if (g_tcp_fastopen_user_enabled && | |
| 79 combine_connect_and_write_ == COMBINE_CONNECT_AND_WRITE_DEFAULT) { | |
| 80 combine_connect_and_write_ = COMBINE_CONNECT_AND_WRITE_DESIRED; | |
| 81 } | |
| 82 } | |
| 69 } | 83 } |
| 70 | 84 |
| 71 TransportSocketParams::~TransportSocketParams() {} | 85 TransportSocketParams::~TransportSocketParams() {} |
| 72 | 86 |
| 73 // TransportConnectJobs will time out after this many seconds. Note this is | 87 // TransportConnectJobs will time out after this many seconds. Note this is |
| 74 // the total time, including both host resolution and TCP connect() times. | 88 // the total time, including both host resolution and TCP connect() times. |
| 75 // | 89 // |
| 76 // TODO(eroman): The use of this constant needs to be re-evaluated. The time | 90 // TODO(eroman): The use of this constant needs to be re-evaluated. The time |
| 77 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since | 91 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since |
| 78 // the address list may contain many alternatives, and most of those may | 92 // the address list may contain many alternatives, and most of those may |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 interval_between_connects_ = CONNECT_INTERVAL_LE_20MS; | 268 interval_between_connects_ = CONNECT_INTERVAL_LE_20MS; |
| 255 else | 269 else |
| 256 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; | 270 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; |
| 257 } | 271 } |
| 258 | 272 |
| 259 helper_.set_next_state( | 273 helper_.set_next_state( |
| 260 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE); | 274 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE); |
| 261 transport_socket_ = | 275 transport_socket_ = |
| 262 helper_.client_socket_factory()->CreateTransportClientSocket( | 276 helper_.client_socket_factory()->CreateTransportClientSocket( |
| 263 helper_.addresses(), net_log().net_log(), net_log().source()); | 277 helper_.addresses(), net_log().net_log(), net_log().source()); |
| 278 | |
| 279 bool try_ipv6_connect_with_ipv4_fallback = | |
|
mmenke
2014/09/10 17:32:23
optional: Maybe add a comment? Something like "I
Jana
2014/09/11 16:02:36
Done. Also added an RFC number to make it look off
| |
| 280 helper_.addresses().front().GetFamily() == ADDRESS_FAMILY_IPV6 && | |
| 281 !AddressListOnlyContainsIPv6(helper_.addresses()); | |
| 282 | |
| 283 // Enable TCP FastOpen if indicated by transport socket params. | |
| 284 // Note: We currently do not turn on TCP FastOpen for destinations where | |
| 285 // we try a TCP connect over IPv6 with fallback to IPv4. | |
| 286 if (!try_ipv6_connect_with_ipv4_fallback && | |
| 287 helper_.params()->combine_connect_and_write() == | |
| 288 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DESIRED) | |
| 289 transport_socket_->EnableTCPFastOpen(); | |
|
mmenke
2014/09/10 17:32:22
nit: Use braces when the conditional takes more t
Jana
2014/09/11 16:02:36
Done.
| |
| 290 | |
| 264 int rv = transport_socket_->Connect(helper_.on_io_complete()); | 291 int rv = transport_socket_->Connect(helper_.on_io_complete()); |
| 265 if (rv == ERR_IO_PENDING && | 292 if (rv == ERR_IO_PENDING && try_ipv6_connect_with_ipv4_fallback) { |
| 266 helper_.addresses().front().GetFamily() == ADDRESS_FAMILY_IPV6 && | |
| 267 !AddressListOnlyContainsIPv6(helper_.addresses())) { | |
| 268 fallback_timer_.Start( | 293 fallback_timer_.Start( |
| 269 FROM_HERE, | 294 FROM_HERE, |
| 270 base::TimeDelta::FromMilliseconds( | 295 base::TimeDelta::FromMilliseconds( |
| 271 TransportConnectJobHelper::kIPv6FallbackTimerInMs), | 296 TransportConnectJobHelper::kIPv6FallbackTimerInMs), |
| 272 this, | 297 this, |
| 273 &TransportConnectJob::DoIPv6FallbackTransportConnect); | 298 &TransportConnectJob::DoIPv6FallbackTransportConnect); |
| 274 } | 299 } |
| 275 return rv; | 300 return rv; |
| 276 } | 301 } |
| 277 | 302 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 HigherLayeredPool* higher_pool) { | 560 HigherLayeredPool* higher_pool) { |
| 536 base_.AddHigherLayeredPool(higher_pool); | 561 base_.AddHigherLayeredPool(higher_pool); |
| 537 } | 562 } |
| 538 | 563 |
| 539 void TransportClientSocketPool::RemoveHigherLayeredPool( | 564 void TransportClientSocketPool::RemoveHigherLayeredPool( |
| 540 HigherLayeredPool* higher_pool) { | 565 HigherLayeredPool* higher_pool) { |
| 541 base_.RemoveHigherLayeredPool(higher_pool); | 566 base_.RemoveHigherLayeredPool(higher_pool); |
| 542 } | 567 } |
| 543 | 568 |
| 544 } // namespace net | 569 } // namespace net |
| OLD | NEW |