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 #include "net/socket/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // NOTE(mmenke): Wonder if we really need different code for each case | 362 // NOTE(mmenke): Wonder if we really need different code for each case |
363 // here. Only reason for them now seems to be preconnects. | 363 // here. Only reason for them now seems to be preconnects. |
364 if (idle_socket_count() > 0) { | 364 if (idle_socket_count() > 0) { |
365 // There's an idle socket in this pool. Either that's because there's | 365 // There's an idle socket in this pool. Either that's because there's |
366 // still one in this group, but we got here due to preconnecting bypassing | 366 // still one in this group, but we got here due to preconnecting bypassing |
367 // idle sockets, or because there's an idle socket in another group. | 367 // idle sockets, or because there's an idle socket in another group. |
368 bool closed = CloseOneIdleSocketExceptInGroup(group); | 368 bool closed = CloseOneIdleSocketExceptInGroup(group); |
369 if (preconnecting && !closed) | 369 if (preconnecting && !closed) |
370 return ERR_PRECONNECT_MAX_SOCKET_LIMIT; | 370 return ERR_PRECONNECT_MAX_SOCKET_LIMIT; |
371 } else { | 371 } else { |
372 // We could check if we really have a stalled group here, but it requires | 372 do { |
373 // a scan of all groups, so just flip a flag here, and do the check later. | 373 if (!CloseOneIdleConnectionInLayeredPool()) { |
374 request->net_log().AddEvent( | 374 // We could check if we really have a stalled group here, but it |
375 NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS, NULL); | 375 // requires a scan of all groups, so return ERR_IO_PENDING, and do |
376 return ERR_IO_PENDING; | 376 // the check later. |
| 377 request->net_log().AddEvent( |
| 378 NetLog::TYPE_SOCKET_POOL_STALLED_MAX_SOCKETS, NULL); |
| 379 return ERR_IO_PENDING; |
| 380 } |
| 381 } while (ReachedMaxSocketsLimit()); |
| 382 |
| 383 // It is possible that CloseOneIdleConnectionInLayeredPool() has deleted |
| 384 // our Group (see http://crbug.com/109876), so look it up again |
| 385 // to be safe. |
| 386 group = GetOrCreateGroup(group_name); |
377 } | 387 } |
378 } | 388 } |
379 | 389 |
380 // We couldn't find a socket to reuse, and there's space to allocate one, | 390 // We couldn't find a socket to reuse, and there's space to allocate one, |
381 // so allocate and connect a new one. | 391 // so allocate and connect a new one. |
382 scoped_ptr<ConnectJob> connect_job( | 392 scoped_ptr<ConnectJob> connect_job( |
383 connect_job_factory_->NewConnectJob(group_name, *request, this)); | 393 connect_job_factory_->NewConnectJob(group_name, *request, this)); |
384 | 394 |
385 connect_job->Initialize(preconnecting); | 395 connect_job->Initialize(preconnecting); |
386 int rv = connect_job->Connect(); | 396 int rv = connect_job->Connect(); |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 // Delete active jobs. | 1223 // Delete active jobs. |
1214 STLDeleteElements(&jobs_); | 1224 STLDeleteElements(&jobs_); |
1215 | 1225 |
1216 // Cancel pending backup job. | 1226 // Cancel pending backup job. |
1217 weak_factory_.InvalidateWeakPtrs(); | 1227 weak_factory_.InvalidateWeakPtrs(); |
1218 } | 1228 } |
1219 | 1229 |
1220 } // namespace internal | 1230 } // namespace internal |
1221 | 1231 |
1222 } // namespace net | 1232 } // namespace net |
OLD | NEW |