| 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 #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 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 | 26 |
| 27 class ClientSocketHandle; | 27 class ClientSocketHandle; |
| 28 class ClientSocketPoolHistograms; | 28 class ClientSocketPoolHistograms; |
| 29 class StreamSocket; | 29 class StreamSocket; |
| 30 | 30 |
| 31 // ClientSocketPools are layered. This defines an interface for lower level | 31 // ClientSocketPools are layered. This defines an interface for lower level |
| 32 // socket pools to communicate with higher layer pools. | 32 // socket pools to communicate with higher layer pools. |
| 33 class NET_EXPORT LayeredPool { | 33 class NET_EXPORT HigherLayeredPool { |
| 34 public: | 34 public: |
| 35 virtual ~LayeredPool() {}; | 35 virtual ~HigherLayeredPool() {} |
| 36 | 36 |
| 37 // Instructs the LayeredPool to close an idle connection. Return true if one | 37 // Instructs the HigherLayeredPool to close an idle connection. Return true if |
| 38 // was closed. | 38 // one was closed. Closing an idle connection will call into the lower layer |
| 39 // pool it came from, so must be careful of re-entrancy when using this. |
| 39 virtual bool CloseOneIdleConnection() = 0; | 40 virtual bool CloseOneIdleConnection() = 0; |
| 40 }; | 41 }; |
| 41 | 42 |
| 43 // ClientSocketPools are layered. This defines an interface for higher level |
| 44 // socket pools to communicate with lower layer pools. |
| 45 class NET_EXPORT LowerLayeredPool { |
| 46 public: |
| 47 virtual ~LowerLayeredPool() {} |
| 48 |
| 49 // Returns true if a there is currently a request blocked on the per-pool |
| 50 // (not per-host) max socket limit, either in this pool, or one that it is |
| 51 // layered on top of. |
| 52 virtual bool IsStalled() const = 0; |
| 53 |
| 54 // Called to add or remove a higher layer pool on top of |this|. A higher |
| 55 // layer pool may be added at most once to |this|, and must be removed prior |
| 56 // to destruction of |this|. |
| 57 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; |
| 58 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; |
| 59 }; |
| 60 |
| 42 // A ClientSocketPool is used to restrict the number of sockets open at a time. | 61 // A ClientSocketPool is used to restrict the number of sockets open at a time. |
| 43 // It also maintains a list of idle persistent sockets. | 62 // It also maintains a list of idle persistent sockets. |
| 44 // | 63 // |
| 45 class NET_EXPORT ClientSocketPool { | 64 class NET_EXPORT ClientSocketPool : public LowerLayeredPool { |
| 46 public: | 65 public: |
| 47 // Requests a connected socket for a group_name. | 66 // Requests a connected socket for a group_name. |
| 48 // | 67 // |
| 49 // There are five possible results from calling this function: | 68 // There are five possible results from calling this function: |
| 50 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 69 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
| 51 // 2) RequestSocket returns OK with a newly connected socket. | 70 // 2) RequestSocket returns OK with a newly connected socket. |
| 52 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a | 71 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a |
| 53 // wait list until a socket is available to reuse or a new socket finishes | 72 // wait list until a socket is available to reuse or a new socket finishes |
| 54 // connecting. |priority| will determine the placement into the wait list. | 73 // connecting. |priority| will determine the placement into the wait list. |
| 55 // 4) An error occurred early on, so RequestSocket returns an error code. | 74 // 4) An error occurred early on, so RequestSocket returns an error code. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 StreamSocket* socket, | 133 StreamSocket* socket, |
| 115 int id) = 0; | 134 int id) = 0; |
| 116 | 135 |
| 117 // This flushes all state from the ClientSocketPool. This means that all | 136 // This flushes all state from the ClientSocketPool. This means that all |
| 118 // idle and connecting sockets are discarded with the given |error|. | 137 // idle and connecting sockets are discarded with the given |error|. |
| 119 // Active sockets being held by ClientSocketPool clients will be discarded | 138 // Active sockets being held by ClientSocketPool clients will be discarded |
| 120 // when released back to the pool. | 139 // when released back to the pool. |
| 121 // Does not flush any pools wrapped by |this|. | 140 // Does not flush any pools wrapped by |this|. |
| 122 virtual void FlushWithError(int error) = 0; | 141 virtual void FlushWithError(int error) = 0; |
| 123 | 142 |
| 124 // Returns true if a there is currently a request blocked on the | |
| 125 // per-pool (not per-host) max socket limit. | |
| 126 virtual bool IsStalled() const = 0; | |
| 127 | |
| 128 // Called to close any idle connections held by the connection manager. | 143 // Called to close any idle connections held by the connection manager. |
| 129 virtual void CloseIdleSockets() = 0; | 144 virtual void CloseIdleSockets() = 0; |
| 130 | 145 |
| 131 // The total number of idle sockets in the pool. | 146 // The total number of idle sockets in the pool. |
| 132 virtual int IdleSocketCount() const = 0; | 147 virtual int IdleSocketCount() const = 0; |
| 133 | 148 |
| 134 // The total number of idle sockets in a connection group. | 149 // The total number of idle sockets in a connection group. |
| 135 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; | 150 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; |
| 136 | 151 |
| 137 // Determine the LoadState of a connecting ClientSocketHandle. | 152 // Determine the LoadState of a connecting ClientSocketHandle. |
| 138 virtual LoadState GetLoadState(const std::string& group_name, | 153 virtual LoadState GetLoadState(const std::string& group_name, |
| 139 const ClientSocketHandle* handle) const = 0; | 154 const ClientSocketHandle* handle) const = 0; |
| 140 | 155 |
| 141 // Adds a LayeredPool on top of |this|. | |
| 142 virtual void AddLayeredPool(LayeredPool* layered_pool) = 0; | |
| 143 | |
| 144 // Removes a LayeredPool from |this|. | |
| 145 virtual void RemoveLayeredPool(LayeredPool* layered_pool) = 0; | |
| 146 | |
| 147 // Retrieves information on the current state of the pool as a | 156 // Retrieves information on the current state of the pool as a |
| 148 // DictionaryValue. Caller takes possession of the returned value. | 157 // DictionaryValue. Caller takes possession of the returned value. |
| 149 // If |include_nested_pools| is true, the states of any nested | 158 // If |include_nested_pools| is true, the states of any nested |
| 150 // ClientSocketPools will be included. | 159 // ClientSocketPools will be included. |
| 151 virtual base::DictionaryValue* GetInfoAsValue( | 160 virtual base::DictionaryValue* GetInfoAsValue( |
| 152 const std::string& name, | 161 const std::string& name, |
| 153 const std::string& type, | 162 const std::string& type, |
| 154 bool include_nested_pools) const = 0; | 163 bool include_nested_pools) const = 0; |
| 155 | 164 |
| 156 // Returns the maximum amount of time to wait before retrying a connect. | 165 // 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... |
| 211 const scoped_refptr<SocketParams>& params, | 220 const scoped_refptr<SocketParams>& params, |
| 212 int num_sockets, | 221 int num_sockets, |
| 213 const BoundNetLog& net_log) { | 222 const BoundNetLog& net_log) { |
| 214 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); | 223 CheckIsValidSocketParamsForPool<PoolType, SocketParams>(); |
| 215 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); | 224 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); |
| 216 } | 225 } |
| 217 | 226 |
| 218 } // namespace net | 227 } // namespace net |
| 219 | 228 |
| 220 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 229 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |