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

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

Issue 7029049: Merge 84251, 85083, 85188, 85375. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/742/src/
Patch Set: Upload before checkin Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.cc ('k') | net/socket/transport_client_socket_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ 5 #ifndef NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_
6 #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ 6 #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 30 matching lines...) Expand all
41 void Initialize(RequestPriority priority, const GURL& referrer, 41 void Initialize(RequestPriority priority, const GURL& referrer,
42 bool disable_resolver_cache); 42 bool disable_resolver_cache);
43 43
44 HostResolver::RequestInfo destination_; 44 HostResolver::RequestInfo destination_;
45 bool ignore_limits_; 45 bool ignore_limits_;
46 46
47 DISALLOW_COPY_AND_ASSIGN(TransportSocketParams); 47 DISALLOW_COPY_AND_ASSIGN(TransportSocketParams);
48 }; 48 };
49 49
50 // TransportConnectJob handles the host resolution necessary for socket creation 50 // TransportConnectJob handles the host resolution necessary for socket creation
51 // and the transport (likely TCP) connect. 51 // and the transport (likely TCP) connect. TransportConnectJob also has fallback
52 // logic for IPv6 connect() timeouts (which may happen due to networks / routers
53 // with broken IPv6 support). Those timeouts take 20s, so rather than make the
54 // user wait 20s for the timeout to fire, we use a fallback timer
55 // (kIPv6FallbackTimerInMs) and start a connect() to a IPv4 address if the timer
56 // fires. Then we race the IPv4 connect() against the IPv6 connect() (which has
57 // a headstart) and return the one that completes first to the socket pool.
52 class TransportConnectJob : public ConnectJob { 58 class TransportConnectJob : public ConnectJob {
53 public: 59 public:
54 TransportConnectJob(const std::string& group_name, 60 TransportConnectJob(const std::string& group_name,
55 const scoped_refptr<TransportSocketParams>& params, 61 const scoped_refptr<TransportSocketParams>& params,
56 base::TimeDelta timeout_duration, 62 base::TimeDelta timeout_duration,
57 ClientSocketFactory* client_socket_factory, 63 ClientSocketFactory* client_socket_factory,
58 HostResolver* host_resolver, 64 HostResolver* host_resolver,
59 Delegate* delegate, 65 Delegate* delegate,
60 NetLog* net_log); 66 NetLog* net_log);
61 virtual ~TransportConnectJob(); 67 virtual ~TransportConnectJob();
62 68
63 // ConnectJob methods. 69 // ConnectJob methods.
64 virtual LoadState GetLoadState() const; 70 virtual LoadState GetLoadState() const;
65 71
72 // Makes |addrlist| start with an IPv4 address if |addrlist| contains any
73 // IPv4 address.
74 //
75 // WARNING: this method should only be used to implement the prefer-IPv4
76 // hack. It is a public method for the unit tests.
77 static void MakeAddrListStartWithIPv4(AddressList* addrlist);
78
79 static const int kIPv6FallbackTimerInMs;
80
66 private: 81 private:
67 enum State { 82 enum State {
68 STATE_RESOLVE_HOST, 83 STATE_RESOLVE_HOST,
69 STATE_RESOLVE_HOST_COMPLETE, 84 STATE_RESOLVE_HOST_COMPLETE,
70 STATE_TRANSPORT_CONNECT, 85 STATE_TRANSPORT_CONNECT,
71 STATE_TRANSPORT_CONNECT_COMPLETE, 86 STATE_TRANSPORT_CONNECT_COMPLETE,
72 STATE_NONE, 87 STATE_NONE,
73 }; 88 };
74 89
75 void OnIOComplete(int result); 90 void OnIOComplete(int result);
76 91
77 // Runs the state transition loop. 92 // Runs the state transition loop.
78 int DoLoop(int result); 93 int DoLoop(int result);
79 94
80 int DoResolveHost(); 95 int DoResolveHost();
81 int DoResolveHostComplete(int result); 96 int DoResolveHostComplete(int result);
82 int DoTransportConnect(); 97 int DoTransportConnect();
83 int DoTransportConnectComplete(int result); 98 int DoTransportConnectComplete(int result);
84 99
100 // Not part of the state machine.
101 void DoIPv6FallbackTransportConnect();
102 void DoIPv6FallbackTransportConnectComplete(int result);
103
85 // Begins the host resolution and the TCP connect. Returns OK on success 104 // Begins the host resolution and the TCP connect. Returns OK on success
86 // and ERR_IO_PENDING if it cannot immediately service the request. 105 // and ERR_IO_PENDING if it cannot immediately service the request.
87 // Otherwise, it returns a net error code. 106 // Otherwise, it returns a net error code.
88 virtual int ConnectInternal(); 107 virtual int ConnectInternal();
89 108
90 scoped_refptr<TransportSocketParams> params_; 109 scoped_refptr<TransportSocketParams> params_;
91 ClientSocketFactory* const client_socket_factory_; 110 ClientSocketFactory* const client_socket_factory_;
92 CompletionCallbackImpl<TransportConnectJob> callback_; 111 CompletionCallbackImpl<TransportConnectJob> callback_;
93 SingleRequestHostResolver resolver_; 112 SingleRequestHostResolver resolver_;
94 AddressList addresses_; 113 AddressList addresses_;
95 State next_state_; 114 State next_state_;
96 115
97 // The time Connect() was called. 116 // The time Connect() was called.
98 base::TimeTicks start_time_; 117 base::TimeTicks start_time_;
99 118
100 // The time the connect was started (after DNS finished). 119 // The time the connect was started (after DNS finished).
101 base::TimeTicks connect_start_time_; 120 base::TimeTicks connect_start_time_;
102 121
122 scoped_ptr<ClientSocket> transport_socket_;
123
124 scoped_ptr<ClientSocket> fallback_transport_socket_;
125 scoped_ptr<AddressList> fallback_addresses_;
126 CompletionCallbackImpl<TransportConnectJob> fallback_callback_;
127 base::TimeTicks fallback_connect_start_time_;
128 base::OneShotTimer<TransportConnectJob> fallback_timer_;
129
103 DISALLOW_COPY_AND_ASSIGN(TransportConnectJob); 130 DISALLOW_COPY_AND_ASSIGN(TransportConnectJob);
104 }; 131 };
105 132
106 class TransportClientSocketPool : public ClientSocketPool { 133 class TransportClientSocketPool : public ClientSocketPool {
107 public: 134 public:
108 TransportClientSocketPool( 135 TransportClientSocketPool(
109 int max_sockets, 136 int max_sockets,
110 int max_sockets_per_group, 137 int max_sockets_per_group,
111 ClientSocketPoolHistograms* histograms, 138 ClientSocketPoolHistograms* histograms,
112 HostResolver* host_resolver, 139 HostResolver* host_resolver,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 218
192 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPool); 219 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPool);
193 }; 220 };
194 221
195 REGISTER_SOCKET_PARAMS_FOR_POOL(TransportClientSocketPool, 222 REGISTER_SOCKET_PARAMS_FOR_POOL(TransportClientSocketPool,
196 TransportSocketParams); 223 TransportSocketParams);
197 224
198 } // namespace net 225 } // namespace net
199 226
200 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ 227 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_
OLDNEW
« no previous file with comments | « net/base/net_util.cc ('k') | net/socket/transport_client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698