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 #include "net/socket/client_socket_pool_manager.h" | 5 #include "net/socket/client_socket_pool_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
12 #include "net/http/http_network_session.h" | |
13 #include "net/http/http_proxy_client_socket_pool.h" | 12 #include "net/http/http_proxy_client_socket_pool.h" |
14 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
15 #include "net/http/http_stream_factory.h" | 14 #include "net/http/http_stream_factory.h" |
16 #include "net/proxy/proxy_info.h" | 15 #include "net/proxy/proxy_info.h" |
17 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
18 #include "net/socket/socks_client_socket_pool.h" | 17 #include "net/socket/socks_client_socket_pool.h" |
19 #include "net/socket/ssl_client_socket_pool.h" | 18 #include "net/socket/ssl_client_socket_pool.h" |
20 #include "net/socket/transport_client_socket_pool.h" | 19 #include "net/socket/transport_client_socket_pool.h" |
21 | 20 |
22 namespace net { | 21 namespace net { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 // Limit of sockets of each socket pool. | 25 // Limit of sockets of each socket pool. |
27 int g_max_sockets_per_pool = 256; | 26 int g_max_sockets_per_pool[HttpNetworkSession::NUM_SOCKET_POOL_TYPES] = { |
27 256, // NORMAL_SOCKET_POOL | |
28 256 // WEBSOCKET_SOCKET_POOL | |
29 }; | |
mmenke
2012/03/21 14:24:34
Since we're specifying default values here, rather
mmenke
2012/03/21 14:25:25
Err, that should be:
int g_max_sockets_per_pool[]
Yuta Kitamura
2012/03/21 17:30:12
Done.
| |
28 | 30 |
29 // Default to allow up to 6 connections per host. Experiment and tuning may | 31 // Default to allow up to 6 connections per host. Experiment and tuning may |
30 // try other values (greater than 0). Too large may cause many problems, such | 32 // try other values (greater than 0). Too large may cause many problems, such |
31 // as home routers blocking the connections!?!? See http://crbug.com/12066. | 33 // as home routers blocking the connections!?!? See http://crbug.com/12066. |
32 int g_max_sockets_per_group = 6; | 34 // |
35 // WebSocket connections are long-lived, and should be treated differently | |
36 // than normal other connections. 6 connections per group sounded too small | |
37 // for such use, thus we use a larger limit which was determined somewhat | |
38 // arbitrarily. | |
39 // TODO(yutak): Look at the usage and determine the right value after | |
40 // WebSocket protocol stack starts to work. | |
41 int g_max_sockets_per_group[HttpNetworkSession::NUM_SOCKET_POOL_TYPES] = { | |
42 6, // NORMAL_SOCKET_POOL | |
43 30 // WEBSOCKET_SOCKET_POOL | |
44 }; | |
33 | 45 |
34 // The max number of sockets to allow per proxy server. This applies both to | 46 // The max number of sockets to allow per proxy server. This applies both to |
35 // http and SOCKS proxies. See http://crbug.com/12066 and | 47 // http and SOCKS proxies. See http://crbug.com/12066 and |
36 // http://crbug.com/44501 for details about proxy server connection limits. | 48 // http://crbug.com/44501 for details about proxy server connection limits. |
37 int g_max_sockets_per_proxy_server = kDefaultMaxSocketsPerProxyServer; | 49 int g_max_sockets_per_proxy_server[ |
50 HttpNetworkSession::NUM_SOCKET_POOL_TYPES] = { | |
51 kDefaultMaxSocketsPerProxyServer, // NORMAL_SOCKET_POOL | |
52 kDefaultMaxSocketsPerProxyServer // WEBSOCKET_SOCKET_POOL | |
53 }; | |
38 | 54 |
39 // The meat of the implementation for the InitSocketHandleForHttpRequest, | 55 // The meat of the implementation for the InitSocketHandleForHttpRequest, |
40 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods. | 56 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods. |
41 int InitSocketPoolHelper(const GURL& request_url, | 57 int InitSocketPoolHelper(const GURL& request_url, |
42 const HttpRequestHeaders& request_extra_headers, | 58 const HttpRequestHeaders& request_extra_headers, |
43 int request_load_flags, | 59 int request_load_flags, |
44 RequestPriority request_priority, | 60 RequestPriority request_priority, |
45 HttpNetworkSession* session, | 61 HttpNetworkSession* session, |
46 const ProxyInfo& proxy_info, | 62 const ProxyInfo& proxy_info, |
47 bool force_spdy_over_ssl, | 63 bool force_spdy_over_ssl, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 num_preconnect_streams, net_log); | 197 num_preconnect_streams, net_log); |
182 return OK; | 198 return OK; |
183 } | 199 } |
184 | 200 |
185 return socket_handle->Init(connection_group, ssl_params, | 201 return socket_handle->Init(connection_group, ssl_params, |
186 request_priority, callback, ssl_pool, | 202 request_priority, callback, ssl_pool, |
187 net_log); | 203 net_log); |
188 } | 204 } |
189 | 205 |
190 // Finally, get the connection started. | 206 // Finally, get the connection started. |
207 | |
191 if (proxy_info.is_http() || proxy_info.is_https()) { | 208 if (proxy_info.is_http() || proxy_info.is_https()) { |
192 HttpProxyClientSocketPool* pool = | 209 HttpProxyClientSocketPool* pool = |
193 session->GetSocketPoolForHTTPProxy( | 210 session->GetSocketPoolForHTTPProxy( |
194 HttpNetworkSession::NORMAL_SOCKET_POOL, | 211 HttpNetworkSession::NORMAL_SOCKET_POOL, |
195 *proxy_host_port); | 212 *proxy_host_port); |
196 if (num_preconnect_streams) { | 213 if (num_preconnect_streams) { |
197 RequestSocketsForPool(pool, connection_group, http_proxy_params, | 214 RequestSocketsForPool(pool, connection_group, http_proxy_params, |
198 num_preconnect_streams, net_log); | 215 num_preconnect_streams, net_log); |
199 return OK; | 216 return OK; |
200 } | 217 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 request_priority, callback, | 251 request_priority, callback, |
235 pool, net_log); | 252 pool, net_log); |
236 } | 253 } |
237 | 254 |
238 } // namespace | 255 } // namespace |
239 | 256 |
240 ClientSocketPoolManager::ClientSocketPoolManager() {} | 257 ClientSocketPoolManager::ClientSocketPoolManager() {} |
241 ClientSocketPoolManager::~ClientSocketPoolManager() {} | 258 ClientSocketPoolManager::~ClientSocketPoolManager() {} |
242 | 259 |
243 // static | 260 // static |
244 int ClientSocketPoolManager::max_sockets_per_pool() { | 261 int ClientSocketPoolManager::max_sockets_per_pool( |
245 return g_max_sockets_per_pool; | 262 HttpNetworkSession::SocketPoolType pool_type) { |
263 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); | |
264 return g_max_sockets_per_pool[pool_type]; | |
246 } | 265 } |
247 | 266 |
248 // static | 267 // static |
249 void ClientSocketPoolManager::set_max_sockets_per_pool(int socket_count) { | 268 void ClientSocketPoolManager::set_max_sockets_per_pool( |
269 HttpNetworkSession::SocketPoolType pool_type, | |
270 int socket_count) { | |
250 DCHECK_LT(0, socket_count); | 271 DCHECK_LT(0, socket_count); |
251 DCHECK_GT(1000, socket_count); // Sanity check. | 272 DCHECK_GT(1000, socket_count); // Sanity check. |
252 g_max_sockets_per_pool = socket_count; | 273 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); |
253 DCHECK_GE(g_max_sockets_per_pool, g_max_sockets_per_group); | 274 g_max_sockets_per_pool[pool_type] = socket_count; |
275 DCHECK_GE(g_max_sockets_per_pool[pool_type], | |
276 g_max_sockets_per_group[pool_type]); | |
254 } | 277 } |
255 | 278 |
256 // static | 279 // static |
257 int ClientSocketPoolManager::max_sockets_per_group() { | 280 int ClientSocketPoolManager::max_sockets_per_group( |
258 return g_max_sockets_per_group; | 281 HttpNetworkSession::SocketPoolType pool_type) { |
282 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); | |
283 return g_max_sockets_per_group[pool_type]; | |
259 } | 284 } |
260 | 285 |
261 // static | 286 // static |
262 void ClientSocketPoolManager::set_max_sockets_per_group(int socket_count) { | 287 void ClientSocketPoolManager::set_max_sockets_per_group( |
288 HttpNetworkSession::SocketPoolType pool_type, | |
289 int socket_count) { | |
263 DCHECK_LT(0, socket_count); | 290 DCHECK_LT(0, socket_count); |
264 // The following is a sanity check... but we should NEVER be near this value. | 291 // The following is a sanity check... but we should NEVER be near this value. |
265 DCHECK_GT(100, socket_count); | 292 DCHECK_GT(100, socket_count); |
266 g_max_sockets_per_group = socket_count; | 293 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); |
294 g_max_sockets_per_group[pool_type] = socket_count; | |
267 | 295 |
268 DCHECK_GE(g_max_sockets_per_pool, g_max_sockets_per_group); | 296 DCHECK_GE(g_max_sockets_per_pool[pool_type], |
269 DCHECK_GE(g_max_sockets_per_proxy_server, g_max_sockets_per_group); | 297 g_max_sockets_per_group[pool_type]); |
298 DCHECK_GE(g_max_sockets_per_proxy_server[pool_type], | |
299 g_max_sockets_per_group[pool_type]); | |
270 } | 300 } |
271 | 301 |
272 // static | 302 // static |
273 int ClientSocketPoolManager::max_sockets_per_proxy_server() { | 303 int ClientSocketPoolManager::max_sockets_per_proxy_server( |
274 return g_max_sockets_per_proxy_server; | 304 HttpNetworkSession::SocketPoolType pool_type) { |
305 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); | |
306 return g_max_sockets_per_proxy_server[pool_type]; | |
275 } | 307 } |
276 | 308 |
277 // static | 309 // static |
278 void ClientSocketPoolManager::set_max_sockets_per_proxy_server( | 310 void ClientSocketPoolManager::set_max_sockets_per_proxy_server( |
311 HttpNetworkSession::SocketPoolType pool_type, | |
279 int socket_count) { | 312 int socket_count) { |
280 DCHECK_LT(0, socket_count); | 313 DCHECK_LT(0, socket_count); |
281 DCHECK_GT(100, socket_count); // Sanity check. | 314 DCHECK_GT(100, socket_count); // Sanity check. |
315 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); | |
282 // Assert this case early on. The max number of sockets per group cannot | 316 // Assert this case early on. The max number of sockets per group cannot |
283 // exceed the max number of sockets per proxy server. | 317 // exceed the max number of sockets per proxy server. |
284 DCHECK_LE(g_max_sockets_per_group, socket_count); | 318 DCHECK_LE(g_max_sockets_per_group[pool_type], socket_count); |
285 g_max_sockets_per_proxy_server = socket_count; | 319 g_max_sockets_per_proxy_server[pool_type] = socket_count; |
286 } | 320 } |
287 | 321 |
288 int InitSocketHandleForHttpRequest( | 322 int InitSocketHandleForHttpRequest( |
289 const GURL& request_url, | 323 const GURL& request_url, |
290 const HttpRequestHeaders& request_extra_headers, | 324 const HttpRequestHeaders& request_extra_headers, |
291 int request_load_flags, | 325 int request_load_flags, |
292 RequestPriority request_priority, | 326 RequestPriority request_priority, |
293 HttpNetworkSession* session, | 327 HttpNetworkSession* session, |
294 const ProxyInfo& proxy_info, | 328 const ProxyInfo& proxy_info, |
295 bool force_spdy_over_ssl, | 329 bool force_spdy_over_ssl, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 const BoundNetLog& net_log, | 377 const BoundNetLog& net_log, |
344 int num_preconnect_streams) { | 378 int num_preconnect_streams) { |
345 return InitSocketPoolHelper( | 379 return InitSocketPoolHelper( |
346 request_url, request_extra_headers, request_load_flags, request_priority, | 380 request_url, request_extra_headers, request_load_flags, request_priority, |
347 session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, | 381 session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, |
348 ssl_config_for_origin, ssl_config_for_proxy, false, net_log, | 382 ssl_config_for_origin, ssl_config_for_proxy, false, net_log, |
349 num_preconnect_streams, NULL, CompletionCallback()); | 383 num_preconnect_streams, NULL, CompletionCallback()); |
350 } | 384 } |
351 | 385 |
352 } // namespace net | 386 } // namespace net |
OLD | NEW |