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.h

Issue 169643006: Use sockets with unread data if they've never been used before. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mmenke comments Created 6 years, 8 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 | « no previous file | net/socket/client_socket_pool_base.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 // A ClientSocketPoolBase is used to restrict the number of sockets open at 5 // A ClientSocketPoolBase is used to restrict the number of sockets open at
6 // a time. It also maintains a list of idle persistent sockets for reuse. 6 // a time. It also maintains a list of idle persistent sockets for reuse.
7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle
8 // the core logic of (1) restricting the number of active (connected or 8 // the core logic of (1) restricting the number of active (connected or
9 // connecting) sockets per "group" (generally speaking, the hostname), (2) 9 // connecting) sockets per "group" (generally speaking, the hostname), (2)
10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3)
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // NetworkChangeNotifier::IPAddressObserver methods: 332 // NetworkChangeNotifier::IPAddressObserver methods:
333 virtual void OnIPAddressChanged() OVERRIDE; 333 virtual void OnIPAddressChanged() OVERRIDE;
334 334
335 private: 335 private:
336 friend class base::RefCounted<ClientSocketPoolBaseHelper>; 336 friend class base::RefCounted<ClientSocketPoolBaseHelper>;
337 337
338 // Entry for a persistent socket which became idle at time |start_time|. 338 // Entry for a persistent socket which became idle at time |start_time|.
339 struct IdleSocket { 339 struct IdleSocket {
340 IdleSocket() : socket(NULL) {} 340 IdleSocket() : socket(NULL) {}
341 341
342 // An idle socket can't be used if it is disconnected or has been used
343 // before and has received data unexpectedly (hence no longer idle). The
344 // unread data would be mistaken for the beginning of the next response if
345 // we were to use the socket for a new request.
346 //
347 // Note that a socket that has never been used before (like a preconnected
348 // socket) may be used even with unread data. This may be, e.g., a SPDY
349 // SETTINGS frame.
350 bool IsUsable() const;
351
342 // An idle socket should be removed if it can't be reused, or has been idle 352 // An idle socket should be removed if it can't be reused, or has been idle
343 // for too long. |now| is the current time value (TimeTicks::Now()). 353 // for too long. |now| is the current time value (TimeTicks::Now()).
344 // |timeout| is the length of time to wait before timing out an idle socket. 354 // |timeout| is the length of time to wait before timing out an idle socket.
345 //
346 // An idle socket can't be reused if it is disconnected or has received
347 // data unexpectedly (hence no longer idle). The unread data would be
348 // mistaken for the beginning of the next response if we were to reuse the
349 // socket for a new request.
350 bool ShouldCleanup(base::TimeTicks now, base::TimeDelta timeout) const; 355 bool ShouldCleanup(base::TimeTicks now, base::TimeDelta timeout) const;
351 356
352 StreamSocket* socket; 357 StreamSocket* socket;
353 base::TimeTicks start_time; 358 base::TimeTicks start_time;
354 }; 359 };
355 360
356 typedef PriorityQueue<const Request*> RequestQueue; 361 typedef PriorityQueue<const Request*> RequestQueue;
357 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap; 362 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap;
358 363
359 // A Group is allocated per group_name when there are idle sockets or pending 364 // A Group is allocated per group_name when there are idle sockets or pending
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 // Histograms for the pool 872 // Histograms for the pool
868 ClientSocketPoolHistograms* const histograms_; 873 ClientSocketPoolHistograms* const histograms_;
869 internal::ClientSocketPoolBaseHelper helper_; 874 internal::ClientSocketPoolBaseHelper helper_;
870 875
871 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); 876 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase);
872 }; 877 };
873 878
874 } // namespace net 879 } // namespace net
875 880
876 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ 881 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_
OLDNEW
« no previous file with comments | « no previous file | net/socket/client_socket_pool_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698