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

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

Issue 160499: Add timeouts for ConnectJobs. Limit ConnectJobs per group to number of Requests per group + 1. (Closed)
Patch Set: Revert the revert. Fix tests. Created 11 years, 4 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
« no previous file with comments | « net/socket/tcp_client_socket_pool.h ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/time.h" 10 #include "base/time.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/socket/client_socket_factory.h" 12 #include "net/socket/client_socket_factory.h"
13 #include "net/socket/client_socket_handle.h" 13 #include "net/socket/client_socket_handle.h"
14 #include "net/socket/client_socket_pool_base.h" 14 #include "net/socket/client_socket_pool_base.h"
15 #include "net/socket/tcp_client_socket.h" 15 #include "net/socket/tcp_client_socket.h"
16 16
17 using base::TimeDelta; 17 using base::TimeDelta;
18 18
19 namespace net { 19 namespace net {
20 20
21 // TCPConnectJobs will time out after this many seconds. Note this is the total
22 // time, including both host resolution and TCP connect() times.
23 static const int kTCPConnectJobTimeoutInSeconds = 60;
24
21 TCPConnectJob::TCPConnectJob( 25 TCPConnectJob::TCPConnectJob(
22 const std::string& group_name, 26 const std::string& group_name,
23 const HostResolver::RequestInfo& resolve_info, 27 const HostResolver::RequestInfo& resolve_info,
24 const ClientSocketHandle* handle, 28 const ClientSocketHandle* handle,
29 base::TimeDelta timeout_duration,
25 ClientSocketFactory* client_socket_factory, 30 ClientSocketFactory* client_socket_factory,
26 HostResolver* host_resolver, 31 HostResolver* host_resolver,
27 Delegate* delegate) 32 Delegate* delegate)
28 : ConnectJob(group_name, handle, delegate), 33 : ConnectJob(group_name, handle, timeout_duration, delegate),
29 resolve_info_(resolve_info), 34 resolve_info_(resolve_info),
30 client_socket_factory_(client_socket_factory), 35 client_socket_factory_(client_socket_factory),
31 ALLOW_THIS_IN_INITIALIZER_LIST( 36 ALLOW_THIS_IN_INITIALIZER_LIST(
32 callback_(this, 37 callback_(this,
33 &TCPConnectJob::OnIOComplete)), 38 &TCPConnectJob::OnIOComplete)),
34 resolver_(host_resolver) {} 39 resolver_(host_resolver) {}
35 40
36 TCPConnectJob::~TCPConnectJob() { 41 TCPConnectJob::~TCPConnectJob() {
37 // We don't worry about cancelling the host resolution and TCP connect, since 42 // We don't worry about cancelling the host resolution and TCP connect, since
38 // ~SingleRequestHostResolver and ~ClientSocket will take care of it. 43 // ~SingleRequestHostResolver and ~ClientSocket will take care of it.
39 } 44 }
40 45
41 int TCPConnectJob::Connect() { 46 int TCPConnectJob::ConnectInternal() {
42 next_state_ = kStateResolveHost; 47 next_state_ = kStateResolveHost;
43 return DoLoop(OK); 48 return DoLoop(OK);
44 } 49 }
45 50
46 void TCPConnectJob::OnIOComplete(int result) { 51 void TCPConnectJob::OnIOComplete(int result) {
47 int rv = DoLoop(result); 52 int rv = DoLoop(result);
48 if (rv != ERR_IO_PENDING) 53 if (rv != ERR_IO_PENDING)
49 delegate()->OnConnectJobComplete(rv, this); // Deletes |this| 54 delegate()->OnConnectJobComplete(rv, this); // Deletes |this|
50 } 55 }
51 56
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 126
122 return result; 127 return result;
123 } 128 }
124 129
125 ConnectJob* TCPClientSocketPool::TCPConnectJobFactory::NewConnectJob( 130 ConnectJob* TCPClientSocketPool::TCPConnectJobFactory::NewConnectJob(
126 const std::string& group_name, 131 const std::string& group_name,
127 const ClientSocketPoolBase::Request& request, 132 const ClientSocketPoolBase::Request& request,
128 ConnectJob::Delegate* delegate) const { 133 ConnectJob::Delegate* delegate) const {
129 return new TCPConnectJob( 134 return new TCPConnectJob(
130 group_name, request.resolve_info, request.handle, 135 group_name, request.resolve_info, request.handle,
136 base::TimeDelta::FromSeconds(kTCPConnectJobTimeoutInSeconds),
131 client_socket_factory_, host_resolver_, delegate); 137 client_socket_factory_, host_resolver_, delegate);
132 } 138 }
133 139
134 TCPClientSocketPool::TCPClientSocketPool( 140 TCPClientSocketPool::TCPClientSocketPool(
135 int max_sockets, 141 int max_sockets,
136 int max_sockets_per_group, 142 int max_sockets_per_group,
137 HostResolver* host_resolver, 143 HostResolver* host_resolver,
138 ClientSocketFactory* client_socket_factory) 144 ClientSocketFactory* client_socket_factory)
139 : base_(new ClientSocketPoolBase( 145 : base_(new ClientSocketPoolBase(
140 max_sockets, max_sockets_per_group, 146 max_sockets, max_sockets_per_group,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 const std::string& group_name) const { 178 const std::string& group_name) const {
173 return base_->IdleSocketCountInGroup(group_name); 179 return base_->IdleSocketCountInGroup(group_name);
174 } 180 }
175 181
176 LoadState TCPClientSocketPool::GetLoadState( 182 LoadState TCPClientSocketPool::GetLoadState(
177 const std::string& group_name, const ClientSocketHandle* handle) const { 183 const std::string& group_name, const ClientSocketHandle* handle) const {
178 return base_->GetLoadState(group_name, handle); 184 return base_->GetLoadState(group_name, handle);
179 } 185 }
180 186
181 } // namespace net 187 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698