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_; |
157 | 158 |
158 // The time the Connect() method was called (if it got called). | 159 // The time the Connect() method was called (if it got called). |
159 base::Time connect_start_time_; | 160 base::Time connect_start_time_; |
160 | 161 |
161 DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); | 162 DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); |
162 }; | 163 }; |
163 | 164 |
164 typedef std::map<const ClientSocketHandle*, ConnectingSocket*> | |
165 ConnectingSocketMap; | |
166 | |
167 virtual ~TCPClientSocketPool(); | 165 virtual ~TCPClientSocketPool(); |
168 | 166 |
169 static void InsertRequestIntoQueue(const Request& r, | 167 static void InsertRequestIntoQueue(const Request& r, |
170 RequestQueue* pending_requests); | 168 RequestQueue* pending_requests); |
171 | 169 |
172 // Closes all idle sockets if |force| is true. Else, only closes idle | 170 // Closes all idle sockets if |force| is true. Else, only closes idle |
173 // sockets that timed out or can't be reused. | 171 // sockets that timed out or can't be reused. |
174 void CleanupIdleSockets(bool force); | 172 void CleanupIdleSockets(bool force); |
175 | 173 |
176 // Called when the number of idle sockets changes. | 174 // Called when the number of idle sockets changes. |
177 void IncrementIdleCount(); | 175 void IncrementIdleCount(); |
178 void DecrementIdleCount(); | 176 void DecrementIdleCount(); |
179 | 177 |
180 // Called via PostTask by ReleaseSocket. | 178 // Called via PostTask by ReleaseSocket. |
181 void DoReleaseSocket(const std::string& group_name, ClientSocket* socket); | 179 void DoReleaseSocket(const std::string& group_name, ClientSocket* socket); |
182 | 180 |
183 // Called when timer_ fires. This method scans the idle sockets removing | 181 // Called when timer_ fires. This method scans the idle sockets removing |
184 // sockets that timed out or can't be reused. | 182 // sockets that timed out or can't be reused. |
185 void OnCleanupTimerFired() { | 183 void OnCleanupTimerFired() { |
186 CleanupIdleSockets(false); | 184 CleanupIdleSockets(false); |
187 } | 185 } |
188 | 186 |
189 // Removes the ConnectingSocket corresponding to |handle| from the | |
190 // |connecting_socket_map_|. | |
191 void RemoveConnectingSocket(const ClientSocketHandle* handle); | |
192 | |
193 ClientSocketFactory* const client_socket_factory_; | 187 ClientSocketFactory* const client_socket_factory_; |
194 | 188 |
195 GroupMap group_map_; | 189 GroupMap group_map_; |
196 | 190 |
197 ConnectingSocketMap connecting_socket_map_; | 191 std::map<const ClientSocketHandle*, ConnectingSocket*> connecting_socket_map_; |
198 | 192 |
199 // Timer used to periodically prune idle sockets that timed out or can't be | 193 // Timer used to periodically prune idle sockets that timed out or can't be |
200 // reused. | 194 // reused. |
201 base::RepeatingTimer<TCPClientSocketPool> timer_; | 195 base::RepeatingTimer<TCPClientSocketPool> timer_; |
202 | 196 |
203 // The total number of idle sockets in the system. | 197 // The total number of idle sockets in the system. |
204 int idle_socket_count_; | 198 int idle_socket_count_; |
205 | 199 |
206 // The maximum number of sockets kept per group. | 200 // The maximum number of sockets kept per group. |
207 const int max_sockets_per_group_; | 201 const int max_sockets_per_group_; |
208 | 202 |
209 // The host resolver that will be used to do DNS lookups for connecting | 203 // The host resolver that will be used to do DNS lookups for connecting |
210 // sockets. | 204 // sockets. |
211 HostResolver* host_resolver_; | 205 HostResolver* host_resolver_; |
212 | 206 |
213 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); | 207 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); |
214 }; | 208 }; |
215 | 209 |
216 } // namespace net | 210 } // namespace net |
217 | 211 |
218 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 212 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |