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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 g_last_connect_time_lock = LAZY_INSTANCE_INITIALIZER; | 53 g_last_connect_time_lock = LAZY_INSTANCE_INITIALIZER; |
54 | 54 |
55 // |g_last_connect_time| has the last time a connect() call is made. | 55 // |g_last_connect_time| has the last time a connect() call is made. |
56 static base::LazyInstance<base::TimeTicks>::Leaky | 56 static base::LazyInstance<base::TimeTicks>::Leaky |
57 g_last_connect_time = LAZY_INSTANCE_INITIALIZER; | 57 g_last_connect_time = LAZY_INSTANCE_INITIALIZER; |
58 | 58 |
59 TransportSocketParams::TransportSocketParams( | 59 TransportSocketParams::TransportSocketParams( |
60 const HostPortPair& host_port_pair, | 60 const HostPortPair& host_port_pair, |
61 bool disable_resolver_cache, | 61 bool disable_resolver_cache, |
62 bool ignore_limits, | 62 bool ignore_limits, |
63 const OnHostResolutionCallback& host_resolution_callback) | 63 const OnHostResolutionCallback& host_resolution_callback, |
| 64 CombineConnectAndWritePolicy combine_connect_and_write_if_supported) |
64 : destination_(host_port_pair), | 65 : destination_(host_port_pair), |
65 ignore_limits_(ignore_limits), | 66 ignore_limits_(ignore_limits), |
66 host_resolution_callback_(host_resolution_callback) { | 67 host_resolution_callback_(host_resolution_callback), |
| 68 combine_connect_and_write_(combine_connect_and_write_if_supported) { |
67 if (disable_resolver_cache) | 69 if (disable_resolver_cache) |
68 destination_.set_allow_cached_response(false); | 70 destination_.set_allow_cached_response(false); |
| 71 // combine_connect_and_write currently translates to TCP FastOpen. |
| 72 // Enable TCP FastOpen if user wants it. |
| 73 if (combine_connect_and_write_ == COMBINE_CONNECT_AND_WRITE_DEFAULT) { |
| 74 IsTCPFastOpenUserEnabled() ? combine_connect_and_write_ = |
| 75 COMBINE_CONNECT_AND_WRITE_DESIRED : |
| 76 COMBINE_CONNECT_AND_WRITE_PROHIBITED; |
| 77 } |
69 } | 78 } |
70 | 79 |
71 TransportSocketParams::~TransportSocketParams() {} | 80 TransportSocketParams::~TransportSocketParams() {} |
72 | 81 |
73 // TransportConnectJobs will time out after this many seconds. Note this is | 82 // TransportConnectJobs will time out after this many seconds. Note this is |
74 // the total time, including both host resolution and TCP connect() times. | 83 // the total time, including both host resolution and TCP connect() times. |
75 // | 84 // |
76 // TODO(eroman): The use of this constant needs to be re-evaluated. The time | 85 // TODO(eroman): The use of this constant needs to be re-evaluated. The time |
77 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since | 86 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since |
78 // the address list may contain many alternatives, and most of those may | 87 // 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; | 263 interval_between_connects_ = CONNECT_INTERVAL_LE_20MS; |
255 else | 264 else |
256 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; | 265 interval_between_connects_ = CONNECT_INTERVAL_GT_20MS; |
257 } | 266 } |
258 | 267 |
259 helper_.set_next_state( | 268 helper_.set_next_state( |
260 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE); | 269 TransportConnectJobHelper::STATE_TRANSPORT_CONNECT_COMPLETE); |
261 transport_socket_ = | 270 transport_socket_ = |
262 helper_.client_socket_factory()->CreateTransportClientSocket( | 271 helper_.client_socket_factory()->CreateTransportClientSocket( |
263 helper_.addresses(), net_log().net_log(), net_log().source()); | 272 helper_.addresses(), net_log().net_log(), net_log().source()); |
| 273 |
| 274 // If the list contains IPv6 and IPv4 addresses, the first address will |
| 275 // be IPv6, and the IPv4 addresses will be tried as fallback addresses, |
| 276 // per "Happy Eyeballs" (RFC 6555). |
| 277 bool try_ipv6_connect_with_ipv4_fallback = |
| 278 helper_.addresses().front().GetFamily() == ADDRESS_FAMILY_IPV6 && |
| 279 !AddressListOnlyContainsIPv6(helper_.addresses()); |
| 280 |
| 281 // Enable TCP FastOpen if indicated by transport socket params. |
| 282 // Note: We currently do not turn on TCP FastOpen for destinations where |
| 283 // we try a TCP connect over IPv6 with fallback to IPv4. |
| 284 if (!try_ipv6_connect_with_ipv4_fallback && |
| 285 helper_.params()->combine_connect_and_write() == |
| 286 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DESIRED) { |
| 287 transport_socket_->EnableTCPFastOpenIfSupported(); |
| 288 } |
| 289 |
264 int rv = transport_socket_->Connect(helper_.on_io_complete()); | 290 int rv = transport_socket_->Connect(helper_.on_io_complete()); |
265 if (rv == ERR_IO_PENDING && | 291 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( | 292 fallback_timer_.Start( |
269 FROM_HERE, | 293 FROM_HERE, |
270 base::TimeDelta::FromMilliseconds( | 294 base::TimeDelta::FromMilliseconds( |
271 TransportConnectJobHelper::kIPv6FallbackTimerInMs), | 295 TransportConnectJobHelper::kIPv6FallbackTimerInMs), |
272 this, | 296 this, |
273 &TransportConnectJob::DoIPv6FallbackTransportConnect); | 297 &TransportConnectJob::DoIPv6FallbackTransportConnect); |
274 } | 298 } |
275 return rv; | 299 return rv; |
276 } | 300 } |
277 | 301 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 HigherLayeredPool* higher_pool) { | 559 HigherLayeredPool* higher_pool) { |
536 base_.AddHigherLayeredPool(higher_pool); | 560 base_.AddHigherLayeredPool(higher_pool); |
537 } | 561 } |
538 | 562 |
539 void TransportClientSocketPool::RemoveHigherLayeredPool( | 563 void TransportClientSocketPool::RemoveHigherLayeredPool( |
540 HigherLayeredPool* higher_pool) { | 564 HigherLayeredPool* higher_pool) { |
541 base_.RemoveHigherLayeredPool(higher_pool); | 565 base_.RemoveHigherLayeredPool(higher_pool); |
542 } | 566 } |
543 | 567 |
544 } // namespace net | 568 } // namespace net |
OLD | NEW |