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

Unified Diff: net/socket/client_socket_pool_base.cc

Issue 176021: Control the amount of time to leave an unused socket idle before closing it. (Closed)
Patch Set: Address wtc's comments. Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/client_socket_pool_base.h ('k') | net/socket/client_socket_pool_base_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/client_socket_pool_base.cc
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index 533d103df50c2216cbac953777f82b284e6e4f9f..18a084b162db57a44fb624440fa6767553a21fa1 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -24,9 +24,6 @@ namespace {
// some conditions. See http://crbug.com/4606.
const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT.
-// The maximum duration, in seconds, to keep idle persistent sockets alive.
-const int kIdleTimeout = 300; // 5 minutes.
-
} // namespace
namespace net {
@@ -99,12 +96,16 @@ bool ClientSocketPoolBaseHelper::g_late_binding = false;
ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper(
int max_sockets,
int max_sockets_per_group,
+ base::TimeDelta unused_idle_socket_timeout,
+ base::TimeDelta used_idle_socket_timeout,
ConnectJobFactory* connect_job_factory)
: idle_socket_count_(0),
connecting_socket_count_(0),
handed_out_socket_count_(0),
max_sockets_(max_sockets),
max_sockets_per_group_(max_sockets_per_group),
+ unused_idle_socket_timeout_(unused_idle_socket_timeout),
+ used_idle_socket_timeout_(used_idle_socket_timeout),
may_have_stalled_group_(false),
connect_job_factory_(connect_job_factory) {
DCHECK_LE(0, max_sockets_per_group);
@@ -340,9 +341,9 @@ LoadState ClientSocketPoolBaseHelper::GetLoadState(
}
bool ClientSocketPoolBaseHelper::IdleSocket::ShouldCleanup(
- base::TimeTicks now) const {
- bool timed_out = (now - start_time) >=
- base::TimeDelta::FromSeconds(kIdleTimeout);
+ base::TimeTicks now,
+ base::TimeDelta timeout) const {
+ bool timed_out = (now - start_time) >= timeout;
return timed_out ||
!(used ? socket->IsConnectedAndIdle() : socket->IsConnected());
}
@@ -361,7 +362,9 @@ void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
std::deque<IdleSocket>::iterator j = group.idle_sockets.begin();
while (j != group.idle_sockets.end()) {
- if (force || j->ShouldCleanup(now)) {
+ base::TimeDelta timeout =
+ j->used ? used_idle_socket_timeout_ : unused_idle_socket_timeout_;
+ if (force || j->ShouldCleanup(now, timeout)) {
delete j->socket;
j = group.idle_sockets.erase(j);
DecrementIdleCount();
« no previous file with comments | « net/socket/client_socket_pool_base.h ('k') | net/socket/client_socket_pool_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698