OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
6 #define NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 6 #define NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 int OnIOCompleteInternal(int result, bool synchronous); | 147 int OnIOCompleteInternal(int result, bool synchronous); |
148 | 148 |
149 const std::string group_name_; | 149 const std::string group_name_; |
150 const ClientSocketHandle* const handle_; | 150 const ClientSocketHandle* const handle_; |
151 ClientSocketFactory* const client_socket_factory_; | 151 ClientSocketFactory* const client_socket_factory_; |
152 CompletionCallbackImpl<ConnectingSocket> callback_; | 152 CompletionCallbackImpl<ConnectingSocket> callback_; |
153 scoped_ptr<ClientSocket> socket_; | 153 scoped_ptr<ClientSocket> socket_; |
154 scoped_refptr<TCPClientSocketPool> pool_; | 154 scoped_refptr<TCPClientSocketPool> pool_; |
155 SingleRequestHostResolver resolver_; | 155 SingleRequestHostResolver resolver_; |
156 AddressList addresses_; | 156 AddressList addresses_; |
157 bool canceled_; | |
158 | 157 |
159 // The time the Connect() method was called (if it got called). | 158 // The time the Connect() method was called (if it got called). |
160 base::Time connect_start_time_; | 159 base::Time connect_start_time_; |
161 | 160 |
162 DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); | 161 DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); |
163 }; | 162 }; |
164 | 163 |
| 164 typedef std::map<const ClientSocketHandle*, ConnectingSocket*> |
| 165 ConnectingSocketMap; |
| 166 |
165 virtual ~TCPClientSocketPool(); | 167 virtual ~TCPClientSocketPool(); |
166 | 168 |
167 static void InsertRequestIntoQueue(const Request& r, | 169 static void InsertRequestIntoQueue(const Request& r, |
168 RequestQueue* pending_requests); | 170 RequestQueue* pending_requests); |
169 | 171 |
170 // Closes all idle sockets if |force| is true. Else, only closes idle | 172 // Closes all idle sockets if |force| is true. Else, only closes idle |
171 // sockets that timed out or can't be reused. | 173 // sockets that timed out or can't be reused. |
172 void CleanupIdleSockets(bool force); | 174 void CleanupIdleSockets(bool force); |
173 | 175 |
174 // Called when the number of idle sockets changes. | 176 // Called when the number of idle sockets changes. |
175 void IncrementIdleCount(); | 177 void IncrementIdleCount(); |
176 void DecrementIdleCount(); | 178 void DecrementIdleCount(); |
177 | 179 |
178 // Called via PostTask by ReleaseSocket. | 180 // Called via PostTask by ReleaseSocket. |
179 void DoReleaseSocket(const std::string& group_name, ClientSocket* socket); | 181 void DoReleaseSocket(const std::string& group_name, ClientSocket* socket); |
180 | 182 |
181 // Called when timer_ fires. This method scans the idle sockets removing | 183 // Called when timer_ fires. This method scans the idle sockets removing |
182 // sockets that timed out or can't be reused. | 184 // sockets that timed out or can't be reused. |
183 void OnCleanupTimerFired() { | 185 void OnCleanupTimerFired() { |
184 CleanupIdleSockets(false); | 186 CleanupIdleSockets(false); |
185 } | 187 } |
186 | 188 |
| 189 // Removes the ConnectingSocket corresponding to |handle| from the |
| 190 // |connecting_socket_map_|. |
| 191 void RemoveConnectingSocket(const ClientSocketHandle* handle); |
| 192 |
187 ClientSocketFactory* const client_socket_factory_; | 193 ClientSocketFactory* const client_socket_factory_; |
188 | 194 |
189 GroupMap group_map_; | 195 GroupMap group_map_; |
190 | 196 |
191 std::map<const ClientSocketHandle*, ConnectingSocket*> connecting_socket_map_; | 197 ConnectingSocketMap connecting_socket_map_; |
192 | 198 |
193 // Timer used to periodically prune idle sockets that timed out or can't be | 199 // Timer used to periodically prune idle sockets that timed out or can't be |
194 // reused. | 200 // reused. |
195 base::RepeatingTimer<TCPClientSocketPool> timer_; | 201 base::RepeatingTimer<TCPClientSocketPool> timer_; |
196 | 202 |
197 // The total number of idle sockets in the system. | 203 // The total number of idle sockets in the system. |
198 int idle_socket_count_; | 204 int idle_socket_count_; |
199 | 205 |
200 // The maximum number of sockets kept per group. | 206 // The maximum number of sockets kept per group. |
201 const int max_sockets_per_group_; | 207 const int max_sockets_per_group_; |
202 | 208 |
203 // The host resolver that will be used to do DNS lookups for connecting | 209 // The host resolver that will be used to do DNS lookups for connecting |
204 // sockets. | 210 // sockets. |
205 HostResolver* host_resolver_; | 211 HostResolver* host_resolver_; |
206 | 212 |
207 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); | 213 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); |
208 }; | 214 }; |
209 | 215 |
210 } // namespace net | 216 } // namespace net |
211 | 217 |
212 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 218 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |