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

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: Small comment fix 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/metrics/stats_counters.h" 11 #include "base/metrics/stats_counters.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "net/base/net_log.h" 16 #include "net/base/net_log.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/socket/client_socket_handle.h" 18 #include "net/socket/client_socket_handle.h"
19 19
20 using base::TimeDelta; 20 using base::TimeDelta;
21 21
22 namespace net {
23
22 namespace { 24 namespace {
23 25
24 // Indicate whether we should enable idle socket cleanup timer. When timer is 26 // Indicate whether we should enable idle socket cleanup timer. When timer is
25 // disabled, sockets are closed next time a socket request is made. 27 // disabled, sockets are closed next time a socket request is made.
26 bool g_cleanup_timer_enabled = true; 28 bool g_cleanup_timer_enabled = true;
27 29
28 // The timeout value, in seconds, used to clean up idle sockets that can't be 30 // The timeout value, in seconds, used to clean up idle sockets that can't be
29 // reused. 31 // reused.
30 // 32 //
31 // Note: It's important to close idle sockets that have received data as soon 33 // Note: It's important to close idle sockets that have received data as soon
32 // as possible because the received data may cause BSOD on Windows XP under 34 // as possible because the received data may cause BSOD on Windows XP under
33 // some conditions. See http://crbug.com/4606. 35 // some conditions. See http://crbug.com/4606.
34 const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT. 36 const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT.
35 37
36 // Indicate whether or not we should establish a new transport layer connection 38 // Indicate whether or not we should establish a new transport layer connection
37 // after a certain timeout has passed without receiving an ACK. 39 // after a certain timeout has passed without receiving an ACK.
38 bool g_connect_backup_jobs_enabled = true; 40 bool g_connect_backup_jobs_enabled = true;
39 41
42 // Compares the effective priority of two results, and returns 1 if |request1|
43 // has greater effective priority than |request2|, 0 if they have the same
44 // effective priority, and -1 if |request2| has the greater effective priority.
45 // Requests with |ignore_limits| set have higher effective pririoty than those
eroman 2013/06/10 17:48:00 typo priority
mmenke 2013/06/10 18:17:26 Done.
46 // without. If both requests have |ignore_limits| set/unset, then the request
47 // with the highest Pririoty has the highest effective priority. Does not take
48 // into account the fact that Requests are serviced in FIFO order if they would
49 // otherwise have the same priority.
50 int CompareEffectiveRequestPriority(
51 const internal::ClientSocketPoolBaseHelper::Request& request1,
52 const internal::ClientSocketPoolBaseHelper::Request& request2) {
53 if (request1.ignore_limits() && !request2.ignore_limits())
54 return 1;
55 if (!request1.ignore_limits() && request2.ignore_limits())
56 return -1;
57 if (request1.priority() > request2.priority())
58 return 1;
59 if (request1.priority() < request2.priority())
60 return -1;
61 return 0;
62 }
63
40 } // namespace 64 } // namespace
41 65
42 namespace net {
43
44 ConnectJob::ConnectJob(const std::string& group_name, 66 ConnectJob::ConnectJob(const std::string& group_name,
45 base::TimeDelta timeout_duration, 67 base::TimeDelta timeout_duration,
46 Delegate* delegate, 68 Delegate* delegate,
47 const BoundNetLog& net_log) 69 const BoundNetLog& net_log)
48 : group_name_(group_name), 70 : group_name_(group_name),
49 timeout_duration_(timeout_duration), 71 timeout_duration_(timeout_duration),
50 delegate_(delegate), 72 delegate_(delegate),
51 net_log_(net_log), 73 net_log_(net_log),
52 idle_(true) { 74 idle_(true) {
53 DCHECK(!group_name.empty()); 75 DCHECK(!group_name.empty());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 202 }
181 203
182 ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair( 204 ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair(
183 const CompletionCallback& callback_in, int result_in) 205 const CompletionCallback& callback_in, int result_in)
184 : callback(callback_in), 206 : callback(callback_in),
185 result(result_in) { 207 result(result_in) {
186 } 208 }
187 209
188 ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {} 210 ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {}
189 211
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 212 // static
195 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue( 213 void ClientSocketPoolBaseHelper::InsertRequestIntoQueue(
196 const Request* r, RequestQueue* pending_requests) { 214 const Request* r, RequestQueue* pending_requests) {
197 RequestQueue::iterator it = pending_requests->begin(); 215 RequestQueue::iterator it = pending_requests->begin();
198 while (it != pending_requests->end() && r->priority() <= (*it)->priority()) 216 // TODO(mmenke): Should the network stack require requests with
217 // |ignore_limits| have the highest priority?
218 while (it != pending_requests->end() &&
219 CompareEffectiveRequestPriority(*r, *(*it)) <= 0) {
eroman 2013/06/10 17:48:00 Given that the result is only compared <=0, would
mmenke 2013/06/10 18:17:26 I could, but to maintain FIFO order, I'd have to e
eroman 2013/06/10 18:31:49 I guess you could do something like !LessThan(b,
199 ++it; 220 ++it;
221 }
200 pending_requests->insert(it, r); 222 pending_requests->insert(it, r);
201 } 223 }
202 224
203 // static 225 // static
204 const ClientSocketPoolBaseHelper::Request* 226 const ClientSocketPoolBaseHelper::Request*
205 ClientSocketPoolBaseHelper::RemoveRequestFromQueue( 227 ClientSocketPoolBaseHelper::RemoveRequestFromQueue(
206 const RequestQueue::iterator& it, Group* group) { 228 const RequestQueue::iterator& it, Group* group) {
207 const Request* req = *it; 229 const Request* req = *it;
208 group->mutable_pending_requests()->erase(it); 230 group->mutable_pending_requests()->erase(it);
209 // If there are no more requests, we kill the backup timer. 231 // 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); 509 Group* group = GetOrCreateGroup(group_name);
488 510
489 // Search pending_requests for matching handle. 511 // Search pending_requests for matching handle.
490 RequestQueue::iterator it = group->mutable_pending_requests()->begin(); 512 RequestQueue::iterator it = group->mutable_pending_requests()->begin();
491 for (; it != group->pending_requests().end(); ++it) { 513 for (; it != group->pending_requests().end(); ++it) {
492 if ((*it)->handle() == handle) { 514 if ((*it)->handle() == handle) {
493 scoped_ptr<const Request> req(RemoveRequestFromQueue(it, group)); 515 scoped_ptr<const Request> req(RemoveRequestFromQueue(it, group));
494 req->net_log().AddEvent(NetLog::TYPE_CANCELLED); 516 req->net_log().AddEvent(NetLog::TYPE_CANCELLED);
495 req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL); 517 req->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
496 518
497 // We let the job run, unless we're at the socket limit. 519 // We let the job run, unless we're at the socket limit and there is
498 if (group->jobs().size() && ReachedMaxSocketsLimit()) { 520 // not another request waiting on the job.
521 if (group->jobs().size() > group->pending_requests().size() &&
522 ReachedMaxSocketsLimit()) {
499 RemoveConnectJob(*group->jobs().begin(), group); 523 RemoveConnectJob(*group->jobs().begin(), group);
500 CheckForStalledSocketGroups(); 524 CheckForStalledSocketGroups();
501 } 525 }
502 break; 526 break;
503 } 527 }
504 } 528 }
505 } 529 }
506 530
507 bool ClientSocketPoolBaseHelper::HasGroup(const std::string& group_name) const { 531 bool ClientSocketPoolBaseHelper::HasGroup(const std::string& group_name) const {
508 return ContainsKey(group_map_, group_name); 532 return ContainsKey(group_map_, group_name);
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 STLDeleteElements(&jobs_); 1242 STLDeleteElements(&jobs_);
1219 unassigned_job_count_ = 0; 1243 unassigned_job_count_ = 0;
1220 1244
1221 // Cancel pending backup job. 1245 // Cancel pending backup job.
1222 weak_factory_.InvalidateWeakPtrs(); 1246 weak_factory_.InvalidateWeakPtrs();
1223 } 1247 }
1224 1248
1225 } // namespace internal 1249 } // namespace internal
1226 1250
1227 } // namespace net 1251 } // namespace net
OLDNEW
« 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