summaryrefslogtreecommitdiffstats
path: root/net/socket/client_socket_pool_base.cc
diff options
context:
space:
mode:
authorsgurun@google.com <sgurun@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-16 04:30:41 +0000
committersgurun@google.com <sgurun@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-16 04:30:41 +0000
commit64770b7da60e539b62d32eb7b0470d1eb2d7268c (patch)
tree2a352d9081806f7350634b7bb184ca8eba0c9ea5 /net/socket/client_socket_pool_base.cc
parentfa7bdda99be53c824d8ac74f063979d8ed752ea6 (diff)
downloadchromium_src-64770b7da60e539b62d32eb7b0470d1eb2d7268c.zip
chromium_src-64770b7da60e539b62d32eb7b0470d1eb2d7268c.tar.gz
chromium_src-64770b7da60e539b62d32eb7b0470d1eb2d7268c.tar.bz2
Close idle sockets next time we are about to send data.
This change enables closing idle sockets when client initiates a new socket request rather than using a timer based approach. This prevents waking up network interface only for the purpose of sending a FIN to the server. BUG=101820 TEST=unit-tests Review URL: http://codereview.chromium.org/8526006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110250 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/client_socket_pool_base.cc')
-rw-r--r--net/socket/client_socket_pool_base.cc38
1 files changed, 33 insertions, 5 deletions
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index 231254a..4c1600e 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -23,6 +23,10 @@ using base::TimeDelta;
namespace {
+// Indicate whether we should enable idle socket cleanup timer. When timer is
+// disabled, sockets are closed next time a socket request is made.
+bool g_cleanup_timer_enabled = true;
+
// The timeout value, in seconds, used to clean up idle sockets that can't be
// reused.
//
@@ -182,6 +186,7 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper(
handed_out_socket_count_(0),
max_sockets_(max_sockets),
max_sockets_per_group_(max_sockets_per_group),
+ use_cleanup_timer_(g_cleanup_timer_enabled),
unused_idle_socket_timeout_(unused_idle_socket_timeout),
used_idle_socket_timeout_(used_idle_socket_timeout),
connect_job_factory_(connect_job_factory),
@@ -237,6 +242,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 +267,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 +709,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 +718,23 @@ void ClientSocketPoolBaseHelper::DecrementIdleCount() {
timer_.Stop();
}
+// static
+bool ClientSocketPoolBaseHelper::cleanup_timer_enabled() {
+ return g_cleanup_timer_enabled;
+}
+
+// static
+bool ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(bool enabled) {
+ bool old_value = g_cleanup_timer_enabled;
+ g_cleanup_timer_enabled = enabled;
+ return old_value;
+}
+
+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 +925,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);
}
}