| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tcp_client_socket_pool.h" | 5 #include "net/socket/tcp_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // TCPConnectJobs will time out after this many seconds. Note this is the total | 23 // TCPConnectJobs will time out after this many seconds. Note this is the total |
| 24 // time, including both host resolution and TCP connect() times. | 24 // time, including both host resolution and TCP connect() times. |
| 25 // | 25 // |
| 26 // TODO(eroman): The use of this constant needs to be re-evaluated. The time | 26 // TODO(eroman): The use of this constant needs to be re-evaluated. The time |
| 27 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since | 27 // needed for TCPClientSocketXXX::Connect() can be arbitrarily long, since |
| 28 // the address list may contain many alternatives, and most of those may | 28 // the address list may contain many alternatives, and most of those may |
| 29 // timeout. Even worse, the per-connect timeout threshold varies greatly | 29 // timeout. Even worse, the per-connect timeout threshold varies greatly |
| 30 // between systems (anywhere from 20 seconds to 190 seconds). | 30 // between systems (anywhere from 20 seconds to 190 seconds). |
| 31 // See comment #12 at http://crbug.com/23364 for specifics. | 31 // See comment #12 at http://crbug.com/23364 for specifics. |
| 32 static const int kTCPConnectJobTimeoutInSeconds = 240; // 4 minutes. | 32 static const int kTCPConnectJobTimeoutInSeconds = 240; // 4 minutes. |
| 33 | 33 |
| 34 TCPConnectJob::TCPConnectJob( | 34 TCPConnectJob::TCPConnectJob( |
| 35 const std::string& group_name, | 35 const std::string& group_name, |
| 36 const TCPSocketParams& params, | 36 const TCPSocketParams& params, |
| 37 base::TimeDelta timeout_duration, | 37 base::TimeDelta timeout_duration, |
| 38 ClientSocketFactory* client_socket_factory, | 38 ClientSocketFactory* client_socket_factory, |
| 39 HostResolver* host_resolver, | 39 HostResolver* host_resolver, |
| 40 Delegate* delegate, | 40 Delegate* delegate, |
| 41 const BoundNetLog& net_log) | 41 NetLog* net_log) |
| 42 : ConnectJob(group_name, timeout_duration, delegate, net_log), | 42 : ConnectJob(group_name, timeout_duration, delegate, |
| 43 BoundNetLog::Make(net_log, NetLog::SOURCE_CONNECT_JOB)), |
| 43 params_(params), | 44 params_(params), |
| 44 client_socket_factory_(client_socket_factory), | 45 client_socket_factory_(client_socket_factory), |
| 45 ALLOW_THIS_IN_INITIALIZER_LIST( | 46 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 46 callback_(this, | 47 callback_(this, |
| 47 &TCPConnectJob::OnIOComplete)), | 48 &TCPConnectJob::OnIOComplete)), |
| 48 resolver_(host_resolver) {} | 49 resolver_(host_resolver) {} |
| 49 | 50 |
| 50 TCPConnectJob::~TCPConnectJob() { | 51 TCPConnectJob::~TCPConnectJob() { |
| 51 // We don't worry about cancelling the host resolution and TCP connect, since | 52 // We don't worry about cancelling the host resolution and TCP connect, since |
| 52 // ~SingleRequestHostResolver and ~ClientSocket will take care of it. | 53 // ~SingleRequestHostResolver and ~ClientSocket will take care of it. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // Delete the socket on error. | 154 // Delete the socket on error. |
| 154 set_socket(NULL); | 155 set_socket(NULL); |
| 155 } | 156 } |
| 156 | 157 |
| 157 return result; | 158 return result; |
| 158 } | 159 } |
| 159 | 160 |
| 160 ConnectJob* TCPClientSocketPool::TCPConnectJobFactory::NewConnectJob( | 161 ConnectJob* TCPClientSocketPool::TCPConnectJobFactory::NewConnectJob( |
| 161 const std::string& group_name, | 162 const std::string& group_name, |
| 162 const PoolBase::Request& request, | 163 const PoolBase::Request& request, |
| 163 ConnectJob::Delegate* delegate, | 164 ConnectJob::Delegate* delegate) const { |
| 164 const BoundNetLog& net_log) const { | |
| 165 return new TCPConnectJob(group_name, request.params(), ConnectionTimeout(), | 165 return new TCPConnectJob(group_name, request.params(), ConnectionTimeout(), |
| 166 client_socket_factory_, host_resolver_, delegate, | 166 client_socket_factory_, host_resolver_, delegate, |
| 167 net_log); | 167 net_log_); |
| 168 } | 168 } |
| 169 | 169 |
| 170 base::TimeDelta | 170 base::TimeDelta |
| 171 TCPClientSocketPool::TCPConnectJobFactory::ConnectionTimeout() const { | 171 TCPClientSocketPool::TCPConnectJobFactory::ConnectionTimeout() const { |
| 172 return base::TimeDelta::FromSeconds(kTCPConnectJobTimeoutInSeconds); | 172 return base::TimeDelta::FromSeconds(kTCPConnectJobTimeoutInSeconds); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TCPClientSocketPool::TCPClientSocketPool( | 175 TCPClientSocketPool::TCPClientSocketPool( |
| 176 int max_sockets, | 176 int max_sockets, |
| 177 int max_sockets_per_group, | 177 int max_sockets_per_group, |
| 178 const scoped_refptr<ClientSocketPoolHistograms>& histograms, | 178 const scoped_refptr<ClientSocketPoolHistograms>& histograms, |
| 179 HostResolver* host_resolver, | 179 HostResolver* host_resolver, |
| 180 ClientSocketFactory* client_socket_factory, | 180 ClientSocketFactory* client_socket_factory, |
| 181 NetworkChangeNotifier* network_change_notifier) | 181 NetworkChangeNotifier* network_change_notifier, |
| 182 NetLog* net_log) |
| 182 : base_(max_sockets, max_sockets_per_group, histograms, | 183 : base_(max_sockets, max_sockets_per_group, histograms, |
| 183 base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), | 184 base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), |
| 184 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), | 185 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), |
| 185 new TCPConnectJobFactory(client_socket_factory, host_resolver), | 186 new TCPConnectJobFactory(client_socket_factory, |
| 187 host_resolver, net_log), |
| 186 network_change_notifier) { | 188 network_change_notifier) { |
| 187 base_.enable_backup_jobs(); | 189 base_.enable_backup_jobs(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 TCPClientSocketPool::~TCPClientSocketPool() {} | 192 TCPClientSocketPool::~TCPClientSocketPool() {} |
| 191 | 193 |
| 192 int TCPClientSocketPool::RequestSocket( | 194 int TCPClientSocketPool::RequestSocket( |
| 193 const std::string& group_name, | 195 const std::string& group_name, |
| 194 const void* params, | 196 const void* params, |
| 195 RequestPriority priority, | 197 RequestPriority priority, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 const std::string& group_name) const { | 236 const std::string& group_name) const { |
| 235 return base_.IdleSocketCountInGroup(group_name); | 237 return base_.IdleSocketCountInGroup(group_name); |
| 236 } | 238 } |
| 237 | 239 |
| 238 LoadState TCPClientSocketPool::GetLoadState( | 240 LoadState TCPClientSocketPool::GetLoadState( |
| 239 const std::string& group_name, const ClientSocketHandle* handle) const { | 241 const std::string& group_name, const ClientSocketHandle* handle) const { |
| 240 return base_.GetLoadState(group_name, handle); | 242 return base_.GetLoadState(group_name, handle); |
| 241 } | 243 } |
| 242 | 244 |
| 243 } // namespace net | 245 } // namespace net |
| OLD | NEW |