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

Unified Diff: net/socket/client_socket_pool_base.cc

Issue 160499: Add timeouts for ConnectJobs. Limit ConnectJobs per group to number of Requests per group + 1. (Closed)
Patch Set: Revert the revert. Fix tests. Created 11 years, 5 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 db3858dcd458e566c33f943c8c38d66a44fe5b01..00b97536bf6c0077a7b888b3fb2c6ee1991b58d2 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_--;
« 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