| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_CLIENT_SOCKET_POOL_H_ | |
| 6 #define NET_BASE_CLIENT_SOCKET_POOL_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/ref_counted.h" | |
| 13 #include "net/base/completion_callback.h" | |
| 14 #include "net/base/host_resolver.h" | |
| 15 #include "net/base/load_states.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 class ClientSocket; | |
| 20 class ClientSocketHandle; | |
| 21 | |
| 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. | |
| 24 // | |
| 25 class ClientSocketPool : public base::RefCounted<ClientSocketPool> { | |
| 26 public: | |
| 27 // Requests a connected socket for a group_name. | |
| 28 // | |
| 29 // There are four possible results from calling this function: | |
| 30 // 1) RequestSocket returns OK and initializes |handle| with a reused 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 | |
| 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. | |
| 35 // 4) An error occurred early on, so RequestSocket returns an error code. | |
| 36 // | |
| 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 | |
| 39 // ClientSocket was reused, then ClientSocketPool will call | |
| 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 | |
| 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 | |
| 44 // encounters an error with the reused socket. | |
| 45 // | |
| 46 // If ERR_IO_PENDING is returned, then the callback will be used to notify the | |
| 47 // client of completion. | |
| 48 // | |
| 49 virtual int RequestSocket(const std::string& group_name, | |
| 50 const HostResolver::RequestInfo& resolve_info, | |
| 51 int priority, | |
| 52 ClientSocketHandle* handle, | |
| 53 CompletionCallback* callback) = 0; | |
| 54 | |
| 55 // Called to cancel a RequestSocket call that returned ERR_IO_PENDING. The | |
| 56 // same handle parameter must be passed to this method as was passed to the | |
| 57 // RequestSocket call being cancelled. The associated CompletionCallback is | |
| 58 // not run. | |
| 59 virtual void CancelRequest(const std::string& group_name, | |
| 60 const ClientSocketHandle* handle) = 0; | |
| 61 | |
| 62 // Called to release a socket once the socket is no longer needed. If the | |
| 63 // socket still has an established connection, then it will be added to the | |
| 64 // set of idle sockets to be used to satisfy future RequestSocket calls. | |
| 65 // Otherwise, the ClientSocket is destroyed. | |
| 66 virtual void ReleaseSocket(const std::string& group_name, | |
| 67 ClientSocket* socket) = 0; | |
| 68 | |
| 69 // Called to close any idle connections held by the connection manager. | |
| 70 virtual void CloseIdleSockets() = 0; | |
| 71 | |
| 72 // Returns the HostResolver that will be used for host lookups. | |
| 73 virtual HostResolver* GetHostResolver() const = 0; | |
| 74 | |
| 75 // The total number of idle sockets in the pool. | |
| 76 virtual int IdleSocketCount() const = 0; | |
| 77 | |
| 78 // The total number of idle sockets in a connection group. | |
| 79 virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; | |
| 80 | |
| 81 // Determine the LoadState of a connecting ClientSocketHandle. | |
| 82 virtual LoadState GetLoadState(const std::string& group_name, | |
| 83 const ClientSocketHandle* handle) const = 0; | |
| 84 | |
| 85 protected: | |
| 86 ClientSocketPool() {} | |
| 87 virtual ~ClientSocketPool() {} | |
| 88 | |
| 89 private: | |
| 90 friend class base::RefCounted<ClientSocketPool>; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(ClientSocketPool); | |
| 93 }; | |
| 94 | |
| 95 } // namespace net | |
| 96 | |
| 97 #endif // NET_BASE_CLIENT_SOCKET_POOL_H_ | |
| OLD | NEW |