Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 // Called to add or remove a higher layer pool on top of |this|. A higher | 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 | 55 // layer pool may be added at most once to |this|, and must be removed prior |
| 56 // to destruction of |this|. | 56 // to destruction of |this|. |
| 57 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; | 57 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; |
| 58 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; | 58 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) = 0; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // 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. |
| 62 // It also maintains a list of idle persistent sockets. | 62 // It also maintains a list of idle persistent sockets. |
| 63 // | 63 // |
| 64 // Subclasses must also have an inner class SocketParams which is | |
| 65 // the type for the |params| argument in RequestSocket() and | |
| 66 // RequestSockets() below. | |
| 64 class NET_EXPORT ClientSocketPool : public LowerLayeredPool { | 67 class NET_EXPORT ClientSocketPool : public LowerLayeredPool { |
| 65 public: | 68 public: |
| 66 // Subclasses must also have an inner class SocketParams which is | 69 // Indicates whether a request for a socket should ignore the SocketPool's |
| 67 // the type for the |params| argument in RequestSocket() and | 70 // global and per-group socket limits. |
| 68 // RequestSockets() below. | 71 enum class IgnoreLimits { DISABLED, ENABLED }; |
|
eroman
2016/01/27 20:15:12
Not sure what to suggest in its place, but "ENABLE
mmenke
2016/01/27 20:37:27
Hrm... IgnoreLimits::DEFAULT / NORMAL seems less
eroman
2016/01/27 20:40:21
ok
| |
| 69 | 72 |
| 70 // Requests a connected socket for a group_name. | 73 // Requests a connected socket for a group_name. |
| 71 // | 74 // |
| 72 // There are five possible results from calling this function: | 75 // There are five possible results from calling this function: |
| 73 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 76 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
| 74 // 2) RequestSocket returns OK with a newly connected socket. | 77 // 2) RequestSocket returns OK with a newly connected socket. |
| 75 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a | 78 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a |
| 76 // wait list until a socket is available to reuse or a new socket finishes | 79 // wait list until a socket is available to reuse or a new socket finishes |
| 77 // connecting. |priority| will determine the placement into the wait list. | 80 // connecting. |priority| will determine the placement into the wait list. |
| 78 // 4) An error occurred early on, so RequestSocket returns an error code. | 81 // 4) An error occurred early on, so RequestSocket returns an error code. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 89 // StreamSocket was reused, then ClientSocketPool will call | 92 // StreamSocket was reused, then ClientSocketPool will call |
| 90 // |handle|->set_reused(true). In either case, the socket will have been | 93 // |handle|->set_reused(true). In either case, the socket will have been |
| 91 // allocated and will be connected. A client might want to know whether or | 94 // allocated and will be connected. A client might want to know whether or |
| 92 // not the socket is reused in order to request a new socket if it encounters | 95 // not the socket is reused in order to request a new socket if it encounters |
| 93 // an error with the reused socket. | 96 // an error with the reused socket. |
| 94 // | 97 // |
| 95 // If ERR_IO_PENDING is returned, then the callback will be used to notify the | 98 // If ERR_IO_PENDING is returned, then the callback will be used to notify the |
| 96 // client of completion. | 99 // client of completion. |
| 97 // | 100 // |
| 98 // Profiling information for the request is saved to |net_log| if non-NULL. | 101 // Profiling information for the request is saved to |net_log| if non-NULL. |
| 102 // | |
| 103 // If |ignore_limits| is ENABLED, priority must be HIGHEST. | |
| 99 virtual int RequestSocket(const std::string& group_name, | 104 virtual int RequestSocket(const std::string& group_name, |
| 100 const void* params, | 105 const void* params, |
| 101 RequestPriority priority, | 106 RequestPriority priority, |
| 107 IgnoreLimits ignore_limits, | |
| 102 ClientSocketHandle* handle, | 108 ClientSocketHandle* handle, |
| 103 const CompletionCallback& callback, | 109 const CompletionCallback& callback, |
| 104 const BoundNetLog& net_log) = 0; | 110 const BoundNetLog& net_log) = 0; |
| 105 | 111 |
| 106 // RequestSockets is used to request that |num_sockets| be connected in the | 112 // RequestSockets is used to request that |num_sockets| be connected in the |
| 107 // connection group for |group_name|. If the connection group already has | 113 // connection group for |group_name|. If the connection group already has |
| 108 // |num_sockets| idle sockets / active sockets / currently connecting sockets, | 114 // |num_sockets| idle sockets / active sockets / currently connecting sockets, |
| 109 // then this function doesn't do anything. Otherwise, it will start up as | 115 // then this function doesn't do anything. Otherwise, it will start up as |
| 110 // many connections as necessary to reach |num_sockets| total sockets for the | 116 // many connections as necessary to reach |num_sockets| total sockets for the |
| 111 // group. It uses |params| to control how to connect the sockets. The | 117 // group. It uses |params| to control how to connect the sockets. The |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 const std::string& group_name, | 198 const std::string& group_name, |
| 193 const scoped_refptr<typename PoolType::SocketParams>& params, | 199 const scoped_refptr<typename PoolType::SocketParams>& params, |
| 194 int num_sockets, | 200 int num_sockets, |
| 195 const BoundNetLog& net_log) { | 201 const BoundNetLog& net_log) { |
| 196 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); | 202 pool->RequestSockets(group_name, ¶ms, num_sockets, net_log); |
| 197 } | 203 } |
| 198 | 204 |
| 199 } // namespace net | 205 } // namespace net |
| 200 | 206 |
| 201 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ | 207 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |