Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1535)

Side by Side Diff: net/http/http_network_session.cc

Issue 1808001: Implement a 15 connection per proxy server limit. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Remove extra newline. Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/http/http_network_session.h" 5 #include "net/http/http_network_session.h"
6 6
7 #include <utility>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util-inl.h"
11 #include "base/string_util.h"
8 #include "net/http/http_auth_handler_factory.h" 12 #include "net/http/http_auth_handler_factory.h"
9 #include "net/http/url_security_manager.h" 13 #include "net/http/url_security_manager.h"
10 #include "net/spdy/spdy_session_pool.h" 14 #include "net/spdy/spdy_session_pool.h"
11 15
12 namespace net { 16 namespace net {
13 17
14 // static 18 namespace {
15 int HttpNetworkSession::max_sockets_ = 256;
16 19
17 // static 20 // Total limit of sockets.
18 int HttpNetworkSession::max_sockets_per_group_ = 6; 21 int g_max_sockets = 256;
19 22
20 // static 23 // Default to allow up to 6 connections per host. Experiment and tuning may
21 uint16 HttpNetworkSession::g_fixed_http_port = 0; 24 // try other values (greater than 0). Too large may cause many problems, such
22 uint16 HttpNetworkSession::g_fixed_https_port = 0; 25 // as home routers blocking the connections!?!? See http://crbug.com/12066.
26 int g_max_sockets_per_group = 6;
27
28 // The max number of sockets to allow per proxy server. This applies both to
29 // http and SOCKS proxies. See http://crbug.com/12066 for details about proxy
30 // server connection limits.
31 int g_max_sockets_per_proxy_server = 15;
wtc 2010/05/03 19:01:53 I would use 16, since 15 is so close to a power of
32
33 uint16 g_fixed_http_port = 0;
34 uint16 g_fixed_https_port = 0;
35
36 } // namespace
23 37
24 // TODO(vandebo) when we've completely converted to pools, the base TCP 38 // TODO(vandebo) when we've completely converted to pools, the base TCP
25 // pool name should get changed to TCP instead of Transport. 39 // pool name should get changed to TCP instead of Transport.
26 HttpNetworkSession::HttpNetworkSession( 40 HttpNetworkSession::HttpNetworkSession(
27 NetworkChangeNotifier* network_change_notifier, 41 NetworkChangeNotifier* network_change_notifier,
28 HostResolver* host_resolver, 42 HostResolver* host_resolver,
29 ProxyService* proxy_service, 43 ProxyService* proxy_service,
30 ClientSocketFactory* client_socket_factory, 44 ClientSocketFactory* client_socket_factory,
31 SSLConfigService* ssl_config_service, 45 SSLConfigService* ssl_config_service,
32 SpdySessionPool* spdy_session_pool, 46 SpdySessionPool* spdy_session_pool,
33 HttpAuthHandlerFactory* http_auth_handler_factory) 47 HttpAuthHandlerFactory* http_auth_handler_factory)
34 : network_change_notifier_(network_change_notifier), 48 : network_change_notifier_(network_change_notifier),
35 tcp_socket_pool_(new TCPClientSocketPool( 49 tcp_socket_pool_(new TCPClientSocketPool(
36 max_sockets_, max_sockets_per_group_, "Transport", 50 g_max_sockets, g_max_sockets_per_group, "Transport",
37 host_resolver, client_socket_factory, network_change_notifier_)), 51 host_resolver, client_socket_factory, network_change_notifier_)),
38 socks_socket_pool_(new SOCKSClientSocketPool(
39 max_sockets_, max_sockets_per_group_, "SOCKS", host_resolver,
40 new TCPClientSocketPool(max_sockets_, max_sockets_per_group_,
41 "TCPForSOCKS", host_resolver,
42 client_socket_factory,
43 network_change_notifier_),
44 network_change_notifier_)),
45 socket_factory_(client_socket_factory), 52 socket_factory_(client_socket_factory),
46 host_resolver_(host_resolver), 53 host_resolver_(host_resolver),
47 proxy_service_(proxy_service), 54 proxy_service_(proxy_service),
48 ssl_config_service_(ssl_config_service), 55 ssl_config_service_(ssl_config_service),
49 spdy_session_pool_(spdy_session_pool), 56 spdy_session_pool_(spdy_session_pool),
50 http_auth_handler_factory_(http_auth_handler_factory) { 57 http_auth_handler_factory_(http_auth_handler_factory) {
51 DCHECK(proxy_service); 58 DCHECK(proxy_service);
52 DCHECK(ssl_config_service); 59 DCHECK(ssl_config_service);
53 } 60 }
54 61
55 HttpNetworkSession::~HttpNetworkSession() { 62 HttpNetworkSession::~HttpNetworkSession() {
56 } 63 }
57 64
65 const scoped_refptr<TCPClientSocketPool>&
66 HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) {
67 HTTPProxySocketPoolMap::const_iterator it =
68 http_proxy_socket_pool_.find(http_proxy);
69 if (it != http_proxy_socket_pool_.end())
70 return it->second;
71
72 std::pair<HTTPProxySocketPoolMap::iterator, bool> ret =
73 http_proxy_socket_pool_.insert(
74 std::make_pair(
75 http_proxy,
76 new TCPClientSocketPool(
77 g_max_sockets_per_proxy_server, g_max_sockets_per_group,
78 "HTTPProxy", host_resolver_, socket_factory_,
79 network_change_notifier_)));
80
81 return ret.first->second;
82 }
83
84 const scoped_refptr<SOCKSClientSocketPool>&
85 HttpNetworkSession::GetSocketPoolForSOCKSProxy(
86 const HostPortPair& socks_proxy) {
87 SOCKSSocketPoolMap::const_iterator it = socks_socket_pool_.find(socks_proxy);
88 if (it != socks_socket_pool_.end())
89 return it->second;
90
91 std::pair<SOCKSSocketPoolMap::iterator, bool> ret =
92 socks_socket_pool_.insert(
93 std::make_pair(
94 socks_proxy,
95 new SOCKSClientSocketPool(
96 g_max_sockets_per_proxy_server, g_max_sockets_per_group,
97 "SOCKS", host_resolver_,
98 new TCPClientSocketPool(g_max_sockets_per_proxy_server,
99 g_max_sockets_per_group,
100 "TCPForSOCKS", host_resolver_,
101 socket_factory_,
102 network_change_notifier_),
103 network_change_notifier_)));
104
105 return ret.first->second;
106 }
107
58 // static 108 // static
59 void HttpNetworkSession::set_max_sockets_per_group(int socket_count) { 109 void HttpNetworkSession::set_max_sockets_per_group(int socket_count) {
60 DCHECK(0 < socket_count); 110 DCHECK_LT(0, socket_count);
61 // The following is a sanity check... but we should NEVER be near this value. 111 // The following is a sanity check... but we should NEVER be near this value.
62 DCHECK(100 > socket_count); 112 DCHECK_GT(100, socket_count);
63 max_sockets_per_group_ = socket_count; 113 g_max_sockets_per_group = socket_count;
114 }
115
116 // static
117 uint16 HttpNetworkSession::fixed_http_port() {
118 return g_fixed_http_port;
119 }
120
121 // static
122 void HttpNetworkSession::set_fixed_http_port(uint16 port) {
123 g_fixed_http_port = port;
124 }
125
126 // static
127 uint16 HttpNetworkSession::fixed_https_port() {
128 return g_fixed_https_port;
129 }
130
131 // static
132 void HttpNetworkSession::set_fixed_https_port(uint16 port) {
133 g_fixed_https_port = port;
64 } 134 }
65 135
66 // TODO(vandebo) when we've completely converted to pools, the base TCP 136 // TODO(vandebo) when we've completely converted to pools, the base TCP
67 // pool name should get changed to TCP instead of Transport. 137 // pool name should get changed to TCP instead of Transport.
68 void HttpNetworkSession::ReplaceTCPSocketPool() { 138 void HttpNetworkSession::ReplaceTCPSocketPool() {
69 tcp_socket_pool_ = new TCPClientSocketPool(max_sockets_, 139 tcp_socket_pool_ = new TCPClientSocketPool(g_max_sockets,
70 max_sockets_per_group_, 140 g_max_sockets_per_group,
71 "Transport", 141 "Transport",
72 host_resolver_, 142 host_resolver_,
73 socket_factory_, 143 socket_factory_,
74 network_change_notifier_); 144 network_change_notifier_);
75 } 145 }
76 146
77 } // namespace net 147 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698