diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-22 23:26:44 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-22 23:26:44 +0000 |
commit | f7984fc67f3c88b6ff1c738700a8229f387d732d (patch) | |
tree | 094f6be7633d60b0413370462bf6bd04b906ac00 /net/socket/client_socket_pool.h | |
parent | 8c1be4e0311d52f07fe16fc091862957757dc002 (diff) | |
download | chromium_src-f7984fc67f3c88b6ff1c738700a8229f387d732d.zip chromium_src-f7984fc67f3c88b6ff1c738700a8229f387d732d.tar.gz chromium_src-f7984fc67f3c88b6ff1c738700a8229f387d732d.tar.bz2 |
Move socket related files from net/base to net/socket.
Review URL: http://codereview.chromium.org/144009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18985 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/client_socket_pool.h')
-rw-r--r-- | net/socket/client_socket_pool.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/net/socket/client_socket_pool.h b/net/socket/client_socket_pool.h new file mode 100644 index 0000000..b3a7bba --- /dev/null +++ b/net/socket/client_socket_pool.h @@ -0,0 +1,97 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_SOCKET_CLIENT_SOCKET_POOL_H_ +#define NET_SOCKET_CLIENT_SOCKET_POOL_H_ + +#include <deque> +#include <map> +#include <string> + +#include "base/ref_counted.h" +#include "net/base/completion_callback.h" +#include "net/base/host_resolver.h" +#include "net/base/load_states.h" + +namespace net { + +class ClientSocket; +class ClientSocketHandle; + +// A ClientSocketPool is used to restrict the number of sockets open at a time. +// It also maintains a list of idle persistent sockets. +// +class ClientSocketPool : public base::RefCounted<ClientSocketPool> { + public: + // Requests a connected socket for a group_name. + // + // There are four possible results from calling this function: + // 1) RequestSocket returns OK and initializes |handle| with a reused socket. + // 2) RequestSocket returns OK with a newly connected socket. + // 3) RequestSocket returns ERR_IO_PENDING. The handle will be added to a + // wait list until a socket is available to reuse or a new socket finishes + // connecting. |priority| will determine the placement into the wait list. + // 4) An error occurred early on, so RequestSocket returns an error code. + // + // If this function returns OK, then |handle| is initialized upon return. + // The |handle|'s is_initialized method will return true in this case. If a + // ClientSocket was reused, then ClientSocketPool will call + // |handle|->set_reused(true). In either case, the socket will have been + // allocated and will be connected. A client might want to know whether or + // not the socket is reused in order to know whether or not he needs to + // perform SSL connection or tunnel setup or to request a new socket if he + // encounters an error with the reused socket. + // + // If ERR_IO_PENDING is returned, then the callback will be used to notify the + // client of completion. + // + virtual int RequestSocket(const std::string& group_name, + const HostResolver::RequestInfo& resolve_info, + int priority, + ClientSocketHandle* handle, + CompletionCallback* callback) = 0; + + // Called to cancel a RequestSocket call that returned ERR_IO_PENDING. The + // same handle parameter must be passed to this method as was passed to the + // RequestSocket call being cancelled. The associated CompletionCallback is + // not run. + virtual void CancelRequest(const std::string& group_name, + const ClientSocketHandle* handle) = 0; + + // Called to release a socket once the socket is no longer needed. If the + // socket still has an established connection, then it will be added to the + // set of idle sockets to be used to satisfy future RequestSocket calls. + // Otherwise, the ClientSocket is destroyed. + virtual void ReleaseSocket(const std::string& group_name, + ClientSocket* socket) = 0; + + // Called to close any idle connections held by the connection manager. + virtual void CloseIdleSockets() = 0; + + // Returns the HostResolver that will be used for host lookups. + virtual HostResolver* GetHostResolver() const = 0; + + // The total number of idle sockets in the pool. + virtual int IdleSocketCount() const = 0; + + // The total number of idle sockets in a connection group. + virtual int IdleSocketCountInGroup(const std::string& group_name) const = 0; + + // Determine the LoadState of a connecting ClientSocketHandle. + virtual LoadState GetLoadState(const std::string& group_name, + const ClientSocketHandle* handle) const = 0; + + protected: + ClientSocketPool() {} + virtual ~ClientSocketPool() {} + + private: + friend class base::RefCounted<ClientSocketPool>; + + DISALLOW_COPY_AND_ASSIGN(ClientSocketPool); +}; + +} // namespace net + +#endif // NET_SOCKET_CLIENT_SOCKET_POOL_H_ |