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

Unified Diff: net/socket/client_socket_pool_base.cc

Issue 8526006: Close idle sockets next time we are about to send data. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: code conventions Created 9 years, 1 month 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
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 231254a5b7d5cb126920812afbeea606bdf7b2be..02f479e985fa5ed4f289c7bba814cdaca5cd0015 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -176,12 +176,14 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper(
int max_sockets_per_group,
base::TimeDelta unused_idle_socket_timeout,
base::TimeDelta used_idle_socket_timeout,
- ConnectJobFactory* connect_job_factory)
+ ConnectJobFactory* connect_job_factory,
+ const ClientSocketPoolOptions& options)
: 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),
+ use_cleanup_timer_(options.use_cleanup_timer),
unused_idle_socket_timeout_(unused_idle_socket_timeout),
used_idle_socket_timeout_(used_idle_socket_timeout),
connect_job_factory_(connect_job_factory),
@@ -237,6 +239,10 @@ int ClientSocketPoolBaseHelper::RequestSocket(
CHECK(request->callback());
CHECK(request->handle());
+ // Cleanup any timed-out idle sockets if no timer is used.
+ if (!use_cleanup_timer_)
+ CleanupIdleSockets(false);
+
request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL, NULL);
Group* group = GetOrCreateGroup(group_name);
@@ -258,6 +264,10 @@ void ClientSocketPoolBaseHelper::RequestSockets(
DCHECK(!request.callback());
DCHECK(!request.handle());
+ // Cleanup any timed out idle sockets if no timer is used.
+ if (!use_cleanup_timer_)
+ CleanupIdleSockets(false);
+
if (num_sockets > max_sockets_per_group_) {
num_sockets = max_sockets_per_group_;
}
@@ -696,9 +706,8 @@ void ClientSocketPoolBaseHelper::EnableConnectBackupJobs() {
}
void ClientSocketPoolBaseHelper::IncrementIdleCount() {
- if (++idle_socket_count_ == 1)
- timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kCleanupInterval), this,
- &ClientSocketPoolBaseHelper::OnCleanupTimerFired);
+ if (++idle_socket_count_ == 1 && use_cleanup_timer_)
+ StartIdleSocketTimer();
}
void ClientSocketPoolBaseHelper::DecrementIdleCount() {
@@ -706,6 +715,11 @@ void ClientSocketPoolBaseHelper::DecrementIdleCount() {
timer_.Stop();
}
+void ClientSocketPoolBaseHelper::StartIdleSocketTimer() {
+ timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kCleanupInterval), this,
+ &ClientSocketPoolBaseHelper::OnCleanupTimerFired);
+}
+
void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name,
StreamSocket* socket,
int id) {
@@ -896,8 +910,7 @@ void ClientSocketPoolBaseHelper::ProcessPendingRequest(
RemoveGroup(group_name);
request->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL, rv);
- InvokeUserCallbackLater(
- request->handle(), request->callback(), rv);
+ InvokeUserCallbackLater(request->handle(), request->callback(), rv);
}
}

Powered by Google App Engine
This is Rietveld 408576698