| 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 #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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
| 16 #include "net/dns/host_resolver.h" | 16 #include "net/dns/host_resolver.h" |
| 17 #include "net/dns/single_request_host_resolver.h" | 17 #include "net/dns/single_request_host_resolver.h" |
| 18 #include "net/socket/client_socket_pool.h" | 18 #include "net/socket/client_socket_pool.h" |
| 19 #include "net/socket/client_socket_pool_base.h" | 19 #include "net/socket/client_socket_pool_base.h" |
| 20 #include "net/socket/connection_attempts.h" | 20 #include "net/socket/connection_attempts.h" |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 class ClientSocketFactory; | 24 class ClientSocketFactory; |
| 25 class SocketPerformanceWatcherFactory; |
| 25 | 26 |
| 26 typedef base::Callback<int(const AddressList&, const BoundNetLog& net_log)> | 27 typedef base::Callback<int(const AddressList&, const BoundNetLog& net_log)> |
| 27 OnHostResolutionCallback; | 28 OnHostResolutionCallback; |
| 28 | 29 |
| 29 class NET_EXPORT_PRIVATE TransportSocketParams | 30 class NET_EXPORT_PRIVATE TransportSocketParams |
| 30 : public base::RefCounted<TransportSocketParams> { | 31 : public base::RefCounted<TransportSocketParams> { |
| 31 public: | 32 public: |
| 32 // CombineConnectAndWrite currently translates to using TCP FastOpen. | 33 // CombineConnectAndWrite currently translates to using TCP FastOpen. |
| 33 // TCP FastOpen should not be used if the first write to the socket may | 34 // TCP FastOpen should not be used if the first write to the socket may |
| 34 // be non-idempotent, as the underlying socket could retransmit the data | 35 // be non-idempotent, as the underlying socket could retransmit the data |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // TransportConnectJob handles the host resolution necessary for socket creation | 147 // TransportConnectJob handles the host resolution necessary for socket creation |
| 147 // and the transport (likely TCP) connect. TransportConnectJob also has fallback | 148 // and the transport (likely TCP) connect. TransportConnectJob also has fallback |
| 148 // logic for IPv6 connect() timeouts (which may happen due to networks / routers | 149 // logic for IPv6 connect() timeouts (which may happen due to networks / routers |
| 149 // with broken IPv6 support). Those timeouts take 20s, so rather than make the | 150 // with broken IPv6 support). Those timeouts take 20s, so rather than make the |
| 150 // user wait 20s for the timeout to fire, we use a fallback timer | 151 // user wait 20s for the timeout to fire, we use a fallback timer |
| 151 // (kIPv6FallbackTimerInMs) and start a connect() to a IPv4 address if the timer | 152 // (kIPv6FallbackTimerInMs) and start a connect() to a IPv4 address if the timer |
| 152 // fires. Then we race the IPv4 connect() against the IPv6 connect() (which has | 153 // fires. Then we race the IPv4 connect() against the IPv6 connect() (which has |
| 153 // a headstart) and return the one that completes first to the socket pool. | 154 // a headstart) and return the one that completes first to the socket pool. |
| 154 class NET_EXPORT_PRIVATE TransportConnectJob : public ConnectJob { | 155 class NET_EXPORT_PRIVATE TransportConnectJob : public ConnectJob { |
| 155 public: | 156 public: |
| 156 TransportConnectJob(const std::string& group_name, | 157 TransportConnectJob( |
| 157 RequestPriority priority, | 158 const std::string& group_name, |
| 158 ClientSocketPool::RespectLimits respect_limits, | 159 RequestPriority priority, |
| 159 const scoped_refptr<TransportSocketParams>& params, | 160 ClientSocketPool::RespectLimits respect_limits, |
| 160 base::TimeDelta timeout_duration, | 161 const scoped_refptr<TransportSocketParams>& params, |
| 161 ClientSocketFactory* client_socket_factory, | 162 base::TimeDelta timeout_duration, |
| 162 HostResolver* host_resolver, | 163 ClientSocketFactory* client_socket_factory, |
| 163 Delegate* delegate, | 164 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
| 164 NetLog* net_log); | 165 HostResolver* host_resolver, |
| 166 Delegate* delegate, |
| 167 NetLog* net_log); |
| 165 ~TransportConnectJob() override; | 168 ~TransportConnectJob() override; |
| 166 | 169 |
| 167 // ConnectJob methods. | 170 // ConnectJob methods. |
| 168 LoadState GetLoadState() const override; | 171 LoadState GetLoadState() const override; |
| 169 void GetAdditionalErrorState(ClientSocketHandle* handle) override; | 172 void GetAdditionalErrorState(ClientSocketHandle* handle) override; |
| 170 | 173 |
| 171 // Rolls |addrlist| forward until the first IPv4 address, if any. | 174 // Rolls |addrlist| forward until the first IPv4 address, if any. |
| 172 // WARNING: this method should only be used to implement the prefer-IPv4 hack. | 175 // WARNING: this method should only be used to implement the prefer-IPv4 hack. |
| 173 static void MakeAddressListStartWithIPv4(AddressList* addrlist); | 176 static void MakeAddressListStartWithIPv4(AddressList* addrlist); |
| 174 | 177 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 198 void CopyConnectionAttemptsFromSockets(); | 201 void CopyConnectionAttemptsFromSockets(); |
| 199 | 202 |
| 200 TransportConnectJobHelper helper_; | 203 TransportConnectJobHelper helper_; |
| 201 | 204 |
| 202 scoped_ptr<StreamSocket> transport_socket_; | 205 scoped_ptr<StreamSocket> transport_socket_; |
| 203 | 206 |
| 204 scoped_ptr<StreamSocket> fallback_transport_socket_; | 207 scoped_ptr<StreamSocket> fallback_transport_socket_; |
| 205 scoped_ptr<AddressList> fallback_addresses_; | 208 scoped_ptr<AddressList> fallback_addresses_; |
| 206 base::TimeTicks fallback_connect_start_time_; | 209 base::TimeTicks fallback_connect_start_time_; |
| 207 base::OneShotTimer fallback_timer_; | 210 base::OneShotTimer fallback_timer_; |
| 211 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_; |
| 208 | 212 |
| 209 // Track the interval between this connect and previous connect. | 213 // Track the interval between this connect and previous connect. |
| 210 ConnectInterval interval_between_connects_; | 214 ConnectInterval interval_between_connects_; |
| 211 | 215 |
| 212 int resolve_result_; | 216 int resolve_result_; |
| 213 | 217 |
| 214 // Used in the failure case to save connection attempts made on the main and | 218 // Used in the failure case to save connection attempts made on the main and |
| 215 // fallback sockets and pass them on in |GetAdditionalErrorState|. (In the | 219 // fallback sockets and pass them on in |GetAdditionalErrorState|. (In the |
| 216 // success case, connection attempts are passed through the returned socket; | 220 // success case, connection attempts are passed through the returned socket; |
| 217 // attempts are copied from the other socket, if one exists, into it before | 221 // attempts are copied from the other socket, if one exists, into it before |
| 218 // it is returned.) | 222 // it is returned.) |
| 219 ConnectionAttempts connection_attempts_; | 223 ConnectionAttempts connection_attempts_; |
| 220 ConnectionAttempts fallback_connection_attempts_; | 224 ConnectionAttempts fallback_connection_attempts_; |
| 221 | 225 |
| 222 DISALLOW_COPY_AND_ASSIGN(TransportConnectJob); | 226 DISALLOW_COPY_AND_ASSIGN(TransportConnectJob); |
| 223 }; | 227 }; |
| 224 | 228 |
| 225 class NET_EXPORT_PRIVATE TransportClientSocketPool : public ClientSocketPool { | 229 class NET_EXPORT_PRIVATE TransportClientSocketPool : public ClientSocketPool { |
| 226 public: | 230 public: |
| 227 typedef TransportSocketParams SocketParams; | 231 typedef TransportSocketParams SocketParams; |
| 228 | 232 |
| 229 TransportClientSocketPool( | 233 TransportClientSocketPool( |
| 230 int max_sockets, | 234 int max_sockets, |
| 231 int max_sockets_per_group, | 235 int max_sockets_per_group, |
| 232 HostResolver* host_resolver, | 236 HostResolver* host_resolver, |
| 233 ClientSocketFactory* client_socket_factory, | 237 ClientSocketFactory* client_socket_factory, |
| 234 NetLog* net_log); | 238 NetLog* net_log); |
| 235 | 239 |
| 240 void SetSocketPerformanceWatcherFactory( |
| 241 SocketPerformanceWatcherFactory* socket_performance_watcher_factory); |
| 242 |
| 236 ~TransportClientSocketPool() override; | 243 ~TransportClientSocketPool() override; |
| 237 | 244 |
| 238 // ClientSocketPool implementation. | 245 // ClientSocketPool implementation. |
| 239 int RequestSocket(const std::string& group_name, | 246 int RequestSocket(const std::string& group_name, |
| 240 const void* resolve_info, | 247 const void* resolve_info, |
| 241 RequestPriority priority, | 248 RequestPriority priority, |
| 242 RespectLimits respect_limits, | 249 RespectLimits respect_limits, |
| 243 ClientSocketHandle* handle, | 250 ClientSocketHandle* handle, |
| 244 const CompletionCallback& callback, | 251 const CompletionCallback& callback, |
| 245 const BoundNetLog& net_log) override; | 252 const BoundNetLog& net_log) override; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 275 const BoundNetLog& net_log, | 282 const BoundNetLog& net_log, |
| 276 const scoped_refptr<TransportSocketParams>* casted_params); | 283 const scoped_refptr<TransportSocketParams>* casted_params); |
| 277 | 284 |
| 278 private: | 285 private: |
| 279 typedef ClientSocketPoolBase<TransportSocketParams> PoolBase; | 286 typedef ClientSocketPoolBase<TransportSocketParams> PoolBase; |
| 280 | 287 |
| 281 class TransportConnectJobFactory | 288 class TransportConnectJobFactory |
| 282 : public PoolBase::ConnectJobFactory { | 289 : public PoolBase::ConnectJobFactory { |
| 283 public: | 290 public: |
| 284 TransportConnectJobFactory(ClientSocketFactory* client_socket_factory, | 291 TransportConnectJobFactory(ClientSocketFactory* client_socket_factory, |
| 285 HostResolver* host_resolver, | 292 HostResolver* host_resolver, |
| 286 NetLog* net_log) | 293 NetLog* net_log) |
| 287 : client_socket_factory_(client_socket_factory), | 294 : client_socket_factory_(client_socket_factory), |
| 295 socket_performance_watcher_factory_(nullptr), |
| 288 host_resolver_(host_resolver), | 296 host_resolver_(host_resolver), |
| 289 net_log_(net_log) {} | 297 net_log_(net_log) {} |
| 290 | 298 |
| 299 void SetSocketPerformanceWatcherFactory( |
| 300 SocketPerformanceWatcherFactory* socket_performance_watcher_factory) |
| 301 override; |
| 302 |
| 291 ~TransportConnectJobFactory() override {} | 303 ~TransportConnectJobFactory() override {} |
| 292 | 304 |
| 293 // ClientSocketPoolBase::ConnectJobFactory methods. | 305 // ClientSocketPoolBase::ConnectJobFactory methods. |
| 294 | 306 |
| 295 scoped_ptr<ConnectJob> NewConnectJob( | 307 scoped_ptr<ConnectJob> NewConnectJob( |
| 296 const std::string& group_name, | 308 const std::string& group_name, |
| 297 const PoolBase::Request& request, | 309 const PoolBase::Request& request, |
| 298 ConnectJob::Delegate* delegate) const override; | 310 ConnectJob::Delegate* delegate) const override; |
| 299 | 311 |
| 300 base::TimeDelta ConnectionTimeout() const override; | 312 base::TimeDelta ConnectionTimeout() const override; |
| 301 | 313 |
| 302 private: | 314 private: |
| 303 ClientSocketFactory* const client_socket_factory_; | 315 ClientSocketFactory* const client_socket_factory_; |
| 316 SocketPerformanceWatcherFactory* socket_performance_watcher_factory_; |
| 304 HostResolver* const host_resolver_; | 317 HostResolver* const host_resolver_; |
| 305 NetLog* net_log_; | 318 NetLog* net_log_; |
| 306 | 319 |
| 307 DISALLOW_COPY_AND_ASSIGN(TransportConnectJobFactory); | 320 DISALLOW_COPY_AND_ASSIGN(TransportConnectJobFactory); |
| 308 }; | 321 }; |
| 309 | 322 |
| 310 PoolBase base_; | 323 PoolBase base_; |
| 311 | 324 |
| 312 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPool); | 325 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPool); |
| 313 }; | 326 }; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 break; | 376 break; |
| 364 } | 377 } |
| 365 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 378 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 366 | 379 |
| 367 return rv; | 380 return rv; |
| 368 } | 381 } |
| 369 | 382 |
| 370 } // namespace net | 383 } // namespace net |
| 371 | 384 |
| 372 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ | 385 #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |