summaryrefslogtreecommitdiffstats
path: root/net/base/client_socket_pool.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/base/client_socket_pool.cc')
-rw-r--r--net/base/client_socket_pool.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/net/base/client_socket_pool.cc b/net/base/client_socket_pool.cc
index 2092017..651fbe2 100644
--- a/net/base/client_socket_pool.cc
+++ b/net/base/client_socket_pool.cc
@@ -41,7 +41,21 @@ ClientSocketPool::~ClientSocketPool() {
DCHECK(group_map_.empty());
}
+// InsertRequestIntoQueue inserts the request into the queue based on
+// priority. Highest priorities are closest to the front. Older requests are
+// prioritized over requests of equal priority.
+//
+// static
+void ClientSocketPool::InsertRequestIntoQueue(const Request& r,
+ RequestQueue* pending_requests) {
+ RequestQueue::iterator it = pending_requests->begin();
+ while (it != pending_requests->end() && r.priority <= it->priority)
+ ++it;
+ pending_requests->insert(it, r);
+}
+
int ClientSocketPool::RequestSocket(ClientSocketHandle* handle,
+ int priority,
CompletionCallback* callback) {
Group& group = group_map_[handle->group_name_];
@@ -51,7 +65,8 @@ int ClientSocketPool::RequestSocket(ClientSocketHandle* handle,
r.handle = handle;
DCHECK(callback);
r.callback = callback;
- group.pending_requests.push_back(r);
+ r.priority = priority;
+ InsertRequestIntoQueue(r, &group.pending_requests);
return ERR_IO_PENDING;
}
@@ -183,7 +198,7 @@ void ClientSocketPool::DoReleaseSocket(const std::string& group_name,
if (!group.pending_requests.empty()) {
Request r = group.pending_requests.front();
group.pending_requests.pop_front();
- int rv = RequestSocket(r.handle, NULL);
+ int rv = RequestSocket(r.handle, r.priority, NULL);
DCHECK(rv == OK);
r.callback->Run(rv);
return;