Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: net/socket/transport_client_socket_pool.cc

Issue 451383002: Plumbing for TCP FastOpen for SSL sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to master. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
mmenke 2014/09/05 19:36:42 These values don't exist on windows. Also, think
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
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;
mmenke 2014/09/05 19:36:42 This isn't needed - we already have a check that i
77 else
78 if (g_tcp_fastopen_user_enabled &&
79 auto_connect_with_write_ == AUTO_CONNECT_USE_DEFAULT)
80 auto_connect_with_write_ = AUTO_CONNECT_ENABLED;
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
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 if (helper_.params()->auto_connect_with_write() == AUTO_CONNECT_ENABLED)
278 transport_socket_->EnableTCPFastOpen();
279
264 int rv = transport_socket_->Connect(helper_.on_io_complete()); 280 int rv = transport_socket_->Connect(helper_.on_io_complete());
265 if (rv == ERR_IO_PENDING && 281 if (rv == ERR_IO_PENDING &&
266 helper_.addresses().front().GetFamily() == ADDRESS_FAMILY_IPV6 && 282 helper_.addresses().front().GetFamily() == ADDRESS_FAMILY_IPV6 &&
267 !AddressListOnlyContainsIPv6(helper_.addresses())) { 283 !AddressListOnlyContainsIPv6(helper_.addresses())) {
268 fallback_timer_.Start( 284 fallback_timer_.Start(
269 FROM_HERE, 285 FROM_HERE,
270 base::TimeDelta::FromMilliseconds( 286 base::TimeDelta::FromMilliseconds(
271 TransportConnectJobHelper::kIPv6FallbackTimerInMs), 287 TransportConnectJobHelper::kIPv6FallbackTimerInMs),
272 this, 288 this,
273 &TransportConnectJob::DoIPv6FallbackTransportConnect); 289 &TransportConnectJob::DoIPv6FallbackTransportConnect);
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 HigherLayeredPool* higher_pool) { 551 HigherLayeredPool* higher_pool) {
536 base_.AddHigherLayeredPool(higher_pool); 552 base_.AddHigherLayeredPool(higher_pool);
537 } 553 }
538 554
539 void TransportClientSocketPool::RemoveHigherLayeredPool( 555 void TransportClientSocketPool::RemoveHigherLayeredPool(
540 HigherLayeredPool* higher_pool) { 556 HigherLayeredPool* higher_pool) {
541 base_.RemoveHigherLayeredPool(higher_pool); 557 base_.RemoveHigherLayeredPool(higher_pool);
542 } 558 }
543 559
544 } // namespace net 560 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698