| Index: net/base/client_socket_pool.h
|
| ===================================================================
|
| --- net/base/client_socket_pool.h (revision 14127)
|
| +++ net/base/client_socket_pool.h (working copy)
|
| @@ -28,7 +28,19 @@
|
| //
|
| class ClientSocketPool : public base::RefCounted<ClientSocketPool> {
|
| public:
|
| - explicit ClientSocketPool(int max_sockets_per_group);
|
| + // Construct a socket pool with the given limits.
|
| + //
|
| + // |max_sockets_per_group|:
|
| + // The total number of active sockets allowed per "group".
|
| + // (A "group" generally corresponds with a single host, so this is
|
| + // effectively the connections-per-host bound).
|
| + //
|
| + // |max_sockets|:
|
| + // The total number of active sockets across all groups.
|
| + //
|
| + // TODO(eroman): would be nice to define these in terms of "open" sockets
|
| + // instead (active + idle).
|
| + ClientSocketPool(int max_sockets_per_group, int max_sockets);
|
|
|
| // Called to request a socket for the given handle. There are three possible
|
| // results: 1) the handle will be initialized with a socket to reuse, 2) the
|
| @@ -110,6 +122,11 @@
|
| std::deque<IdleSocket> idle_sockets;
|
| RequestQueue pending_requests;
|
| int active_socket_count;
|
| +
|
| + bool empty() const {
|
| + return active_socket_count == 0 && idle_sockets.empty() &&
|
| + pending_requests.empty();
|
| + }
|
| };
|
|
|
| typedef std::map<std::string, Group> GroupMap;
|
| @@ -130,6 +147,30 @@
|
| // Called via PostTask by ReleaseSocket.
|
| void DoReleaseSocket(const std::string& group_name, ClientSocketPtr* ptr);
|
|
|
| + // Dequeue and start the highest priority pending request in |group|.
|
| + void StartPendingRequestForGroup(Group* group);
|
| +
|
| + // Finds the group containing the highest priority pending request, and which
|
| + // has fewer than |max_sockets_per_group_| active sockets. Returns NULL if
|
| + // there is no such group.
|
| + Group* FindTopStalledGroup();
|
| +
|
| + // Until the maximum number of sockets limit is reached, a group can ONLY
|
| + // have pending requests if it exceeds the "max sockets per group" limit.
|
| + //
|
| + // This means when a socket is released, the only pending requests that can
|
| + // be started next belong to the same group.
|
| + //
|
| + // However once the |max_sockets_| limit is reached, this stops being true:
|
| + // groups can now have pending requests without having first reached the
|
| + // |max_sockets_per_group_| limit. So choosing the next request involves
|
| + // selecting the highest priority request across *all* groups.
|
| + //
|
| + // Since reaching the maximum number of sockets is an edge case, we make note
|
| + // of when it happens with the following variable, and thus avoid doing
|
| + // the slower "scan all groups" in the common case.
|
| + bool may_have_stalled_group_;
|
| +
|
| // Called when timer_ fires. This method scans the idle sockets removing
|
| // sockets that timed out or can't be reused.
|
| void OnCleanupTimerFired() {
|
| @@ -145,9 +186,15 @@
|
| // The total number of idle sockets in the system.
|
| int idle_socket_count_;
|
|
|
| - // The maximum number of sockets kept per group.
|
| + // The total number of active sockets in the system.
|
| + int active_socket_count_;
|
| +
|
| + // The maximum number of active sockets kept per group.
|
| int max_sockets_per_group_;
|
|
|
| + // The maximum number of active sockets kept across all groups.
|
| + int max_sockets_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(ClientSocketPool);
|
| };
|
|
|
|
|