[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/socket/client_socket_pool_base.h" |
| 6 | |
| 7 | #include "base/compiler_specific.h" |
| 8 | #include "base/message_loop.h" |
| 9 | #include "base/stl_util-inl.h" |
| 10 | #include "base/time.h" |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 11 | #include "net/base/load_log.h" |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 12 | #include "net/base/net_errors.h" |
| 13 | #include "net/socket/client_socket_handle.h" |
| 14 | |
| 15 | using base::TimeDelta; |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | // The timeout value, in seconds, used to clean up idle sockets that can't be |
| 20 | // reused. |
| 21 | // |
| 22 | // Note: It's important to close idle sockets that have received data as soon |
| 23 | // as possible because the received data may cause BSOD on Windows XP under |
| 24 | // some conditions. See http://crbug.com/4606. |
| 25 | const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT. |
| 26 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 27 | } // namespace |
| 28 | |
| 29 | namespace net { |
| 30 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 31 | ConnectJob::ConnectJob(const std::string& group_name, |
| 32 | const ClientSocketHandle* key_handle, |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 33 | base::TimeDelta timeout_duration, |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 34 | Delegate* delegate, |
| 35 | LoadLog* load_log) |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 36 | : group_name_(group_name), |
| 37 | key_handle_(key_handle), |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 38 | timeout_duration_(timeout_duration), |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 39 | delegate_(delegate), |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 40 | load_log_(load_log) { |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 41 | DCHECK(!group_name.empty()); |
| 42 | DCHECK(key_handle); |
| 43 | DCHECK(delegate); |
| 44 | } |
| 45 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 46 | ConnectJob::~ConnectJob() { |
| 47 | if (delegate_) { |
| 48 | // If the delegate was not NULLed, then NotifyDelegateOfCompletion has |
| 49 | // not been called yet (hence we are cancelling). |
| 50 | LoadLog::AddEvent(load_log_, LoadLog::TYPE_CANCELLED); |
| 51 | LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
| 52 | } |
| 53 | } |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 54 | |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 55 | int ConnectJob::Connect() { |
| 56 | if (timeout_duration_ != base::TimeDelta()) |
| 57 | timer_.Start(timeout_duration_, this, &ConnectJob::OnTimeout); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 58 | |
| 59 | LoadLog::BeginEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
| 60 | |
| 61 | int rv = ConnectInternal(); |
| 62 | |
| 63 | if (rv != ERR_IO_PENDING) { |
| 64 | delegate_ = NULL; |
| 65 | LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
| 66 | } |
| 67 | |
| 68 | return rv; |
| 69 | } |
| 70 | |
| 71 | void ConnectJob::NotifyDelegateOfCompletion(int rv) { |
| 72 | // The delegate will delete |this|. |
| 73 | Delegate *delegate = delegate_; |
| 74 | delegate_ = NULL; |
| 75 | |
| 76 | LoadLog::EndEvent(load_log_, LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB); |
| 77 | |
| 78 | delegate->OnConnectJobComplete(rv, this); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void ConnectJob::OnTimeout() { |
[email protected] | 6e713f0 | 2009-08-06 02:56:40 | [diff] [blame] | 82 | // Make sure the socket is NULL before calling into |delegate|. |
| 83 | set_socket(NULL); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 84 | |
| 85 | LoadLog::AddEvent(load_log_, |
| 86 | LoadLog::TYPE_SOCKET_POOL_CONNECT_JOB_TIMED_OUT); |
| 87 | |
| 88 | NotifyDelegateOfCompletion(ERR_TIMED_OUT); |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 91 | namespace internal { |
| 92 | |
| 93 | bool ClientSocketPoolBaseHelper::g_late_binding = false; |
| 94 | |
| 95 | ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 96 | int max_sockets, |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 97 | int max_sockets_per_group, |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 98 | base::TimeDelta unused_idle_socket_timeout, |
| 99 | base::TimeDelta used_idle_socket_timeout, |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 100 | ConnectJobFactory* connect_job_factory) |
| 101 | : idle_socket_count_(0), |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 102 | connecting_socket_count_(0), |
| 103 | handed_out_socket_count_(0), |
| 104 | max_sockets_(max_sockets), |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 105 | max_sockets_per_group_(max_sockets_per_group), |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 106 | unused_idle_socket_timeout_(unused_idle_socket_timeout), |
| 107 | used_idle_socket_timeout_(used_idle_socket_timeout), |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 108 | may_have_stalled_group_(false), |
| 109 | connect_job_factory_(connect_job_factory) { |
| 110 | DCHECK_LE(0, max_sockets_per_group); |
| 111 | DCHECK_LE(max_sockets_per_group, max_sockets); |
| 112 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 113 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 114 | ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 115 | if (g_late_binding) |
| 116 | CancelAllConnectJobs(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 117 | // Clean up any idle sockets. Assert that we have no remaining active |
| 118 | // sockets or pending requests. They should have all been cleaned up prior |
| 119 | // to the manager being destroyed. |
| 120 | CloseIdleSockets(); |
| 121 | DCHECK(group_map_.empty()); |
| 122 | DCHECK(connect_job_map_.empty()); |
| 123 | } |
| 124 | |
| 125 | // InsertRequestIntoQueue inserts the request into the queue based on |
| 126 | // priority. Highest priorities are closest to the front. Older requests are |
| 127 | // prioritized over requests of equal priority. |
| 128 | // |
| 129 | // static |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 130 | void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( |
| 131 | const Request* r, RequestQueue* pending_requests) { |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 132 | LoadLog::BeginEvent(r->load_log(), |
| 133 | LoadLog::TYPE_SOCKET_POOL_WAITING_IN_QUEUE); |
| 134 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 135 | RequestQueue::iterator it = pending_requests->begin(); |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 136 | while (it != pending_requests->end() && r->priority() <= (*it)->priority()) |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 137 | ++it; |
| 138 | pending_requests->insert(it, r); |
| 139 | } |
| 140 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 141 | // static |
| 142 | const ClientSocketPoolBaseHelper::Request* |
| 143 | ClientSocketPoolBaseHelper::RemoveRequestFromQueue( |
| 144 | RequestQueue::iterator it, RequestQueue* pending_requests) { |
| 145 | const Request* req = *it; |
| 146 | |
| 147 | LoadLog::EndEvent(req->load_log(), |
| 148 | LoadLog::TYPE_SOCKET_POOL_WAITING_IN_QUEUE); |
| 149 | |
| 150 | pending_requests->erase(it); |
| 151 | return req; |
| 152 | } |
| 153 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 154 | int ClientSocketPoolBaseHelper::RequestSocket( |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 155 | const std::string& group_name, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 156 | const Request* request) { |
| 157 | DCHECK_GE(request->priority(), 0); |
| 158 | CompletionCallback* const callback = request->callback(); |
| 159 | CHECK(callback); |
| 160 | ClientSocketHandle* const handle = request->handle(); |
| 161 | CHECK(handle); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 162 | Group& group = group_map_[group_name]; |
| 163 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 164 | // Can we make another active socket now? |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 165 | if (ReachedMaxSocketsLimit() || |
| 166 | !group.HasAvailableSocketSlot(max_sockets_per_group_)) { |
| 167 | if (ReachedMaxSocketsLimit()) { |
| 168 | // We could check if we really have a stalled group here, but it requires |
| 169 | // a scan of all groups, so just flip a flag here, and do the check later. |
| 170 | may_have_stalled_group_ = true; |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 171 | |
| 172 | LoadLog::AddEvent(request->load_log(), |
| 173 | LoadLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS); |
| 174 | } else { |
| 175 | LoadLog::AddEvent(request->load_log(), |
| 176 | LoadLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS_PER_GROUP); |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 177 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 178 | InsertRequestIntoQueue(request, &group.pending_requests); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 179 | return ERR_IO_PENDING; |
| 180 | } |
| 181 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 182 | while (!group.idle_sockets.empty()) { |
| 183 | IdleSocket idle_socket = group.idle_sockets.back(); |
| 184 | group.idle_sockets.pop_back(); |
| 185 | DecrementIdleCount(); |
| 186 | if (idle_socket.socket->IsConnectedAndIdle()) { |
| 187 | // We found one we can reuse! |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 188 | base::TimeDelta idle_time = |
| 189 | base::TimeTicks::Now() - idle_socket.start_time; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 190 | HandOutSocket( |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 191 | idle_socket.socket, idle_socket.used, handle, idle_time, &group); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 192 | return OK; |
| 193 | } |
| 194 | delete idle_socket.socket; |
| 195 | } |
| 196 | |
| 197 | // We couldn't find a socket to reuse, so allocate and connect a new one. |
| 198 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 199 | // If we aren't using late binding, the job lines up with a request so |
| 200 | // just write directly into the request's LoadLog. |
| 201 | scoped_refptr<LoadLog> job_load_log = g_late_binding ? |
| 202 | new LoadLog : request->load_log(); |
| 203 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 204 | scoped_ptr<ConnectJob> connect_job( |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 205 | connect_job_factory_->NewConnectJob(group_name, *request, this, |
| 206 | job_load_log)); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 207 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 208 | int rv = connect_job->Connect(); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 209 | |
| 210 | if (g_late_binding && rv != ERR_IO_PENDING && request->load_log()) |
| 211 | request->load_log()->Append(job_load_log); |
| 212 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 213 | if (rv == OK) { |
| 214 | HandOutSocket(connect_job->ReleaseSocket(), false /* not reused */, |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 215 | handle, base::TimeDelta(), &group); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 216 | } else if (rv == ERR_IO_PENDING) { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 217 | connecting_socket_count_++; |
| 218 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 219 | ConnectJob* job = connect_job.release(); |
| 220 | if (g_late_binding) { |
| 221 | CHECK(!ContainsKey(connect_job_map_, handle)); |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 222 | InsertRequestIntoQueue(request, &group.pending_requests); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 223 | } else { |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 224 | group.connecting_requests[handle] = request; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 225 | CHECK(!ContainsKey(connect_job_map_, handle)); |
| 226 | connect_job_map_[handle] = job; |
| 227 | } |
| 228 | group.jobs.insert(job); |
[email protected] | 2b7523d | 2009-07-29 20:29:23 | [diff] [blame] | 229 | } else if (group.IsEmpty()) { |
| 230 | group_map_.erase(group_name); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 231 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 232 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 233 | return rv; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 236 | void ClientSocketPoolBaseHelper::CancelRequest( |
| 237 | const std::string& group_name, const ClientSocketHandle* handle) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 238 | CHECK(ContainsKey(group_map_, group_name)); |
| 239 | |
| 240 | Group& group = group_map_[group_name]; |
| 241 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 242 | // Search pending_requests for matching handle. |
| 243 | RequestQueue::iterator it = group.pending_requests.begin(); |
| 244 | for (; it != group.pending_requests.end(); ++it) { |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 245 | if ((*it)->handle() == handle) { |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 246 | const Request* req = RemoveRequestFromQueue(it, &group.pending_requests); |
| 247 | LoadLog::AddEvent(req->load_log(), LoadLog::TYPE_CANCELLED); |
| 248 | LoadLog::EndEvent(req->load_log(), LoadLog::TYPE_SOCKET_POOL); |
| 249 | delete req; |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 250 | if (g_late_binding && |
| 251 | group.jobs.size() > group.pending_requests.size() + 1) { |
| 252 | // TODO(willchan): Cancel the job in the earliest LoadState. |
| 253 | RemoveConnectJob(handle, *group.jobs.begin(), &group); |
| 254 | OnAvailableSocketSlot(group_name, &group); |
| 255 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 256 | return; |
| 257 | } |
| 258 | } |
| 259 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 260 | if (!g_late_binding) { |
| 261 | // It's invalid to cancel a non-existent request. |
| 262 | CHECK(ContainsKey(group.connecting_requests, handle)); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 263 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 264 | RequestMap::iterator map_it = group.connecting_requests.find(handle); |
| 265 | if (map_it != group.connecting_requests.end()) { |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 266 | scoped_refptr<LoadLog> log(map_it->second->load_log()); |
| 267 | LoadLog::AddEvent(log, LoadLog::TYPE_CANCELLED); |
| 268 | LoadLog::EndEvent(log, LoadLog::TYPE_SOCKET_POOL); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 269 | RemoveConnectJob(handle, NULL, &group); |
| 270 | OnAvailableSocketSlot(group_name, &group); |
| 271 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 275 | void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, |
| 276 | ClientSocket* socket) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 277 | // Run this asynchronously to allow the caller to finish before we let |
| 278 | // another to begin doing work. This also avoids nasty recursion issues. |
| 279 | // NOTE: We cannot refer to the handle argument after this method returns. |
| 280 | MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 281 | this, &ClientSocketPoolBaseHelper::DoReleaseSocket, group_name, socket)); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 284 | void ClientSocketPoolBaseHelper::CloseIdleSockets() { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 285 | CleanupIdleSockets(true); |
| 286 | } |
| 287 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 288 | int ClientSocketPoolBaseHelper::IdleSocketCountInGroup( |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 289 | const std::string& group_name) const { |
| 290 | GroupMap::const_iterator i = group_map_.find(group_name); |
| 291 | CHECK(i != group_map_.end()); |
| 292 | |
| 293 | return i->second.idle_sockets.size(); |
| 294 | } |
| 295 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 296 | LoadState ClientSocketPoolBaseHelper::GetLoadState( |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 297 | const std::string& group_name, |
| 298 | const ClientSocketHandle* handle) const { |
| 299 | if (!ContainsKey(group_map_, group_name)) { |
| 300 | NOTREACHED() << "ClientSocketPool does not contain group: " << group_name |
| 301 | << " for handle: " << handle; |
| 302 | return LOAD_STATE_IDLE; |
| 303 | } |
| 304 | |
| 305 | // Can't use operator[] since it is non-const. |
| 306 | const Group& group = group_map_.find(group_name)->second; |
| 307 | |
| 308 | // Search connecting_requests for matching handle. |
| 309 | RequestMap::const_iterator map_it = group.connecting_requests.find(handle); |
| 310 | if (map_it != group.connecting_requests.end()) { |
[email protected] | ab83889 | 2009-06-30 18:49:05 | [diff] [blame] | 311 | ConnectJobMap::const_iterator job_it = connect_job_map_.find(handle); |
| 312 | if (job_it == connect_job_map_.end()) { |
| 313 | NOTREACHED(); |
| 314 | return LOAD_STATE_IDLE; |
| 315 | } |
[email protected] | 4645135 | 2009-09-01 14:54:21 | [diff] [blame^] | 316 | return job_it->second->GetLoadState(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // Search pending_requests for matching handle. |
| 320 | RequestQueue::const_iterator it = group.pending_requests.begin(); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 321 | for (size_t i = 0; it != group.pending_requests.end(); ++it, ++i) { |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 322 | if ((*it)->handle() == handle) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 323 | if (g_late_binding && i < group.jobs.size()) { |
| 324 | LoadState max_state = LOAD_STATE_IDLE; |
| 325 | for (ConnectJobSet::const_iterator job_it = group.jobs.begin(); |
| 326 | job_it != group.jobs.end(); ++job_it) { |
[email protected] | 4645135 | 2009-09-01 14:54:21 | [diff] [blame^] | 327 | max_state = std::max(max_state, (*job_it)->GetLoadState()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 328 | } |
| 329 | return max_state; |
| 330 | } else { |
| 331 | // TODO(wtc): Add a state for being on the wait list. |
| 332 | // See http://www.crbug.com/5077. |
| 333 | return LOAD_STATE_IDLE; |
| 334 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
| 338 | NOTREACHED(); |
| 339 | return LOAD_STATE_IDLE; |
| 340 | } |
| 341 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 342 | bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup( |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 343 | base::TimeTicks now, |
| 344 | base::TimeDelta timeout) const { |
| 345 | bool timed_out = (now - start_time) >= timeout; |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 346 | return timed_out || |
| 347 | !(used ? socket->IsConnectedAndIdle() : socket->IsConnected()); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 348 | } |
| 349 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 350 | void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 351 | if (idle_socket_count_ == 0) |
| 352 | return; |
| 353 | |
| 354 | // Current time value. Retrieving it once at the function start rather than |
| 355 | // inside the inner loop, since it shouldn't change by any meaningful amount. |
| 356 | base::TimeTicks now = base::TimeTicks::Now(); |
| 357 | |
| 358 | GroupMap::iterator i = group_map_.begin(); |
| 359 | while (i != group_map_.end()) { |
| 360 | Group& group = i->second; |
| 361 | |
| 362 | std::deque<IdleSocket>::iterator j = group.idle_sockets.begin(); |
| 363 | while (j != group.idle_sockets.end()) { |
[email protected] | 9bf28db | 2009-08-29 01:35:16 | [diff] [blame] | 364 | base::TimeDelta timeout = |
| 365 | j->used ? used_idle_socket_timeout_ : unused_idle_socket_timeout_; |
| 366 | if (force || j->ShouldCleanup(now, timeout)) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 367 | delete j->socket; |
| 368 | j = group.idle_sockets.erase(j); |
| 369 | DecrementIdleCount(); |
| 370 | } else { |
| 371 | ++j; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // Delete group if no longer needed. |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 376 | if (group.IsEmpty()) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 377 | group_map_.erase(i++); |
| 378 | } else { |
| 379 | ++i; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 384 | void ClientSocketPoolBaseHelper::IncrementIdleCount() { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 385 | if (++idle_socket_count_ == 1) |
| 386 | timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this, |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 387 | &ClientSocketPoolBaseHelper::OnCleanupTimerFired); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 388 | } |
| 389 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 390 | void ClientSocketPoolBaseHelper::DecrementIdleCount() { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 391 | if (--idle_socket_count_ == 0) |
| 392 | timer_.Stop(); |
| 393 | } |
| 394 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 395 | void ClientSocketPoolBaseHelper::DoReleaseSocket(const std::string& group_name, |
| 396 | ClientSocket* socket) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 397 | GroupMap::iterator i = group_map_.find(group_name); |
| 398 | CHECK(i != group_map_.end()); |
| 399 | |
| 400 | Group& group = i->second; |
| 401 | |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 402 | CHECK(handed_out_socket_count_ > 0); |
| 403 | handed_out_socket_count_--; |
| 404 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 405 | CHECK(group.active_socket_count > 0); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 406 | group.active_socket_count--; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 407 | |
| 408 | const bool can_reuse = socket->IsConnectedAndIdle(); |
| 409 | if (can_reuse) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 410 | AddIdleSocket(socket, true /* used socket */, &group); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 411 | } else { |
| 412 | delete socket; |
| 413 | } |
| 414 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 415 | OnAvailableSocketSlot(group_name, &group); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 418 | // Search for the highest priority pending request, amongst the groups that |
| 419 | // are not at the |max_sockets_per_group_| limit. Note: for requests with |
| 420 | // the same priority, the winner is based on group hash ordering (and not |
| 421 | // insertion order). |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 422 | int ClientSocketPoolBaseHelper::FindTopStalledGroup(Group** group, |
| 423 | std::string* group_name) { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 424 | Group* top_group = NULL; |
| 425 | const std::string* top_group_name = NULL; |
| 426 | int stalled_group_count = 0; |
| 427 | for (GroupMap::iterator i = group_map_.begin(); |
| 428 | i != group_map_.end(); ++i) { |
| 429 | Group& group = i->second; |
| 430 | const RequestQueue& queue = group.pending_requests; |
| 431 | if (queue.empty()) |
| 432 | continue; |
| 433 | bool has_slot = group.HasAvailableSocketSlot(max_sockets_per_group_); |
| 434 | if (has_slot) |
| 435 | stalled_group_count++; |
| 436 | bool has_higher_priority = !top_group || |
| 437 | group.TopPendingPriority() > top_group->TopPendingPriority(); |
| 438 | if (has_slot && has_higher_priority) { |
| 439 | top_group = &group; |
| 440 | top_group_name = &i->first; |
| 441 | } |
| 442 | } |
| 443 | if (top_group) { |
| 444 | *group = top_group; |
| 445 | *group_name = *top_group_name; |
| 446 | } |
| 447 | return stalled_group_count; |
| 448 | } |
| 449 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 450 | void ClientSocketPoolBaseHelper::OnConnectJobComplete( |
| 451 | int result, ConnectJob* job) { |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 452 | DCHECK_NE(ERR_IO_PENDING, result); |
| 453 | const std::string group_name = job->group_name(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 454 | GroupMap::iterator group_it = group_map_.find(group_name); |
| 455 | CHECK(group_it != group_map_.end()); |
| 456 | Group& group = group_it->second; |
| 457 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 458 | const ClientSocketHandle* const key_handle = job->key_handle(); |
| 459 | scoped_ptr<ClientSocket> socket(job->ReleaseSocket()); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 460 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 461 | if (g_late_binding) { |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 462 | scoped_refptr<LoadLog> job_load_log(job->load_log()); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 463 | RemoveConnectJob(key_handle, job, &group); |
| 464 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 465 | scoped_ptr<const Request> r; |
| 466 | if (!group.pending_requests.empty()) { |
| 467 | r.reset(RemoveRequestFromQueue( |
| 468 | group.pending_requests.begin(), &group.pending_requests)); |
| 469 | |
| 470 | if (r->load_log()) |
| 471 | r->load_log()->Append(job_load_log); |
| 472 | |
| 473 | LoadLog::EndEvent(r->load_log(), LoadLog::TYPE_SOCKET_POOL); |
| 474 | } |
| 475 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 476 | if (result == OK) { |
| 477 | DCHECK(socket.get()); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 478 | if (r.get()) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 479 | HandOutSocket( |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 480 | socket.release(), false /* unused socket */, r->handle(), |
| 481 | base::TimeDelta(), &group); |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 482 | r->callback()->Run(result); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 483 | } else { |
| 484 | AddIdleSocket(socket.release(), false /* unused socket */, &group); |
| 485 | OnAvailableSocketSlot(group_name, &group); |
| 486 | } |
| 487 | } else { |
| 488 | DCHECK(!socket.get()); |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 489 | if (r.get()) |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 490 | r->callback()->Run(result); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 491 | MaybeOnAvailableSocketSlot(group_name); |
| 492 | } |
| 493 | |
| 494 | return; |
| 495 | } |
| 496 | |
| 497 | RequestMap* request_map = &group.connecting_requests; |
| 498 | RequestMap::iterator it = request_map->find(key_handle); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 499 | CHECK(it != request_map->end()); |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 500 | const Request* request = it->second; |
| 501 | ClientSocketHandle* const handle = request->handle(); |
| 502 | CompletionCallback* const callback = request->callback(); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 503 | |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 504 | LoadLog::EndEvent(request->load_log(), LoadLog::TYPE_SOCKET_POOL); |
| 505 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 506 | RemoveConnectJob(key_handle, job, &group); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 507 | |
| 508 | if (result != OK) { |
[email protected] | 8e12ae0 | 2009-07-02 16:15:04 | [diff] [blame] | 509 | DCHECK(!socket.get()); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 510 | callback->Run(result); // |group| is not necessarily valid after this. |
| 511 | // |group| may be invalid after the callback, we need to search |
| 512 | // |group_map_| again. |
| 513 | MaybeOnAvailableSocketSlot(group_name); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 514 | } else { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 515 | DCHECK(socket.get()); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 516 | HandOutSocket(socket.release(), false /* not reused */, handle, |
| 517 | base::TimeDelta(), &group); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 518 | callback->Run(result); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 519 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 520 | } |
| 521 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 522 | void ClientSocketPoolBaseHelper::EnableLateBindingOfSockets(bool enabled) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 523 | g_late_binding = enabled; |
| 524 | } |
| 525 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 526 | void ClientSocketPoolBaseHelper::RemoveConnectJob( |
[email protected] | 974ebd6 | 2009-08-03 23:14:34 | [diff] [blame] | 527 | const ClientSocketHandle* handle, const ConnectJob *job, Group* group) { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 528 | CHECK(connecting_socket_count_ > 0); |
| 529 | connecting_socket_count_--; |
| 530 | |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 531 | if (g_late_binding) { |
| 532 | DCHECK(job); |
| 533 | delete job; |
| 534 | } else { |
| 535 | ConnectJobMap::iterator it = connect_job_map_.find(handle); |
| 536 | CHECK(it != connect_job_map_.end()); |
| 537 | job = it->second; |
| 538 | delete job; |
| 539 | connect_job_map_.erase(it); |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 540 | RequestMap::iterator map_it = group->connecting_requests.find(handle); |
| 541 | CHECK(map_it != group->connecting_requests.end()); |
| 542 | const Request* request = map_it->second; |
| 543 | delete request; |
| 544 | group->connecting_requests.erase(map_it); |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | if (group) { |
| 548 | DCHECK(ContainsKey(group->jobs, job)); |
| 549 | group->jobs.erase(job); |
| 550 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 551 | } |
| 552 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 553 | void ClientSocketPoolBaseHelper::MaybeOnAvailableSocketSlot( |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 554 | const std::string& group_name) { |
| 555 | GroupMap::iterator it = group_map_.find(group_name); |
| 556 | if (it != group_map_.end()) { |
| 557 | Group& group = it->second; |
| 558 | if (group.HasAvailableSocketSlot(max_sockets_per_group_)) |
| 559 | OnAvailableSocketSlot(group_name, &group); |
| 560 | } |
| 561 | } |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 562 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 563 | void ClientSocketPoolBaseHelper::OnAvailableSocketSlot( |
| 564 | const std::string& group_name, Group* group) { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 565 | if (may_have_stalled_group_) { |
| 566 | std::string top_group_name; |
[email protected] | bed37d44 | 2009-08-20 19:58:20 | [diff] [blame] | 567 | Group* top_group = NULL; |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 568 | int stalled_group_count = FindTopStalledGroup(&top_group, &top_group_name); |
| 569 | if (stalled_group_count <= 1) |
| 570 | may_have_stalled_group_ = false; |
| 571 | if (stalled_group_count >= 1) |
| 572 | ProcessPendingRequest(top_group_name, top_group); |
| 573 | } else if (!group->pending_requests.empty()) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 574 | ProcessPendingRequest(group_name, group); |
| 575 | // |group| may no longer be valid after this point. Be careful not to |
| 576 | // access it again. |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 577 | } else if (group->IsEmpty()) { |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 578 | // Delete |group| if no longer needed. |group| will no longer be valid. |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 579 | group_map_.erase(group_name); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 583 | void ClientSocketPoolBaseHelper::ProcessPendingRequest( |
| 584 | const std::string& group_name, Group* group) { |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 585 | scoped_ptr<const Request> r(RemoveRequestFromQueue( |
| 586 | group->pending_requests.begin(), &group->pending_requests)); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 587 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 588 | int rv = RequestSocket(group_name, r.get()); |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 589 | |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 590 | if (rv != ERR_IO_PENDING) { |
[email protected] | fd7b7c9 | 2009-08-20 19:38:30 | [diff] [blame] | 591 | LoadLog::EndEvent(r->load_log(), LoadLog::TYPE_SOCKET_POOL); |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 592 | r->callback()->Run(rv); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 593 | if (rv != OK) { |
| 594 | // |group| may be invalid after the callback, we need to search |
| 595 | // |group_map_| again. |
| 596 | MaybeOnAvailableSocketSlot(group_name); |
| 597 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 598 | } else { |
| 599 | r.release(); |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 603 | void ClientSocketPoolBaseHelper::HandOutSocket( |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 604 | ClientSocket* socket, |
| 605 | bool reused, |
| 606 | ClientSocketHandle* handle, |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 607 | base::TimeDelta idle_time, |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 608 | Group* group) { |
| 609 | DCHECK(socket); |
| 610 | handle->set_socket(socket); |
| 611 | handle->set_is_reused(reused); |
[email protected] | f9d285c | 2009-08-17 19:54:29 | [diff] [blame] | 612 | handle->set_idle_time(idle_time); |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 613 | |
| 614 | handed_out_socket_count_++; |
[email protected] | 2ab05b5 | 2009-07-01 23:57:58 | [diff] [blame] | 615 | group->active_socket_count++; |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 616 | } |
| 617 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 618 | void ClientSocketPoolBaseHelper::AddIdleSocket( |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 619 | ClientSocket* socket, bool used, Group* group) { |
| 620 | DCHECK(socket); |
| 621 | IdleSocket idle_socket; |
| 622 | idle_socket.socket = socket; |
| 623 | idle_socket.start_time = base::TimeTicks::Now(); |
| 624 | idle_socket.used = used; |
| 625 | |
| 626 | group->idle_sockets.push_back(idle_socket); |
| 627 | IncrementIdleCount(); |
| 628 | } |
| 629 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 630 | void ClientSocketPoolBaseHelper::CancelAllConnectJobs() { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 631 | for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { |
| 632 | Group& group = i->second; |
| 633 | STLDeleteElements(&group.jobs); |
| 634 | |
| 635 | // Delete group if no longer needed. |
| 636 | if (group.IsEmpty()) { |
[email protected] | 5fc08e3 | 2009-07-15 17:09:57 | [diff] [blame] | 637 | group_map_.erase(i++); |
| 638 | } else { |
| 639 | ++i; |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 644 | bool ClientSocketPoolBaseHelper::ReachedMaxSocketsLimit() const { |
[email protected] | 211d217 | 2009-07-22 15:48:53 | [diff] [blame] | 645 | // Each connecting socket will eventually connect and be handed out. |
| 646 | int total = handed_out_socket_count_ + connecting_socket_count_; |
| 647 | DCHECK_LE(total, max_sockets_); |
| 648 | return total == max_sockets_; |
| 649 | } |
| 650 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 651 | } // namespace internal |
| 652 | |
| 653 | void EnableLateBindingOfSockets(bool enabled) { |
| 654 | internal::ClientSocketPoolBaseHelper::EnableLateBindingOfSockets(enabled); |
| 655 | } |
| 656 | |
[email protected] | ff579d4 | 2009-06-24 15:47:02 | [diff] [blame] | 657 | } // namespace net |