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

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: 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/udp/datagram_client_socket.h"
13 17
14 namespace net { 18 namespace net {
15 19
16 class ClientSocketFactory; 20 class ClientSocketFactory;
17 class NetLog; 21 class NetLog;
18 22
19 // Session parameters and state shared between DNS transactions. 23 // Session parameters and state shared between DNS transactions.
20 // Ref-counted so that DnsClient::Request can keep working in absence of 24 // Ref-counted so that DnsClient::Request can keep working in absence of
21 // DnsClient. A DnsSession must be recreated when DnsConfig changes. 25 // DnsClient. A DnsSession must be recreated when DnsConfig changes.
22 class NET_EXPORT_PRIVATE DnsSession 26 class NET_EXPORT_PRIVATE DnsSession
23 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>) { 27 : NON_EXPORTED_BASE(public base::RefCounted<DnsSession>) {
24 public: 28 public:
25 typedef base::Callback<int()> RandCallback; 29 typedef base::Callback<int()> RandCallback;
26 30
31 class SocketLease {
32 public:
33 SocketLease(scoped_refptr<DnsSession> session,
34 int server_index,
35 scoped_ptr<DatagramClientSocket> socket);
36 ~SocketLease();
37
38 DatagramClientSocket* socket() { return socket_.get(); }
39
40 private:
41 scoped_refptr<DnsSession> session_;
42 int server_index_;
43 scoped_ptr<DatagramClientSocket> socket_;
44 };
45
27 DnsSession(const DnsConfig& config, 46 DnsSession(const DnsConfig& config,
28 ClientSocketFactory* factory, 47 ClientSocketFactory* factory,
29 const RandIntCallback& rand_int_callback, 48 const RandIntCallback& rand_int_callback,
49 bool bypass_pools,
szym 2012/09/04 15:42:27 You could also consider making SocketPool a separa
30 NetLog* net_log); 50 NetLog* net_log);
31 51
32 const DnsConfig& config() const { return config_; } 52 const DnsConfig& config() const { return config_; }
33 NetLog* net_log() const { return net_log_; } 53 NetLog* net_log() const { return net_log_; }
34 54
35 ClientSocketFactory* socket_factory() { return socket_factory_; }
36
37 // Return the next random query ID. 55 // Return the next random query ID.
38 int NextQueryId() const; 56 int NextQueryId() const;
39 57
40 // Return the index of the first configured server to use on first attempt. 58 // Return the index of the first configured server to use on first attempt.
41 int NextFirstServerIndex(); 59 int NextFirstServerIndex();
42 60
43 // Return the timeout for the next query. 61 // Return the timeout for the next query.
44 base::TimeDelta NextTimeout(int attempt); 62 base::TimeDelta NextTimeout(int attempt);
45 63
64 // Allocate a socket, already connected to the server address.
65 // TODO(szym): add NetLog param?
66 scoped_ptr<SocketLease> AllocateSocket(int server_index);
cbentzel 2012/08/29 16:48:06 Not sure that I like using a server_index for this
szym 2012/08/29 16:57:08 If it's an IPEndPoint, this will have to keep a ma
cbentzel 2012/08/29 17:03:48 OK, int may be fine. But would we want to be able
Deprecated (see juliatuttle) 2012/08/29 17:52:34 I don't think DnsConfig changes are that common th
67
46 private: 68 private:
47 friend class base::RefCounted<DnsSession>; 69 friend class base::RefCounted<DnsSession>;
70
48 ~DnsSession(); 71 ~DnsSession();
49 72
73 // Release a socket.
74 void FreeSocket(int server_index, scoped_ptr<DatagramClientSocket> socket);
75
50 const DnsConfig config_; 76 const DnsConfig config_;
51 ClientSocketFactory* socket_factory_; 77 ClientSocketFactory* socket_factory_;
52 RandCallback rand_callback_; 78 RandCallback rand_callback_;
79 bool bypass_pools_;
53 NetLog* net_log_; 80 NetLog* net_log_;
54 81
82 std::vector<std::vector<DatagramClientSocket*> > pools_;
83
55 // Current index into |config_.nameservers| to begin resolution with. 84 // Current index into |config_.nameservers| to begin resolution with.
56 int server_index_; 85 int server_index_;
57 86
58 // TODO(szym): Add current RTT estimate. 87 // TODO(szym): Add current RTT estimate.
59 // TODO(szym): Add TCP connection pool to support DNS over TCP. 88 // TODO(szym): Add TCP connection pool to support DNS over TCP.
60 // TODO(szym): Add UDP port pool to avoid NAT table overload.
61 89
62 DISALLOW_COPY_AND_ASSIGN(DnsSession); 90 DISALLOW_COPY_AND_ASSIGN(DnsSession);
63 }; 91 };
64 92
65 } // namespace net 93 } // namespace net
66 94
67 #endif // NET_DNS_DNS_SESSION_H_ 95 #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.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698