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

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

Issue 8526006: Close idle sockets next time we are about to send data. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: code conventions Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 27 matching lines...) Expand all
38 #include "net/base/address_list.h" 38 #include "net/base/address_list.h"
39 #include "net/base/completion_callback.h" 39 #include "net/base/completion_callback.h"
40 #include "net/base/load_states.h" 40 #include "net/base/load_states.h"
41 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
42 #include "net/base/net_export.h" 42 #include "net/base/net_export.h"
43 #include "net/base/net_log.h" 43 #include "net/base/net_log.h"
44 #include "net/base/network_change_notifier.h" 44 #include "net/base/network_change_notifier.h"
45 #include "net/base/request_priority.h" 45 #include "net/base/request_priority.h"
46 #include "net/socket/client_socket_pool.h" 46 #include "net/socket/client_socket_pool.h"
47 #include "net/socket/stream_socket.h" 47 #include "net/socket/stream_socket.h"
48 #include "net/socket/client_socket_pool_options.h"
48 49
49 namespace net { 50 namespace net {
50 51
51 class ClientSocketHandle; 52 class ClientSocketHandle;
52 53
53 // Returns the client socket reuse policy. 54 // Returns the client socket reuse policy.
54 NET_EXPORT_PRIVATE int GetSocketReusePolicy(); 55 NET_EXPORT_PRIVATE int GetSocketReusePolicy();
55 56
56 // Sets the client socket reuse policy. 57 // Sets the client socket reuse policy.
57 // NOTE: 'policy' should be a valid ClientSocketReusePolicy enum value. 58 // NOTE: 'policy' should be a valid ClientSocketReusePolicy enum value.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 229
229 private: 230 private:
230 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); 231 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory);
231 }; 232 };
232 233
233 ClientSocketPoolBaseHelper( 234 ClientSocketPoolBaseHelper(
234 int max_sockets, 235 int max_sockets,
235 int max_sockets_per_group, 236 int max_sockets_per_group,
236 base::TimeDelta unused_idle_socket_timeout, 237 base::TimeDelta unused_idle_socket_timeout,
237 base::TimeDelta used_idle_socket_timeout, 238 base::TimeDelta used_idle_socket_timeout,
238 ConnectJobFactory* connect_job_factory); 239 ConnectJobFactory* connect_job_factory,
240 const ClientSocketPoolOptions& options);
239 241
240 virtual ~ClientSocketPoolBaseHelper(); 242 virtual ~ClientSocketPoolBaseHelper();
241 243
242 // See ClientSocketPool::RequestSocket for documentation on this function. 244 // See ClientSocketPool::RequestSocket for documentation on this function.
243 // ClientSocketPoolBaseHelper takes ownership of |request|, which must be 245 // ClientSocketPoolBaseHelper takes ownership of |request|, which must be
244 // heap allocated. 246 // heap allocated.
245 int RequestSocket(const std::string& group_name, const Request* request); 247 int RequestSocket(const std::string& group_name, const Request* request);
246 248
247 // See ClientSocketPool::RequestSocket for documentation on this function. 249 // See ClientSocketPool::RequestSocket for documentation on this function.
248 void RequestSockets(const std::string& group_name, 250 void RequestSockets(const std::string& group_name,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 Group* group); 437 Group* group);
436 438
437 Group* GetOrCreateGroup(const std::string& group_name); 439 Group* GetOrCreateGroup(const std::string& group_name);
438 void RemoveGroup(const std::string& group_name); 440 void RemoveGroup(const std::string& group_name);
439 void RemoveGroup(GroupMap::iterator it); 441 void RemoveGroup(GroupMap::iterator it);
440 442
441 // Called when the number of idle sockets changes. 443 // Called when the number of idle sockets changes.
442 void IncrementIdleCount(); 444 void IncrementIdleCount();
443 void DecrementIdleCount(); 445 void DecrementIdleCount();
444 446
447 // Start cleanup timer for idle sockets.
448 void StartIdleSocketTimer();
449
445 // Scans the group map for groups which have an available socket slot and 450 // Scans the group map for groups which have an available socket slot and
446 // at least one pending request. Returns true if any groups are stalled, and 451 // at least one pending request. Returns true if any groups are stalled, and
447 // if so, fills |group| and |group_name| with data of the stalled group 452 // if so, fills |group| and |group_name| with data of the stalled group
448 // having highest priority. 453 // having highest priority.
449 bool FindTopStalledGroup(Group** group, std::string* group_name); 454 bool FindTopStalledGroup(Group** group, std::string* group_name);
450 455
451 // Called when timer_ fires. This method scans the idle sockets removing 456 // Called when timer_ fires. This method scans the idle sockets removing
452 // sockets that timed out or can't be reused. 457 // sockets that timed out or can't be reused.
453 void OnCleanupTimerFired() { 458 void OnCleanupTimerFired() {
454 CleanupIdleSockets(false); 459 CleanupIdleSockets(false);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 550
546 // Number of connected sockets we handed out across all groups. 551 // Number of connected sockets we handed out across all groups.
547 int handed_out_socket_count_; 552 int handed_out_socket_count_;
548 553
549 // The maximum total number of sockets. See ReachedMaxSocketsLimit. 554 // The maximum total number of sockets. See ReachedMaxSocketsLimit.
550 const int max_sockets_; 555 const int max_sockets_;
551 556
552 // The maximum number of sockets kept per group. 557 // The maximum number of sockets kept per group.
553 const int max_sockets_per_group_; 558 const int max_sockets_per_group_;
554 559
560 // Whether to use timer to cleanup idle sockets.
561 bool use_cleanup_timer_;
562
555 // The time to wait until closing idle sockets. 563 // The time to wait until closing idle sockets.
556 const base::TimeDelta unused_idle_socket_timeout_; 564 const base::TimeDelta unused_idle_socket_timeout_;
557 const base::TimeDelta used_idle_socket_timeout_; 565 const base::TimeDelta used_idle_socket_timeout_;
558 566
559 const scoped_ptr<ConnectJobFactory> connect_job_factory_; 567 const scoped_ptr<ConnectJobFactory> connect_job_factory_;
560 568
561 // TODO(vandebo) Remove when backup jobs move to TransportClientSocketPool 569 // TODO(vandebo) Remove when backup jobs move to TransportClientSocketPool
562 bool connect_backup_jobs_enabled_; 570 bool connect_backup_jobs_enabled_;
563 571
564 // A unique id for the pool. It gets incremented every time we Flush() the 572 // A unique id for the pool. It gets incremented every time we Flush() the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how 624 // sockets a "group" can have. |unused_idle_socket_timeout| specifies how
617 // long to leave an unused idle socket open before closing it. 625 // long to leave an unused idle socket open before closing it.
618 // |used_idle_socket_timeout| specifies how long to leave a previously used 626 // |used_idle_socket_timeout| specifies how long to leave a previously used
619 // idle socket open before closing it. 627 // idle socket open before closing it.
620 ClientSocketPoolBase( 628 ClientSocketPoolBase(
621 int max_sockets, 629 int max_sockets,
622 int max_sockets_per_group, 630 int max_sockets_per_group,
623 ClientSocketPoolHistograms* histograms, 631 ClientSocketPoolHistograms* histograms,
624 base::TimeDelta unused_idle_socket_timeout, 632 base::TimeDelta unused_idle_socket_timeout,
625 base::TimeDelta used_idle_socket_timeout, 633 base::TimeDelta used_idle_socket_timeout,
626 ConnectJobFactory* connect_job_factory) 634 ConnectJobFactory* connect_job_factory,
635 const ClientSocketPoolOptions& options = ClientSocketPoolOptions())
627 : histograms_(histograms), 636 : histograms_(histograms),
628 helper_(max_sockets, max_sockets_per_group, 637 helper_(max_sockets, max_sockets_per_group,
629 unused_idle_socket_timeout, used_idle_socket_timeout, 638 unused_idle_socket_timeout, used_idle_socket_timeout,
630 new ConnectJobFactoryAdaptor(connect_job_factory)) {} 639 new ConnectJobFactoryAdaptor(connect_job_factory),
640 options) {}
631 641
632 virtual ~ClientSocketPoolBase() {} 642 virtual ~ClientSocketPoolBase() {}
633 643
634 // These member functions simply forward to ClientSocketPoolBaseHelper. 644 // These member functions simply forward to ClientSocketPoolBaseHelper.
635 645
636 // RequestSocket bundles up the parameters into a Request and then forwards to 646 // RequestSocket bundles up the parameters into a Request and then forwards to
637 // ClientSocketPoolBaseHelper::RequestSocket(). 647 // ClientSocketPoolBaseHelper::RequestSocket().
638 int RequestSocket(const std::string& group_name, 648 int RequestSocket(const std::string& group_name,
639 const scoped_refptr<SocketParams>& params, 649 const scoped_refptr<SocketParams>& params,
640 RequestPriority priority, 650 RequestPriority priority,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 // Histograms for the pool 771 // Histograms for the pool
762 ClientSocketPoolHistograms* const histograms_; 772 ClientSocketPoolHistograms* const histograms_;
763 internal::ClientSocketPoolBaseHelper helper_; 773 internal::ClientSocketPoolBaseHelper helper_;
764 774
765 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); 775 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase);
766 }; 776 };
767 777
768 } // namespace net 778 } // namespace net
769 779
770 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ 780 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698