| 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 13 matching lines...) Expand all Loading... |
| 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 | 32 // ClientSocketPools are layered. This defines an interface for lower level |
| 33 // socket pools to communicate with higher layer pools. | 33 // socket pools to communicate with higher layer pools. |
| 34 class NET_EXPORT LayeredPool { | 34 class NET_EXPORT HigherLayeredPool { |
| 35 public: | 35 public: |
| 36 virtual ~LayeredPool() {}; | 36 virtual ~HigherLayeredPool() {} |
| 37 | 37 |
| 38 // Instructs the LayeredPool to close an idle connection. Return true if one | 38 // Instructs the HigherLayeredPool to close an idle connection. Return true if |
| 39 // was closed. | 39 // one was closed. Closing an idle connection will call into the lower layer |
| 40 // pool it came from, so must be careful of re-entrancy when using this. |
| 40 virtual bool CloseOneIdleConnection() = 0; | 41 virtual bool CloseOneIdleConnection() = 0; |
| 41 }; | 42 }; |
| 42 | 43 |
| 44 // ClientSocketPools are layered. This defines an interface for higher level |
| 45 // socket pools to communicate with lower layer pools. |
| 46 class NET_EXPORT LowerLayeredPool { |
| 47 public: |
| 48 virtual ~LowerLayeredPool() {} |
| 49 |
| 50 // Returns true if a there is currently a request blocked on the per-pool |
| 51 // (not per-host) max socket limit, either in this pool, or one that it is |
| 52 // layered on top of. |
| 53 virtual bool IsStalled() const = 0; |
| 54 |
| 55 // Called to add or remove a higher layer pool on top of |this|. A higher |
| 56 // layer pool may be added at most once to |this|, and must be removed prior |
| 57 // to destruction of |this|. |
| 58 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; |
| 59 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; |
| 60 }; |
| 61 |
| 43 // A ClientSocketPool is used to restrict the number of sockets open at a time. | 62 // A ClientSocketPool is used to restrict the number of sockets open at a time. |
| 44 // It also maintains a list of idle persistent sockets. | 63 // It also maintains a list of idle persistent sockets. |
| 45 // | 64 // |
| 46 class NET_EXPORT ClientSocketPool { | 65 class NET_EXPORT ClientSocketPool : public LowerLayeredPool { |
| 47 public: | 66 public: |
| 48 // Subclasses must also have an inner class SocketParams which is | 67 // Subclasses must also have an inner class SocketParams which is |
| 49 // the type for the |params| argument in RequestSocket() and | 68 // the type for the |params| argument in RequestSocket() and |
| 50 // RequestSockets() below. | 69 // RequestSockets() below. |
| 51 | 70 |
| 52 // Requests a connected socket for a group_name. | 71 // Requests a connected socket for a group_name. |
| 53 // | 72 // |
| 54 // There are five possible results from calling this function: | 73 // There are five possible results from calling this function: |
| 55 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 74 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
| 56 // 2) RequestSocket returns OK with a newly connected socket. | 75 // 2) RequestSocket returns OK with a newly connected socket. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 scoped_ptr<StreamSocket> socket, | 138 scoped_ptr<StreamSocket> socket, |
| 120 int id) = 0; | 139 int id) = 0; |
| 121 | 140 |
| 122 // This flushes all state from the ClientSocketPool. This means that all | 141 // This flushes all state from the ClientSocketPool. This means that all |
| 123 // idle and connecting sockets are discarded with the given |error|. | 142 // idle and connecting sockets are discarded with the given |error|. |
| 124 // Active sockets being held by ClientSocketPool clients will be discarded | 143 // Active sockets being held by ClientSocketPool clients will be discarded |
| 125 // when released back to the pool. | 144 // when released back to the pool. |
| 126 // Does not flush any pools wrapped by |this|. | 145 // Does not flush any pools wrapped by |this|. |
| 127 virtual void FlushWithError(int error) = 0; | 146 virtual void FlushWithError(int error) = 0; |
| 128 | 147 |
| 129 // Returns true if a there is currently a request blocked on the | |
| 130 // per-pool (not per-host) max socket limit. | |
| 131 virtual bool IsStalled() const = 0; | |
| 132 | |
| 133 // Called to close any idle connections held by the connection manager. | 148 // Called to close any idle connections held by the connection manager. |
| 134 virtual void CloseIdleSockets() = 0; | 149 virtual void CloseIdleSockets() = 0; |
| 135 | 150 |
| 136 // The total number of idle sockets in the pool. | 151 // The total number of idle sockets in the pool. |
| 137 virtual int IdleSocketCount() const = 0; | 152 virtual int IdleSocketCount() const = 0; |
| 138 | 153 |
| 139 // The total number of idle sockets in a connection group. | 154 // The total number of idle sockets in a connection group. |
| 140 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; | 155 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; |
| 141 | 156 |
| 142 // Determine the LoadState of a connecting ClientSocketHandle. | 157 // Determine the LoadState of a connecting ClientSocketHandle. |
| 143 virtual LoadState GetLoadState(const std::string& group_name, | 158 virtual LoadState GetLoadState(const std::string& group_name, |
| 144 const ClientSocketHandle* handle) const = 0; | 159 const ClientSocketHandle* handle) const = 0; |
| 145 | 160 |
| 146 // Adds a LayeredPool on top of |this|. | |
| 147 virtual void AddLayeredPool(LayeredPool* layered_pool) = 0; | |
| 148 | |
| 149 // Removes a LayeredPool from |this|. | |
| 150 virtual void RemoveLayeredPool(LayeredPool* layered_pool) = 0; | |
| 151 | |
| 152 // Retrieves information on the current state of the pool as a | 161 // Retrieves information on the current state of the pool as a |
| 153 // DictionaryValue. Caller takes possession of the returned value. | 162 // DictionaryValue. Caller takes possession of the returned value. |
| 154 // If |include_nested_pools| is true, the states of any nested | 163 // If |include_nested_pools| is true, the states of any nested |
| 155 // ClientSocketPools will be included. | 164 // ClientSocketPools will be included. |
| 156 virtual base::DictionaryValue* GetInfoAsValue( | 165 virtual base::DictionaryValue* GetInfoAsValue( |
| 157 const std::string& name, | 166 const std::string& name, |
| 158 const std::string& type, | 167 const std::string& type, |
| 159 bool include_nested_pools) const = 0; | 168 bool include_nested_pools) const = 0; |
| 160 | 169 |
| 161 // Returns the maximum amount of time to wait before retrying a connect. | 170 // Returns the maximum amount of time to wait before retrying a connect. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 188 const std::string& group_name, | 197 const std::string& group_name, |
| 189 const scoped_refptr<typename PoolType::SocketParams>& params, | 198 const scoped_refptr<typename PoolType::SocketParams>& params, |
| 190 int num_sockets, | 199 int num_sockets, |
| 191 const BoundNetLog& net_log) { | 200 const BoundNetLog& net_log) { |
| 192 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); | 201 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); |
| 193 } | 202 } |
| 194 | 203 |
| 195 } // namespace net | 204 } // namespace net |
| 196 | 205 |
| 197 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 206 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |