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

Side by Side Diff: net/socket/client_socket_pool_base.cc

Issue 15927019: net: Socket pools prioritize requests with ignore_limits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove bonus spaces. Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 181
182 ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair( 182 ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair(
183 const CompletionCallback& callback_in, int result_in) 183 const CompletionCallback& callback_in, int result_in)
184 : callback(callback_in), 184 : callback(callback_in),
185 result(result_in) { 185 result(result_in) {
186 } 186 }
187 187
188 ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {} 188 ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {}
189 189
190 // InsertRequestIntoQueue inserts the request into the queue based on
191 // priority. Highest priorities are closest to the front. Older requests are
192 // prioritized over requests of equal priority.
193 //
194 // static 190 // static
195 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( 191 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue(
196 const Request* r, RequestQueue* pending_requests) { 192 const Request* r, RequestQueue* pending_requests) {
197 RequestQueue::iterator it = pending_requests->begin(); 193 RequestQueue::iterator it = pending_requests->begin();
198 while (it != pending_requests->end() && r->priority() <= (*it)->priority()) 194
195 // If not ignoring the socket pool limits, skip over all requests that do.
eroman 2013/06/04 20:42:21 rather than splitting things up into 2 loops, I su
mmenke 2013/06/05 04:32:24 Done, went with the function approach and a 3-valu
196 if (!r->ignore_limits()) {
197 while (it != pending_requests->end() && (*it)->ignore_limits()) {
198 ++it;
199 }
200 }
201
202 // Skip over all requests with priority <= the new request, with the same
203 // value of |ignore_limits|.
204 // TODO(mmenke): Should the network stack require requests with
205 // |ignore_limits| set have the highest priority?
eroman 2013/06/04 20:42:21 nit: wording. i think "have the" --> "to have the"
mmenke 2013/06/05 04:32:24 It's actually correct: "(requests with |ignore_li
206 while (it != pending_requests->end() && r->priority() <= (*it)->priority() &&
207 r->ignore_limits() == (*it)->ignore_limits()) {
199 ++it; 208 ++it;
209 }
200 pending_requests->insert(it, r); 210 pending_requests->insert(it, r);
201 } 211 }
202 212
203 // static 213 // static
204 const ClientSocketPoolBaseHelper::Request* 214 const ClientSocketPoolBaseHelper::Request*
205 ClientSocketPoolBaseHelper::RemoveRequestFromQueue( 215 ClientSocketPoolBaseHelper::RemoveRequestFromQueue(
206 const RequestQueue::iterator& it, Group* group) { 216 const RequestQueue::iterator& it, Group* group) {
207 const Request* req = *it; 217 const Request* req = *it;
208 group->mutable_pending_requests()->erase(it); 218 group->mutable_pending_requests()->erase(it);
209 // If there are no more requests, we kill the backup timer. 219 // If there are no more requests, we kill the backup timer.
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 Group* group = GetOrCreateGroup(group_name); 497 Group* group = GetOrCreateGroup(group_name);
488 498
489 // Search pending_requests for matching handle. 499 // Search pending_requests for matching handle.
490 RequestQueue::iterator it = group->mutable_pending_requests()->begin(); 500 RequestQueue::iterator it = group->mutable_pending_requests()->begin();
491 for (; it != group->pending_requests().end(); ++it) { 501 for (; it != group->pending_requests().end(); ++it) {
492 if ((*it)->handle() == handle) { 502 if ((*it)->handle() == handle) {
493 scoped_ptr<const Request> req(RemoveRequestFromQueue(it, group)); 503 scoped_ptr<const Request> req(RemoveRequestFromQueue(it, group));
494 req->net_log().AddEvent(NetLog::TYPE_CANCELLED); 504 req->net_log().AddEvent(NetLog::TYPE_CANCELLED);
495 req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); 505 req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
496 506
497 // We let the job run, unless we're at the socket limit. 507 // We let the job run, unless we're at the socket limit and there is
498 if (group->jobs().size() && ReachedMaxSocketsLimit()) { 508 // not another request waiting on the job.
509 if (group->jobs().size() > group->pending_requests().size() &&
510 ReachedMaxSocketsLimit()) {
499 RemoveConnectJob(*group->jobs().begin(), group); 511 RemoveConnectJob(*group->jobs().begin(), group);
500 CheckForStalledSocketGroups(); 512 CheckForStalledSocketGroups();
501 } 513 }
502 break; 514 break;
503 } 515 }
504 } 516 }
505 } 517 }
506 518
507 bool ClientSocketPoolBaseHelper::HasGroup(const std::string& group_name) const { 519 bool ClientSocketPoolBaseHelper::HasGroup(const std::string& group_name) const {
508 return ContainsKey(group_map_, group_name); 520 return ContainsKey(group_map_, group_name);
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 STLDeleteElements(&jobs_); 1230 STLDeleteElements(&jobs_);
1219 unassigned_job_count_ = 0; 1231 unassigned_job_count_ = 0;
1220 1232
1221 // Cancel pending backup job. 1233 // Cancel pending backup job.
1222 weak_factory_.InvalidateWeakPtrs(); 1234 weak_factory_.InvalidateWeakPtrs();
1223 } 1235 }
1224 1236
1225 } // namespace internal 1237 } // namespace internal
1226 1238
1227 } // namespace net 1239 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698