| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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 HostResolver::RequestInfo& resolve_info, | 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 LoadLog* load_log) | 41 LoadLog* load_log) |
| 42 : ConnectJob(group_name, timeout_duration, delegate, load_log), | 42 : ConnectJob(group_name, timeout_duration, delegate, load_log), |
| 43 resolve_info_(resolve_info), | 43 params_(params), |
| 44 client_socket_factory_(client_socket_factory), | 44 client_socket_factory_(client_socket_factory), |
| 45 ALLOW_THIS_IN_INITIALIZER_LIST( | 45 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 46 callback_(this, | 46 callback_(this, |
| 47 &TCPConnectJob::OnIOComplete)), | 47 &TCPConnectJob::OnIOComplete)), |
| 48 resolver_(host_resolver) {} | 48 resolver_(host_resolver) {} |
| 49 | 49 |
| 50 TCPConnectJob::~TCPConnectJob() { | 50 TCPConnectJob::~TCPConnectJob() { |
| 51 // We don't worry about cancelling the host resolution and TCP connect, since | 51 // We don't worry about cancelling the host resolution and TCP connect, since |
| 52 // ~SingleRequestHostResolver and ~ClientSocket will take care of it. | 52 // ~SingleRequestHostResolver and ~ClientSocket will take care of it. |
| 53 } | 53 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 rv = ERR_FAILED; | 105 rv = ERR_FAILED; |
| 106 break; | 106 break; |
| 107 } | 107 } |
| 108 } while (rv != ERR_IO_PENDING && next_state_ != kStateNone); | 108 } while (rv != ERR_IO_PENDING && next_state_ != kStateNone); |
| 109 | 109 |
| 110 return rv; | 110 return rv; |
| 111 } | 111 } |
| 112 | 112 |
| 113 int TCPConnectJob::DoResolveHost() { | 113 int TCPConnectJob::DoResolveHost() { |
| 114 next_state_ = kStateResolveHostComplete; | 114 next_state_ = kStateResolveHostComplete; |
| 115 return resolver_.Resolve(resolve_info_, &addresses_, &callback_, load_log()); | 115 return resolver_.Resolve(params_.destination(), &addresses_, &callback_, |
| 116 load_log()); |
| 116 } | 117 } |
| 117 | 118 |
| 118 int TCPConnectJob::DoResolveHostComplete(int result) { | 119 int TCPConnectJob::DoResolveHostComplete(int result) { |
| 119 if (result == OK) | 120 if (result == OK) |
| 120 next_state_ = kStateTCPConnect; | 121 next_state_ = kStateTCPConnect; |
| 121 return result; | 122 return result; |
| 122 } | 123 } |
| 123 | 124 |
| 124 int TCPConnectJob::DoTCPConnect() { | 125 int TCPConnectJob::DoTCPConnect() { |
| 125 next_state_ = kStateTCPConnectComplete; | 126 next_state_ = kStateTCPConnectComplete; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 : base_(max_sockets, max_sockets_per_group, | 176 : base_(max_sockets, max_sockets_per_group, |
| 176 base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), | 177 base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), |
| 177 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), | 178 base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), |
| 178 new TCPConnectJobFactory(client_socket_factory, host_resolver), | 179 new TCPConnectJobFactory(client_socket_factory, host_resolver), |
| 179 network_change_notifier) {} | 180 network_change_notifier) {} |
| 180 | 181 |
| 181 TCPClientSocketPool::~TCPClientSocketPool() {} | 182 TCPClientSocketPool::~TCPClientSocketPool() {} |
| 182 | 183 |
| 183 int TCPClientSocketPool::RequestSocket( | 184 int TCPClientSocketPool::RequestSocket( |
| 184 const std::string& group_name, | 185 const std::string& group_name, |
| 185 const void* resolve_info, | 186 const void* params, |
| 186 RequestPriority priority, | 187 RequestPriority priority, |
| 187 ClientSocketHandle* handle, | 188 ClientSocketHandle* handle, |
| 188 CompletionCallback* callback, | 189 CompletionCallback* callback, |
| 189 LoadLog* load_log) { | 190 LoadLog* load_log) { |
| 190 const HostResolver::RequestInfo* casted_resolve_info = | 191 const TCPSocketParams* casted_params = |
| 191 static_cast<const HostResolver::RequestInfo*>(resolve_info); | 192 static_cast<const TCPSocketParams*>(params); |
| 192 | 193 |
| 193 if (LoadLog::IsUnbounded(load_log)) { | 194 if (LoadLog::IsUnbounded(load_log)) { |
| 194 LoadLog::AddString( | 195 LoadLog::AddString( |
| 195 load_log, | 196 load_log, |
| 196 StringPrintf("Requested TCP socket to: %s [port %d]", | 197 StringPrintf("Requested TCP socket to: %s [port %d]", |
| 197 casted_resolve_info->hostname().c_str(), | 198 casted_params->destination().hostname().c_str(), |
| 198 casted_resolve_info->port())); | 199 casted_params->destination().port())); |
| 199 } | 200 } |
| 200 | 201 |
| 201 return base_.RequestSocket( | 202 return base_.RequestSocket(group_name, *casted_params, priority, handle, |
| 202 group_name, *casted_resolve_info, priority, handle, callback, load_log); | 203 callback, load_log); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void TCPClientSocketPool::CancelRequest( | 206 void TCPClientSocketPool::CancelRequest( |
| 206 const std::string& group_name, | 207 const std::string& group_name, |
| 207 const ClientSocketHandle* handle) { | 208 const ClientSocketHandle* handle) { |
| 208 base_.CancelRequest(group_name, handle); | 209 base_.CancelRequest(group_name, handle); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void TCPClientSocketPool::ReleaseSocket( | 212 void TCPClientSocketPool::ReleaseSocket( |
| 212 const std::string& group_name, | 213 const std::string& group_name, |
| 213 ClientSocket* socket) { | 214 ClientSocket* socket) { |
| 214 base_.ReleaseSocket(group_name, socket); | 215 base_.ReleaseSocket(group_name, socket); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void TCPClientSocketPool::CloseIdleSockets() { | 218 void TCPClientSocketPool::CloseIdleSockets() { |
| 218 base_.CloseIdleSockets(); | 219 base_.CloseIdleSockets(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 int TCPClientSocketPool::IdleSocketCountInGroup( | 222 int TCPClientSocketPool::IdleSocketCountInGroup( |
| 222 const std::string& group_name) const { | 223 const std::string& group_name) const { |
| 223 return base_.IdleSocketCountInGroup(group_name); | 224 return base_.IdleSocketCountInGroup(group_name); |
| 224 } | 225 } |
| 225 | 226 |
| 226 LoadState TCPClientSocketPool::GetLoadState( | 227 LoadState TCPClientSocketPool::GetLoadState( |
| 227 const std::string& group_name, const ClientSocketHandle* handle) const { | 228 const std::string& group_name, const ClientSocketHandle* handle) const { |
| 228 return base_.GetLoadState(group_name, handle); | 229 return base_.GetLoadState(group_name, handle); |
| 229 } | 230 } |
| 230 | 231 |
| 231 } // namespace net | 232 } // namespace net |
| OLD | NEW |