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 AutoConnectWithWritePolicy auto_connect_with_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 auto_connect_with_write_(auto_connect_with_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 // Auto-connect currently translates to only TCP Fast Open. | |
| 74 // Enable TCP FastOpen if user wants it and system supports it. | |
| 75 if (!g_tcp_fastopen_supported) | |
| 76 auto_connect_with_write_ = AUTO_CONNECT_DISABLED; | |
| 77 else | |
|
mmenke
2014/09/09 14:29:28
Use braces for both cases of an if/else statement
Jana
2014/09/10 16:03:11
Done.
| |
| 78 if (g_tcp_fastopen_user_enabled && | |
| 79 auto_connect_with_write_ == AUTO_CONNECT_USE_DEFAULT) | |
| 80 auto_connect_with_write_ = AUTO_CONNECT_ENABLED; | |
|
mmenke
2014/09/09 14:29:28
Use braces for an if when the antecedent takes up
Jana
2014/09/10 16:03:11
Done.
| |
| 69 } | 81 } |
| 70 | 82 |
| 71 TransportSocketParams::~TransportSocketParams() {} | 83 TransportSocketParams::~TransportSocketParams() {} |
| 72 | 84 |
| 73 // TransportConnectJobs will time out after this many seconds. Note this is | 85 // TransportConnectJobs will time out after this many seconds. Note this is |
| 74 // the total time, including both host resolution and TCP connect() times. | 86 // the total time, including both host resolution and TCP connect() times. |
| 75 // | 87 // |
| 76 // TODO(eroman): The use of this constant needs to be re-evaluated. The time | 88 // TODO(eroman): The use of this constant needs to be re-evaluated. The time |
| 77 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since | 89 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since |
| 78 // the address list may contain many alternatives, and most of those may | 90 // 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; | 266 interval_between_connects_ = CONNECT_INTERVAL_LE_20MS; |
| 255 else | 267 else |
| 256 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; | 268 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; |
| 257 } | 269 } |
| 258 | 270 |
| 259 helper_.set_next_state( | 271 helper_.set_next_state( |
| 260 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE); | 272 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE); |
| 261 transport_socket_ = | 273 transport_socket_ = |
| 262 helper_.client_socket_factory()->CreateTransportClientSocket( | 274 helper_.client_socket_factory()->CreateTransportClientSocket( |
| 263 helper_.addresses(), net_log().net_log(), net_log().source()); | 275 helper_.addresses(), net_log().net_log(), net_log().source()); |
| 276 | |
| 277 // Enable TCP FastOpen if indicated by transport socket params. | |
| 278 // Note: We currently do not turn on TCP FastOpen for destinations where | |
| 279 // we might try a TCP connect over IPv6 with fallback to IPv4. | |
| 280 if (helper_.params()->auto_connect_with_write() == AUTO_CONNECT_ENABLED && | |
| 281 (helper_.addresses().front().GetFamily() != ADDRESS_FAMILY_IPV6 || | |
| 282 AddressListOnlyContainsIPv6(helper_.addresses()))) | |
|
mmenke
2014/09/09 14:29:28
optional: Think this is a little clearer if the l
mmenke
2014/09/09 16:03:33
Should we have any tests for this? Not sure how h
mmenke
2014/09/09 16:03:33
optional: Or may be clearer as a function in an a
Jana
2014/09/10 16:03:11
Acknowledged.
Jana
2014/09/10 16:03:11
Do you have a pointer for a test that currently te
mmenke
2014/09/10 17:32:22
Yea, we'd need to force the tests to think they ha
Jana
2014/09/11 16:02:36
Tests added in transport_client_socket_pool_unitte
| |
| 283 transport_socket_->EnableTCPFastOpen(); | |
|
mmenke
2014/09/09 14:29:28
use braces.
Jana
2014/09/10 16:03:11
This code has changed, but what's the formatting l
mmenke
2014/09/10 17:32:22
It's because the antecedent of the if statement ta
Jana
2014/09/11 16:02:36
Acknowledged.
| |
| 284 | |
| 264 int rv = transport_socket_->Connect(helper_.on_io_complete()); | 285 int rv = transport_socket_->Connect(helper_.on_io_complete()); |
| 265 if (rv == ERR_IO_PENDING && | 286 if (rv == ERR_IO_PENDING && |
| 266 helper_.addresses().front().GetFamily() == ADDRESS_FAMILY_IPV6 && | 287 helper_.addresses().front().GetFamily() == ADDRESS_FAMILY_IPV6 && |
| 267 !AddressListOnlyContainsIPv6(helper_.addresses())) { | 288 !AddressListOnlyContainsIPv6(helper_.addresses())) { |
| 268 fallback_timer_.Start( | 289 fallback_timer_.Start( |
| 269 FROM_HERE, | 290 FROM_HERE, |
| 270 base::TimeDelta::FromMilliseconds( | 291 base::TimeDelta::FromMilliseconds( |
| 271 TransportConnectJobHelper::kIPv6FallbackTimerInMs), | 292 TransportConnectJobHelper::kIPv6FallbackTimerInMs), |
| 272 this, | 293 this, |
| 273 &TransportConnectJob::DoIPv6FallbackTransportConnect); | 294 &TransportConnectJob::DoIPv6FallbackTransportConnect); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 HigherLayeredPool* higher_pool) { | 556 HigherLayeredPool* higher_pool) { |
| 536 base_.AddHigherLayeredPool(higher_pool); | 557 base_.AddHigherLayeredPool(higher_pool); |
| 537 } | 558 } |
| 538 | 559 |
| 539 void TransportClientSocketPool::RemoveHigherLayeredPool( | 560 void TransportClientSocketPool::RemoveHigherLayeredPool( |
| 540 HigherLayeredPool* higher_pool) { | 561 HigherLayeredPool* higher_pool) { |
| 541 base_.RemoveHigherLayeredPool(higher_pool); | 562 base_.RemoveHigherLayeredPool(higher_pool); |
| 542 } | 563 } |
| 543 | 564 |
| 544 } // namespace net | 565 } // namespace net |
| OLD | NEW |