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

Side by Side Diff: net/dns/dns_session.h

Issue 10878090: Keep pool of pre-connected DNS sockets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use a single, separate DnsSocketPool object Created 8 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_DNS_DNS_SESSION_H_ 5 #ifndef NET_DNS_DNS_SESSION_H_
6 #define NET_DNS_DNS_SESSION_H_ 6 #define NET_DNS_DNS_SESSION_H_
7 7
8 #include <vector>
9
8 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
9 #include "base/time.h" 12 #include "base/time.h"
10 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
11 #include "net/base/rand_callback.h" 14 #include "net/base/rand_callback.h"
12 #include "net/dns/dns_config_service.h" 15 #include "net/dns/dns_config_service.h"
16 #include "net/dns/dns_socket_pool.h"
17 #include "net/udp/datagram_client_socket.h"
13 18
14 namespace net { 19 namespace net {
15 20
16 class ClientSocketFactory; 21 class ClientSocketFactory;
17 class NetLog; 22 class NetLog;
18 23
19 // Session parameters and state shared between DNS transactions. 24 // Session parameters and state shared between DNS transactions.
20 // Ref-counted so that DnsClient::Request can keep working in absence of 25 // Ref-counted so that DnsClient::Request can keep working in absence of
21 // DnsClient. A DnsSession must be recreated when DnsConfig changes. 26 // DnsClient. A DnsSession must be recreated when DnsConfig changes.
22 class NET_EXPORT_PRIVATE DnsSession 27 class NET_EXPORT_PRIVATE DnsSession
23 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>) { 28 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>) {
24 public: 29 public:
30 class SocketPool;
szym 2012/09/14 20:49:27 leftovers?
Deprecated (see juliatuttle) 2012/09/18 20:28:00 Done.
31
25 typedef base::Callback<int()> RandCallback; 32 typedef base::Callback<int()> RandCallback;
26 33
34 class SocketLease {
35 public:
36 SocketLease(scoped_refptr<DnsSession> session,
37 unsigned server_index,
38 scoped_ptr<DatagramClientSocket> socket);
39 ~SocketLease();
40
41 DatagramClientSocket* socket() { return socket_.get(); }
42
43 private:
44 scoped_refptr<DnsSession> session_;
45 unsigned server_index_;
46 scoped_ptr<DatagramClientSocket> socket_;
szym 2012/09/14 20:49:27 DISALLOW_COPY_AND_ASSIGN
Deprecated (see juliatuttle) 2012/09/18 20:28:00 Done.
47 };
48
27 DnsSession(const DnsConfig& config, 49 DnsSession(const DnsConfig& config,
28 ClientSocketFactory* factory, 50 ClientSocketFactory* socket_factory,
szym 2012/09/14 20:49:27 DnsSession never uses ClientSocketFactory other th
Deprecated (see juliatuttle) 2012/09/18 20:28:00 Done.
51 scoped_ptr<DnsSocketPool> socket_pool,
29 const RandIntCallback& rand_int_callback, 52 const RandIntCallback& rand_int_callback,
30 NetLog* net_log); 53 NetLog* net_log);
31 54
32 const DnsConfig& config() const { return config_; } 55 const DnsConfig& config() const { return config_; }
33 NetLog* net_log() const { return net_log_; } 56 NetLog* net_log() const { return net_log_; }
34 57
35 ClientSocketFactory* socket_factory() { return socket_factory_; }
36
37 // Return the next random query ID. 58 // Return the next random query ID.
38 int NextQueryId() const; 59 int NextQueryId() const;
39 60
40 // Return the index of the first configured server to use on first attempt. 61 // Return the index of the first configured server to use on first attempt.
41 int NextFirstServerIndex(); 62 int NextFirstServerIndex();
42 63
43 // Return the timeout for the next query. 64 // Return the timeout for the next query.
44 base::TimeDelta NextTimeout(int attempt); 65 base::TimeDelta NextTimeout(int attempt);
45 66
67 // Allocate a socket, already connected to the server address.
68 scoped_ptr<SocketLease> AllocateSocket(unsigned server_index,
69 const NetLog::Source& source);
70
46 private: 71 private:
47 friend class base::RefCounted<DnsSession>; 72 friend class base::RefCounted<DnsSession>;
48 ~DnsSession(); 73
74 // Release a socket.
75 void FreeSocket(unsigned server_index,
76 scoped_ptr<DatagramClientSocket> socket);
49 77
50 const DnsConfig config_; 78 const DnsConfig config_;
51 ClientSocketFactory* socket_factory_; 79 scoped_ptr<DnsSocketPool> socket_pool_;
52 RandCallback rand_callback_; 80 RandIntCallback rand_int_callback_;
szym 2012/09/14 20:49:27 Do you still need this change?
Deprecated (see juliatuttle) 2012/09/18 20:28:00 Done.
53 NetLog* net_log_; 81 NetLog* net_log_;
54 82
55 // Current index into |config_.nameservers| to begin resolution with. 83 // Current index into |config_.nameservers| to begin resolution with.
56 int server_index_; 84 int server_index_;
57 85
58 // TODO(szym): Add current RTT estimate. 86 // TODO(szym): Add current RTT estimate.
59 // TODO(szym): Add TCP connection pool to support DNS over TCP. 87 // TODO(szym): Add TCP connection pool to support DNS over TCP.
60 // TODO(szym): Add UDP port pool to avoid NAT table overload.
61 88
62 DISALLOW_COPY_AND_ASSIGN(DnsSession); 89 DISALLOW_COPY_AND_ASSIGN(DnsSession);
63 }; 90 };
64 91
65 } // namespace net 92 } // namespace net
66 93
67 #endif // NET_DNS_DNS_SESSION_H_ 94 #endif // NET_DNS_DNS_SESSION_H_
OLDNEW
« no previous file with comments | « net/dns/dns_client.cc ('k') | net/dns/dns_session.cc » ('j') | net/dns/dns_session_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698