summaryrefslogtreecommitdiffstats
path: root/net/socket/client_socket_pool_base.cc
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 22:05:15 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 22:05:15 +0000
commit02d89618b93897a404b466b2f019e7914dd8c798 (patch)
tree2053cf7b5b901f32f90a16dad527a583170970c8 /net/socket/client_socket_pool_base.cc
parentb10a91eb470ed96162c448b5a83b364aab23efac (diff)
downloadchromium_src-02d89618b93897a404b466b2f019e7914dd8c798.zip
chromium_src-02d89618b93897a404b466b2f019e7914dd8c798.tar.gz
chromium_src-02d89618b93897a404b466b2f019e7914dd8c798.tar.bz2
Add timeouts for ConnectJobs. Limit ConnectJobs per group to number of Requests per group + 1.
In the histograms for Net.SocketRequestTime, late binding has a much longer tail. This is presumably because I didn't implement timeouts and CancelRequest() never cancelled jobs. I'm limiting TCPConnectJobs to 30 seconds and cancelling jobs if there are too many more than there are requests. Review URL: http://codereview.chromium.org/160499 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22326 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/client_socket_pool_base.cc')
-rw-r--r--net/socket/client_socket_pool_base.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index db3858d..00b9753 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -34,9 +34,11 @@ bool ClientSocketPoolBase::g_late_binding = false;
ConnectJob::ConnectJob(const std::string& group_name,
const ClientSocketHandle* key_handle,
+ base::TimeDelta timeout_duration,
Delegate* delegate)
: group_name_(group_name),
key_handle_(key_handle),
+ timeout_duration_(timeout_duration),
delegate_(delegate),
load_state_(LOAD_STATE_IDLE) {
DCHECK(!group_name.empty());
@@ -46,6 +48,19 @@ ConnectJob::ConnectJob(const std::string& group_name,
ConnectJob::~ConnectJob() {}
+int ConnectJob::Connect() {
+ if (timeout_duration_ != base::TimeDelta())
+ timer_.Start(timeout_duration_, this, &ConnectJob::OnTimeout);
+ return ConnectInternal();
+}
+
+void ConnectJob::OnTimeout() {
+ // The delegate will delete |this|.
+ Delegate *delegate = delegate_;
+ delegate_ = NULL;
+ delegate->OnConnectJobComplete(ERR_TIMED_OUT, this);
+}
+
ClientSocketPoolBase::ClientSocketPoolBase(
int max_sockets,
int max_sockets_per_group,
@@ -164,6 +179,12 @@ void ClientSocketPoolBase::CancelRequest(const std::string& group_name,
for (; it != group.pending_requests.end(); ++it) {
if (it->handle == handle) {
group.pending_requests.erase(it);
+ if (g_late_binding &&
+ group.jobs.size() > group.pending_requests.size() + 1) {
+ // TODO(willchan): Cancel the job in the earliest LoadState.
+ RemoveConnectJob(handle, *group.jobs.begin(), &group);
+ OnAvailableSocketSlot(group_name, &group);
+ }
return;
}
}
@@ -417,7 +438,7 @@ void ClientSocketPoolBase::EnableLateBindingOfSockets(bool enabled) {
}
void ClientSocketPoolBase::RemoveConnectJob(
- const ClientSocketHandle* handle, ConnectJob *job, Group* group) {
+ const ClientSocketHandle* handle, const ConnectJob *job, Group* group) {
CHECK(connecting_socket_count_ > 0);
connecting_socket_count_--;