diff options
Diffstat (limited to 'net/base/client_socket_pool.h')
-rw-r--r-- | net/base/client_socket_pool.h | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/net/base/client_socket_pool.h b/net/base/client_socket_pool.h index a313a80..dd08c24 100644 --- a/net/base/client_socket_pool.h +++ b/net/base/client_socket_pool.h @@ -35,7 +35,8 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> { // handle will be initialized without a socket such that the consumer needs // to supply a socket, or 3) the handle will be added to a wait list until a // socket is available to reuse or the opportunity to create a new socket - // arises. The completion callback is notified in the 3rd case. + // arises. The completion callback is notified in the 3rd case. |priority| + // will determine the placement into the wait list. // // If this function returns OK, then |handle| is initialized upon return. // The |handle|'s is_initialized method will return true in this case. If a @@ -47,7 +48,9 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> { // If ERR_IO_PENDING is returned, then the completion callback will be called // when |handle| has been initialized. // - int RequestSocket(ClientSocketHandle* handle, CompletionCallback* callback); + int RequestSocket(ClientSocketHandle* handle, + int priority, + CompletionCallback* callback); // Called to cancel a RequestSocket call that returned ERR_IO_PENDING. The // same handle parameter must be passed to this method as was passed to the @@ -75,30 +78,12 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> { typedef scoped_ptr<ClientSocket> ClientSocketPtr; - ~ClientSocketPool(); - - // Closes all idle sockets if |force| is true. Else, only closes idle - // sockets that timed out or can't be reused. - void CleanupIdleSockets(bool force); - - // Called when the number of idle sockets changes. - void IncrementIdleCount(); - void DecrementIdleCount(); - - // Called via PostTask by ReleaseSocket. - void DoReleaseSocket(const std::string& group_name, ClientSocketPtr* ptr); - - // Called when timer_ fires. This method scans the idle sockets removing - // sockets that timed out or can't be reused. - void OnCleanupTimerFired() { - CleanupIdleSockets(false); - } - // A Request is allocated per call to RequestSocket that results in // ERR_IO_PENDING. struct Request { ClientSocketHandle* handle; CompletionCallback* callback; + int priority; }; // Entry for a persistent socket which became idle at time |start_time|. @@ -116,16 +101,41 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> { bool ShouldCleanup(base::TimeTicks now) const; }; + typedef std::deque<Request> RequestQueue; + // A Group is allocated per group_name when there are idle sockets or pending // requests. Otherwise, the Group object is removed from the map. struct Group { Group() : active_socket_count(0) {} std::deque<IdleSocket> idle_sockets; - std::deque<Request> pending_requests; + RequestQueue pending_requests; int active_socket_count; }; typedef std::map<std::string, Group> GroupMap; + + ~ClientSocketPool(); + + static void InsertRequestIntoQueue(const Request& r, + RequestQueue* pending_requests); + + // Closes all idle sockets if |force| is true. Else, only closes idle + // sockets that timed out or can't be reused. + void CleanupIdleSockets(bool force); + + // Called when the number of idle sockets changes. + void IncrementIdleCount(); + void DecrementIdleCount(); + + // Called via PostTask by ReleaseSocket. + void DoReleaseSocket(const std::string& group_name, ClientSocketPtr* ptr); + + // Called when timer_ fires. This method scans the idle sockets removing + // sockets that timed out or can't be reused. + void OnCleanupTimerFired() { + CleanupIdleSockets(false); + } + GroupMap group_map_; // Timer used to periodically prune idle sockets that timed out or can't be |