summaryrefslogtreecommitdiffstats
path: root/net/base/client_socket_pool.cc
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 23:27:33 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 23:27:33 +0000
commitb2197853ee021e8b6d1c4f3c46e475da372b6980 (patch)
tree3429dcfc22d7f3ec683bbe2c1923b208d78adb26 /net/base/client_socket_pool.cc
parent814c99861aa1116c588a63b20dd1b7a4f9a974e0 (diff)
downloadchromium_src-b2197853ee021e8b6d1c4f3c46e475da372b6980.zip
chromium_src-b2197853ee021e8b6d1c4f3c46e475da372b6980.tar.gz
chromium_src-b2197853ee021e8b6d1c4f3c46e475da372b6980.tar.bz2
If an idle socket has received data unexpectedly, we can't
reuse it. Add the IsConnectedAndIdle method, which returns true if the connection is still alive and idle (hasn't received any data unexpectedly). R=eroman BUG=4606 Review URL: http://codereview.chromium.org/21501 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/client_socket_pool.cc')
-rw-r--r--net/base/client_socket_pool.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/net/base/client_socket_pool.cc b/net/base/client_socket_pool.cc
index b8434dd..41c1b7f 100644
--- a/net/base/client_socket_pool.cc
+++ b/net/base/client_socket_pool.cc
@@ -13,11 +13,12 @@ using base::TimeDelta;
namespace {
-// The timeout value, in seconds, used to clean up disconnected idle sockets.
+// The timeout value, in seconds, used to clean up idle sockets that can't be
+// reused.
const int kCleanupInterval = 10;
// The maximum duration, in seconds, to keep idle persistent sockets alive.
-const int kIdleTimeout = 300; // 5 minutes.
+const int kIdleTimeout = 300; // 5 minutes.
} // namespace
@@ -54,12 +55,12 @@ int ClientSocketPool::RequestSocket(ClientSocketHandle* handle,
group.active_socket_count++;
// Use idle sockets in LIFO order because they're more likely to be
- // still connected.
+ // still reusable.
while (!group.idle_sockets.empty()) {
IdleSocket idle_socket = group.idle_sockets.back();
group.idle_sockets.pop_back();
DecrementIdleCount();
- if ((*idle_socket.ptr)->IsConnected()) {
+ if ((*idle_socket.ptr)->IsConnectedAndIdle()) {
// We found one we can reuse!
handle->socket_ = idle_socket.ptr;
return OK;
@@ -103,9 +104,9 @@ void ClientSocketPool::CloseIdleSockets() {
}
bool ClientSocketPool::IdleSocket::ShouldCleanup(base::TimeTicks now) const {
- bool timed_out = (now - start_time) >=
+ bool timed_out = (now - start_time) >=
base::TimeDelta::FromSeconds(kIdleTimeout);
- return timed_out || !(*ptr)->IsConnected();
+ return timed_out || !(*ptr)->IsConnectedAndIdle();
}
void ClientSocketPool::CleanupIdleSockets(bool force) {
@@ -162,7 +163,7 @@ void ClientSocketPool::DoReleaseSocket(const std::string& group_name,
DCHECK(group.active_socket_count > 0);
group.active_socket_count--;
- bool can_reuse = ptr->get() && (*ptr)->IsConnected();
+ bool can_reuse = ptr->get() && (*ptr)->IsConnectedAndIdle();
if (can_reuse) {
IdleSocket idle_socket;
idle_socket.ptr = ptr;