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> |
(...skipping 13 matching lines...) Expand all Loading... |
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 HostResolver* host_resolver, |
29 ClientSocketFactory* client_socket_factory); | 29 ClientSocketFactory* client_socket_factory); |
30 | 30 |
31 // ClientSocketPool methods: | 31 // ClientSocketPool methods: |
32 | 32 |
33 virtual int RequestSocket(const std::string& group_name, | 33 virtual int RequestSocket(const std::string& group_name, |
34 const std::string& host, | 34 const HostResolver::RequestInfo& resolve_info, |
35 int port, | |
36 int priority, | 35 int priority, |
37 ClientSocketHandle* handle, | 36 ClientSocketHandle* handle, |
38 CompletionCallback* callback); | 37 CompletionCallback* callback); |
39 | 38 |
40 virtual void CancelRequest(const std::string& group_name, | 39 virtual void CancelRequest(const std::string& group_name, |
41 const ClientSocketHandle* handle); | 40 const ClientSocketHandle* handle); |
42 | 41 |
43 virtual void ReleaseSocket(const std::string& group_name, | 42 virtual void ReleaseSocket(const std::string& group_name, |
44 ClientSocket* socket); | 43 ClientSocket* socket); |
45 | 44 |
46 virtual void CloseIdleSockets(); | 45 virtual void CloseIdleSockets(); |
47 | 46 |
48 virtual HostResolver* GetHostResolver() const { | 47 virtual HostResolver* GetHostResolver() const { |
49 return host_resolver_; | 48 return host_resolver_; |
50 } | 49 } |
51 | 50 |
52 virtual int idle_socket_count() const { | 51 virtual int idle_socket_count() const { |
53 return idle_socket_count_; | 52 return idle_socket_count_; |
54 } | 53 } |
55 | 54 |
56 virtual int IdleSocketCountInGroup(const std::string& group_name) const; | 55 virtual int IdleSocketCountInGroup(const std::string& group_name) const; |
57 | 56 |
58 virtual LoadState GetLoadState(const std::string& group_name, | 57 virtual LoadState GetLoadState(const std::string& group_name, |
59 const ClientSocketHandle* handle) const; | 58 const ClientSocketHandle* handle) const; |
60 | 59 |
61 private: | 60 private: |
62 // A Request is allocated per call to RequestSocket that results in | 61 // A Request is allocated per call to RequestSocket that results in |
63 // ERR_IO_PENDING. | 62 // ERR_IO_PENDING. |
64 struct Request { | 63 struct Request { |
| 64 // HostResolver::RequestInfo has no default constructor, so fudge something. |
| 65 Request() : resolve_info(std::string(), 0) {} |
| 66 |
| 67 Request(ClientSocketHandle* handle, |
| 68 CompletionCallback* callback, |
| 69 int priority, |
| 70 const HostResolver::RequestInfo& resolve_info, |
| 71 LoadState load_state) |
| 72 : handle(handle), callback(callback), priority(priority), |
| 73 resolve_info(resolve_info), load_state(load_state) { |
| 74 } |
| 75 |
65 ClientSocketHandle* handle; | 76 ClientSocketHandle* handle; |
66 CompletionCallback* callback; | 77 CompletionCallback* callback; |
67 int priority; | 78 int priority; |
68 std::string host; | 79 HostResolver::RequestInfo resolve_info; |
69 int port; | |
70 LoadState load_state; | 80 LoadState load_state; |
71 }; | 81 }; |
72 | 82 |
73 // Entry for a persistent socket which became idle at time |start_time|. | 83 // Entry for a persistent socket which became idle at time |start_time|. |
74 struct IdleSocket { | 84 struct IdleSocket { |
75 ClientSocket* socket; | 85 ClientSocket* socket; |
76 base::TimeTicks start_time; | 86 base::TimeTicks start_time; |
77 | 87 |
78 // An idle socket should be removed if it can't be reused, or has been idle | 88 // An idle socket should be removed if it can't be reused, or has been idle |
79 // for too long. |now| is the current time value (TimeTicks::Now()). | 89 // for too long. |now| is the current time value (TimeTicks::Now()). |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 121 |
112 ConnectingSocket(const std::string& group_name, | 122 ConnectingSocket(const std::string& group_name, |
113 const ClientSocketHandle* handle, | 123 const ClientSocketHandle* handle, |
114 ClientSocketFactory* client_socket_factory, | 124 ClientSocketFactory* client_socket_factory, |
115 TCPClientSocketPool* pool); | 125 TCPClientSocketPool* pool); |
116 ~ConnectingSocket(); | 126 ~ConnectingSocket(); |
117 | 127 |
118 // Begins the host resolution and the TCP connect. Returns OK on success | 128 // Begins the host resolution and the TCP connect. Returns OK on success |
119 // and ERR_IO_PENDING if it cannot immediately service the request. | 129 // and ERR_IO_PENDING if it cannot immediately service the request. |
120 // Otherwise, it returns a net error code. | 130 // Otherwise, it returns a net error code. |
121 int Connect(const std::string& host, int port); | 131 int Connect(const HostResolver::RequestInfo& resolve_info); |
122 | 132 |
123 // Called by the TCPClientSocketPool to cancel this ConnectingSocket. Only | 133 // Called by the TCPClientSocketPool to cancel this ConnectingSocket. Only |
124 // necessary if a ClientSocketHandle is reused. | 134 // necessary if a ClientSocketHandle is reused. |
125 void Cancel(); | 135 void Cancel(); |
126 | 136 |
127 private: | 137 private: |
128 // Handles asynchronous completion of IO. |result| represents the result of | 138 // Handles asynchronous completion of IO. |result| represents the result of |
129 // the IO operation. | 139 // the IO operation. |
130 void OnIOComplete(int result); | 140 void OnIOComplete(int result); |
131 | 141 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // The host resolver that will be used to do DNS lookups for connecting | 203 // The host resolver that will be used to do DNS lookups for connecting |
194 // sockets. | 204 // sockets. |
195 HostResolver* host_resolver_; | 205 HostResolver* host_resolver_; |
196 | 206 |
197 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); | 207 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketPool); |
198 }; | 208 }; |
199 | 209 |
200 } // namespace net | 210 } // namespace net |
201 | 211 |
202 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ | 212 #endif // NET_BASE_TCP_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |