| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| 6 #define NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 6 #define NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace base { | 22 namespace base { |
| 23 class DictionaryValue; | 23 class DictionaryValue; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 class ClientSocketHandle; | 28 class ClientSocketHandle; |
| 29 class ClientSocketPoolHistograms; | 29 class ClientSocketPoolHistograms; |
| 30 class StreamSocket; | 30 class StreamSocket; |
| 31 | 31 |
| 32 // ClientSocketPools are layered. This defines an interface for lower level | |
| 33 // socket pools to communicate with higher layer pools. | |
| 34 class LayeredPool { | |
| 35 public: | |
| 36 // Instructs the LayeredPool to close an idle connection. Return true if one | |
| 37 // was closed. | |
| 38 virtual bool CloseOneIdleConnection() = 0; | |
| 39 }; | |
| 40 | |
| 41 // A ClientSocketPool is used to restrict the number of sockets open at a time. | 32 // A ClientSocketPool is used to restrict the number of sockets open at a time. |
| 42 // It also maintains a list of idle persistent sockets. | 33 // It also maintains a list of idle persistent sockets. |
| 43 // | 34 // |
| 44 class NET_EXPORT ClientSocketPool { | 35 class NET_EXPORT ClientSocketPool { |
| 45 public: | 36 public: |
| 46 // Requests a connected socket for a group_name. | 37 // Requests a connected socket for a group_name. |
| 47 // | 38 // |
| 48 // There are five possible results from calling this function: | 39 // There are five possible results from calling this function: |
| 49 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 40 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
| 50 // 2) RequestSocket returns OK with a newly connected socket. | 41 // 2) RequestSocket returns OK with a newly connected socket. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 virtual void ReleaseSocket(const std::string& group_name, | 103 virtual void ReleaseSocket(const std::string& group_name, |
| 113 StreamSocket* socket, | 104 StreamSocket* socket, |
| 114 int id) = 0; | 105 int id) = 0; |
| 115 | 106 |
| 116 // This flushes all state from the ClientSocketPool. This means that all | 107 // This flushes all state from the ClientSocketPool. This means that all |
| 117 // idle and connecting sockets are discarded. Active sockets being | 108 // idle and connecting sockets are discarded. Active sockets being |
| 118 // held by ClientSocketPool clients will be discarded when released back to | 109 // held by ClientSocketPool clients will be discarded when released back to |
| 119 // the pool. Does not flush any pools wrapped by |this|. | 110 // the pool. Does not flush any pools wrapped by |this|. |
| 120 virtual void Flush() = 0; | 111 virtual void Flush() = 0; |
| 121 | 112 |
| 122 // Returns true if a new request may hit a per-pool (not per-host) max socket | |
| 123 // limit. | |
| 124 virtual bool IsStalled() const = 0; | |
| 125 | |
| 126 // Called to close any idle connections held by the connection manager. | 113 // Called to close any idle connections held by the connection manager. |
| 127 virtual void CloseIdleSockets() = 0; | 114 virtual void CloseIdleSockets() = 0; |
| 128 | 115 |
| 129 // The total number of idle sockets in the pool. | 116 // The total number of idle sockets in the pool. |
| 130 virtual int IdleSocketCount() const = 0; | 117 virtual int IdleSocketCount() const = 0; |
| 131 | 118 |
| 132 // The total number of idle sockets in a connection group. | 119 // The total number of idle sockets in a connection group. |
| 133 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; | 120 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; |
| 134 | 121 |
| 135 // Determine the LoadState of a connecting ClientSocketHandle. | 122 // Determine the LoadState of a connecting ClientSocketHandle. |
| 136 virtual LoadState GetLoadState(const std::string& group_name, | 123 virtual LoadState GetLoadState(const std::string& group_name, |
| 137 const ClientSocketHandle* handle) const = 0; | 124 const ClientSocketHandle* handle) const = 0; |
| 138 | 125 |
| 139 // Adds a LayeredPool on top of |this|. | |
| 140 virtual void AddLayeredPool(LayeredPool* layered_pool) = 0; | |
| 141 | |
| 142 // Removes a LayeredPool from |this|. | |
| 143 virtual void RemoveLayeredPool(LayeredPool* layered_pool) = 0; | |
| 144 | |
| 145 // Retrieves information on the current state of the pool as a | 126 // Retrieves information on the current state of the pool as a |
| 146 // DictionaryValue. Caller takes possession of the returned value. | 127 // DictionaryValue. Caller takes possession of the returned value. |
| 147 // If |include_nested_pools| is true, the states of any nested | 128 // If |include_nested_pools| is true, the states of any nested |
| 148 // ClientSocketPools will be included. | 129 // ClientSocketPools will be included. |
| 149 virtual base::DictionaryValue* GetInfoAsValue( | 130 virtual base::DictionaryValue* GetInfoAsValue( |
| 150 const std::string& name, | 131 const std::string& name, |
| 151 const std::string& type, | 132 const std::string& type, |
| 152 bool include_nested_pools) const = 0; | 133 bool include_nested_pools) const = 0; |
| 153 | 134 |
| 154 // Returns the maximum amount of time to wait before retrying a connect. | 135 // Returns the maximum amount of time to wait before retrying a connect. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 const scoped_refptr<SocketParams>& params, | 190 const scoped_refptr<SocketParams>& params, |
| 210 int num_sockets, | 191 int num_sockets, |
| 211 const BoundNetLog& net_log) { | 192 const BoundNetLog& net_log) { |
| 212 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); | 193 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); |
| 213 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); | 194 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); |
| 214 } | 195 } |
| 215 | 196 |
| 216 } // namespace net | 197 } // namespace net |
| 217 | 198 |
| 218 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 199 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |