Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: net/dns/dns_socket_pool.h

Issue 11573012: patch from issue 10878090 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/dns/dns_session_unittest.cc ('k') | net/dns/dns_socket_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_socket_pool.h
diff --git a/net/dns/dns_socket_pool.h b/net/dns/dns_socket_pool.h
new file mode 100644
index 0000000000000000000000000000000000000000..54a2edb6f8df1864475e5d3ff05b7acd56e36a71
--- /dev/null
+++ b/net/dns/dns_socket_pool.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2012 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_DNS_DNS_SOCKET_POOL_H_
+#define NET_DNS_DNS_SOCKET_POOL_H_
+
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+class ClientSocketFactory;
+class DatagramClientSocket;
+class IPEndPoint;
+class NetLog;
+
+// A DnsSocketPool is an abstraction layer around a ClientSocketFactory that
+// allows preallocation, reuse, or other strategies to manage sockets connected
+// to DNS servers.
+class NET_EXPORT_PRIVATE DnsSocketPool {
+ public:
+ virtual ~DnsSocketPool() { }
+
+ // Creates a DnsSocketPool that implements the default strategy for managing
+ // sockets. (This varies by platform; see DnsSocketPoolImpl in
+ // dns_socket_pool.cc for details.)
+ static scoped_ptr<DnsSocketPool> CreateDefault(
+ ClientSocketFactory* factory);
+
+ // Creates a DnsSocketPool that implements a "null" strategy -- no sockets are
+ // preallocated, allocation requests are satisfied by calling the factory
+ // directly, and returned sockets are deleted immediately.
+ static scoped_ptr<DnsSocketPool> CreateNull(
+ ClientSocketFactory* factory);
+
+ // Initializes the DnsSocketPool. |nameservers| is the list of nameservers
+ // for which the DnsSocketPool will manage sockets; |net_log| is the NetLog
+ // used when constructing sockets with the factory.
+ //
+ // Initialize may not be called more than once, and must be called before
+ // calling AllocateSocket or FreeSocket.
+ virtual void Initialize(
+ const std::vector<IPEndPoint>* nameservers,
+ NetLog* net_log) = 0;
+
+ // Allocates a socket that is already connected to the nameserver referenced
+ // by |server_index|. May return a scoped_ptr to NULL if no sockets are
+ // available to reuse and the factory fails to produce a socket (or produces
+ // one on which Connect fails).
+ virtual scoped_ptr<DatagramClientSocket> AllocateSocket(
+ unsigned server_index) = 0;
+
+ // Frees a socket allocated by AllocateSocket. |server_index| must be the
+ // same index passed to AllocateSocket.
+ virtual void FreeSocket(
+ unsigned server_index,
+ scoped_ptr<DatagramClientSocket> socket) = 0;
+
+ protected:
+ DnsSocketPool(ClientSocketFactory* socket_factory);
+
+ void InitializeInternal(
+ const std::vector<IPEndPoint>* nameservers,
+ NetLog* net_log);
+
+ scoped_ptr<DatagramClientSocket> CreateConnectedSocket(
+ unsigned server_index);
+
+ private:
+ ClientSocketFactory* socket_factory_;
+ NetLog* net_log_;
+ const std::vector<IPEndPoint>* nameservers_;
+ bool initialized_;
+
+ DISALLOW_COPY_AND_ASSIGN(DnsSocketPool);
+};
+
+} // namespace net
+
+#endif // NET_DNS_DNS_SOCKET_POOL_H_
« no previous file with comments | « net/dns/dns_session_unittest.cc ('k') | net/dns/dns_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698