| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
| 6 #define NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 6 #define NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/timer.h" | 13 #include "base/timer.h" |
| 14 #include "net/base/address_list.h" | 14 #include "net/base/address_list.h" |
| 15 #include "net/base/client_socket_pool.h" | 15 #include "net/base/client_socket_pool.h" |
| 16 #include "net/base/host_resolver.h" | 16 #include "net/base/host_resolver.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 class ClientSocketFactory; | 20 class ClientSocketFactory; |
| 21 | 21 |
| 22 // A TCPClientSocketPool is used to restrict the number of TCP sockets open at | 22 // A TCPClientSocketPool is used to restrict the number of TCP sockets open at |
| 23 // a time. It also maintains a list of idle persistent sockets. | 23 // a time. It also maintains a list of idle persistent sockets. |
| 24 // | 24 // |
| 25 class TCPClientSocketPool : public ClientSocketPool { | 25 class TCPClientSocketPool : public ClientSocketPool { |
| 26 public: | 26 public: |
| 27 TCPClientSocketPool(int max_sockets_per_group, | 27 TCPClientSocketPool(int max_sockets_per_group, |
| 28 HostResolver* host_resolver, |
| 28 ClientSocketFactory* client_socket_factory); | 29 ClientSocketFactory* client_socket_factory); |
| 29 | 30 |
| 30 // ClientSocketPool methods: | 31 // ClientSocketPool methods: |
| 31 | 32 |
| 32 virtual int RequestSocket(const std::string& group_name, | 33 virtual int RequestSocket(const std::string& group_name, |
| 33 const std::string& host, | 34 const std::string& host, |
| 34 int port, | 35 int port, |
| 35 int priority, | 36 int priority, |
| 36 ClientSocketHandle* handle, | 37 ClientSocketHandle* handle, |
| 37 CompletionCallback* callback); | 38 CompletionCallback* callback); |
| 38 | 39 |
| 39 virtual void CancelRequest(const std::string& group_name, | 40 virtual void CancelRequest(const std::string& group_name, |
| 40 const ClientSocketHandle* handle); | 41 const ClientSocketHandle* handle); |
| 41 | 42 |
| 42 virtual void ReleaseSocket(const std::string& group_name, | 43 virtual void ReleaseSocket(const std::string& group_name, |
| 43 ClientSocket* socket); | 44 ClientSocket* socket); |
| 44 | 45 |
| 45 virtual void CloseIdleSockets(); | 46 virtual void CloseIdleSockets(); |
| 46 | 47 |
| 48 virtual HostResolver* GetHostResolver() const { |
| 49 return host_resolver_; |
| 50 } |
| 51 |
| 47 virtual int idle_socket_count() const { | 52 virtual int idle_socket_count() const { |
| 48 return idle_socket_count_; | 53 return idle_socket_count_; |
| 49 } | 54 } |
| 50 | 55 |
| 51 virtual int IdleSocketCountInGroup(const std::string& group_name) const; | 56 virtual int IdleSocketCountInGroup(const std::string& group_name) const; |
| 52 | 57 |
| 53 virtual LoadState GetLoadState(const std::string& group_name, | 58 virtual LoadState GetLoadState(const std::string& group_name, |
| 54 const ClientSocketHandle* handle) const; | 59 const ClientSocketHandle* handle) const; |
| 55 | 60 |
| 56 private: | 61 private: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // asynchronously. OnIOCompleteInternal returns the result of the next IO | 135 // asynchronously. OnIOCompleteInternal returns the result of the next IO |
| 131 // operation that executes, or just the value of |result|. | 136 // operation that executes, or just the value of |result|. |
| 132 int OnIOCompleteInternal(int result, bool synchronous); | 137 int OnIOCompleteInternal(int result, bool synchronous); |
| 133 | 138 |
| 134 const std::string group_name_; | 139 const std::string group_name_; |
| 135 const ClientSocketHandle* const handle_; | 140 const ClientSocketHandle* const handle_; |
| 136 ClientSocketFactory* const client_socket_factory_; | 141 ClientSocketFactory* const client_socket_factory_; |
| 137 CompletionCallbackImpl<ConnectingSocket> callback_; | 142 CompletionCallbackImpl<ConnectingSocket> callback_; |
| 138 scoped_ptr<ClientSocket> socket_; | 143 scoped_ptr<ClientSocket> socket_; |
| 139 scoped_refptr<TCPClientSocketPool> pool_; | 144 scoped_refptr<TCPClientSocketPool> pool_; |
| 140 HostResolver resolver_; | 145 SingleRequestHostResolver resolver_; |
| 141 AddressList addresses_; | 146 AddressList addresses_; |
| 142 bool canceled_; | 147 bool canceled_; |
| 143 | 148 |
| 144 // The time the Connect() method was called (if it got called). | 149 // The time the Connect() method was called (if it got called). |
| 145 base::Time connect_start_time_; | 150 base::Time connect_start_time_; |
| 146 | 151 |
| 147 DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); | 152 DISALLOW_COPY_AND_ASSIGN(ConnectingSocket); |
| 148 }; | 153 }; |
| 149 | 154 |
| 150 virtual ~TCPClientSocketPool(); | 155 virtual ~TCPClientSocketPool(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 178 // Timer used to periodically prune idle sockets that timed out or can't be | 183 // Timer used to periodically prune idle sockets that timed out or can't be |
| 179 // reused. | 184 // reused. |
| 180 base::RepeatingTimer<TCPClientSocketPool> timer_; | 185 base::RepeatingTimer<TCPClientSocketPool> timer_; |
| 181 | 186 |
| 182 // The total number of idle sockets in the system. | 187 // The total number of idle sockets in the system. |
| 183 int idle_socket_count_; | 188 int idle_socket_count_; |
| 184 | 189 |
| 185 // The maximum number of sockets kept per group. | 190 // The maximum number of sockets kept per group. |
| 186 const int max_sockets_per_group_; | 191 const int max_sockets_per_group_; |
| 187 | 192 |
| 193 // The host resolver that will be used to do DNS lookups for connecting |
| 194 // sockets. |
| 195 HostResolver* host_resolver_; |
| 196 |
| 188 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); | 197 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); |
| 189 }; | 198 }; |
| 190 | 199 |
| 191 } // namespace net | 200 } // namespace net |
| 192 | 201 |
| 193 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 202 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |