Chromium Code Reviews| 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 // A ClientSocketPoolBase is used to restrict the number of sockets open at | 5 // A ClientSocketPoolBase is used to restrict the number of sockets open at |
| 6 // a time. It also maintains a list of idle persistent sockets for reuse. | 6 // a time. It also maintains a list of idle persistent sockets for reuse. |
| 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle | 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle |
| 8 // the core logic of (1) restricting the number of active (connected or | 8 // the core logic of (1) restricting the number of active (connected or |
| 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) | 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) |
| 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) | 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 // NetworkChangeNotifier::IPAddressObserver methods: | 331 // NetworkChangeNotifier::IPAddressObserver methods: |
| 332 virtual void OnIPAddressChanged() OVERRIDE; | 332 virtual void OnIPAddressChanged() OVERRIDE; |
| 333 | 333 |
| 334 private: | 334 private: |
| 335 friend class base::RefCounted<ClientSocketPoolBaseHelper>; | 335 friend class base::RefCounted<ClientSocketPoolBaseHelper>; |
| 336 | 336 |
| 337 // Entry for a persistent socket which became idle at time |start_time|. | 337 // Entry for a persistent socket which became idle at time |start_time|. |
| 338 struct IdleSocket { | 338 struct IdleSocket { |
| 339 IdleSocket() : socket(NULL) {} | 339 IdleSocket() : socket(NULL) {} |
| 340 | 340 |
| 341 // An idle socket can't be reused if it is disconnected or has been used | |
| 342 // before and has received data unexpectedly (hence no longer idle). The | |
| 343 // unread data would be mistaken for the beginning of the next response if | |
| 344 // we were to reuse the socket for a new request. | |
| 345 // | |
| 346 // Note that a preconnected socket (one that has never been used before) | |
|
mmenke
2014/02/25 17:01:53
Suggest rephrasing this to be "Note that a socket
davidben
2014/02/27 16:36:35
Done.
| |
| 347 // with unread data may be reused. This may be, e.g., a SPDY SETTINGS | |
| 348 // frame. | |
| 349 bool IsReusable() const; | |
| 350 | |
| 341 // An idle socket should be removed if it can't be reused, or has been idle | 351 // An idle socket should be removed if it can't be reused, or has been idle |
| 342 // for too long. |now| is the current time value (TimeTicks::Now()). | 352 // for too long. |now| is the current time value (TimeTicks::Now()). |
| 343 // |timeout| is the length of time to wait before timing out an idle socket. | 353 // |timeout| is the length of time to wait before timing out an idle socket. |
| 344 // | |
| 345 // An idle socket can't be reused if it is disconnected or has received | |
| 346 // data unexpectedly (hence no longer idle). The unread data would be | |
| 347 // mistaken for the beginning of the next response if we were to reuse the | |
| 348 // socket for a new request. | |
| 349 bool ShouldCleanup(base::TimeTicks now, base::TimeDelta timeout) const; | 354 bool ShouldCleanup(base::TimeTicks now, base::TimeDelta timeout) const; |
| 350 | 355 |
| 351 StreamSocket* socket; | 356 StreamSocket* socket; |
| 352 base::TimeTicks start_time; | 357 base::TimeTicks start_time; |
| 353 }; | 358 }; |
| 354 | 359 |
| 355 typedef PriorityQueue<const Request*> RequestQueue; | 360 typedef PriorityQueue<const Request*> RequestQueue; |
| 356 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap; | 361 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap; |
| 357 | 362 |
| 358 // A Group is allocated per group_name when there are idle sockets or pending | 363 // A Group is allocated per group_name when there are idle sockets or pending |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 866 // Histograms for the pool | 871 // Histograms for the pool |
| 867 ClientSocketPoolHistograms* const histograms_; | 872 ClientSocketPoolHistograms* const histograms_; |
| 868 internal::ClientSocketPoolBaseHelper helper_; | 873 internal::ClientSocketPoolBaseHelper helper_; |
| 869 | 874 |
| 870 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 875 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 871 }; | 876 }; |
| 872 | 877 |
| 873 } // namespace net | 878 } // namespace net |
| 874 | 879 |
| 875 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 880 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |