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_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_BASE_CLIENT_SOCKET_POOL_H_ |
6 #define NET_BASE_CLIENT_SOCKET_POOL_H_ | 6 #define NET_BASE_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/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 14 #include "net/base/host_resolver.h" |
14 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 | 18 |
18 class ClientSocket; | 19 class ClientSocket; |
19 class ClientSocketHandle; | 20 class ClientSocketHandle; |
20 class HostResolver; | |
21 | 21 |
22 // A ClientSocketPool is used to restrict the number of sockets open at a time. | 22 // A ClientSocketPool is used to restrict the number of sockets open at a time. |
23 // It also maintains a list of idle persistent sockets. | 23 // It also maintains a list of idle persistent sockets. |
24 // | 24 // |
25 class ClientSocketPool : public base::RefCounted<ClientSocketPool> { | 25 class ClientSocketPool : public base::RefCounted<ClientSocketPool> { |
26 public: | 26 public: |
27 // Requests a connected socket for a group_name. | 27 // Requests a connected socket for a group_name. |
28 // | 28 // |
29 // There are four possible results from calling this function: | 29 // There are four possible results from calling this function: |
30 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. | 30 // 1) RequestSocket returns OK and initializes |handle| with a reused socket. |
31 // 2) RequestSocket returns OK with a newly connected socket. | 31 // 2) RequestSocket returns OK with a newly connected socket. |
32 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a | 32 // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a |
33 // wait list until a socket is available to reuse or a new socket finishes | 33 // wait list until a socket is available to reuse or a new socket finishes |
34 // connecting. |priority| will determine the placement into the wait list. | 34 // connecting. |priority| will determine the placement into the wait list. |
35 // 4) An error occurred early on, so RequestSocket returns an error code. | 35 // 4) An error occurred early on, so RequestSocket returns an error code. |
36 // | 36 // |
37 // If this function returns OK, then |handle| is initialized upon return. | 37 // If this function returns OK, then |handle| is initialized upon return. |
38 // The |handle|'s is_initialized method will return true in this case. If a | 38 // The |handle|'s is_initialized method will return true in this case. If a |
39 // ClientSocket was reused, then ClientSocketPool will call | 39 // ClientSocket was reused, then ClientSocketPool will call |
40 // |handle|->set_reused(true). In either case, the socket will have been | 40 // |handle|->set_reused(true). In either case, the socket will have been |
41 // allocated and will be connected. A client might want to know whether or | 41 // allocated and will be connected. A client might want to know whether or |
42 // not the socket is reused in order to know whether or not he needs to | 42 // not the socket is reused in order to know whether or not he needs to |
43 // perform SSL connection or tunnel setup or to request a new socket if he | 43 // perform SSL connection or tunnel setup or to request a new socket if he |
44 // encounters an error with the reused socket. | 44 // encounters an error with the reused socket. |
45 // | 45 // |
46 // If ERR_IO_PENDING is returned, then the callback will be used to notify the | 46 // If ERR_IO_PENDING is returned, then the callback will be used to notify the |
47 // client of completion. | 47 // client of completion. |
48 // | 48 // |
49 virtual int RequestSocket(const std::string& group_name, | 49 virtual int RequestSocket(const std::string& group_name, |
50 const std::string& host, | 50 const HostResolver::RequestInfo& resolve_info, |
51 int port, | |
52 int priority, | 51 int priority, |
53 ClientSocketHandle* handle, | 52 ClientSocketHandle* handle, |
54 CompletionCallback* callback) = 0; | 53 CompletionCallback* callback) = 0; |
55 | 54 |
56 // Called to cancel a RequestSocket call that returned ERR_IO_PENDING. The | 55 // Called to cancel a RequestSocket call that returned ERR_IO_PENDING. The |
57 // same handle parameter must be passed to this method as was passed to the | 56 // same handle parameter must be passed to this method as was passed to the |
58 // RequestSocket call being cancelled. The associated CompletionCallback is | 57 // RequestSocket call being cancelled. The associated CompletionCallback is |
59 // not run. | 58 // not run. |
60 virtual void CancelRequest(const std::string& group_name, | 59 virtual void CancelRequest(const std::string& group_name, |
61 const ClientSocketHandle* handle) = 0; | 60 const ClientSocketHandle* handle) = 0; |
(...skipping 27 matching lines...) Expand all Loading... |
89 | 88 |
90 private: | 89 private: |
91 friend class base::RefCounted<ClientSocketPool>; | 90 friend class base::RefCounted<ClientSocketPool>; |
92 | 91 |
93 DISALLOW_COPY_AND_ASSIGN(ClientSocketPool); | 92 DISALLOW_COPY_AND_ASSIGN(ClientSocketPool); |
94 }; | 93 }; |
95 | 94 |
96 } // namespace net | 95 } // namespace net |
97 | 96 |
98 #endif // NET_BASE_CLIENT_SOCKET_POOL_H_ | 97 #endif // NET_BASE_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |