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

Unified Diff: net/dns/dns_session.cc

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 side-by-side diff with in-line comments
Download patch
Index: net/dns/dns_session.cc
diff --git a/net/dns/dns_session.cc b/net/dns/dns_session.cc
index fb6c4b4c5ba269157bf7ca29cc7d5c06052ccda1..bbb9faf014ca7e969b209012393de390ad67bc43 100644
--- a/net/dns/dns_session.cc
+++ b/net/dns/dns_session.cc
@@ -6,22 +6,35 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/rand_util.h"
+#include "base/stl_util.h"
#include "base/time.h"
#include "net/base/ip_endpoint.h"
+#include "net/base/net_errors.h"
#include "net/dns/dns_config_service.h"
-#include "net/socket/client_socket_factory.h"
+#include "net/dns/dns_socket_pool.h"
namespace net {
+DnsSession::SocketLease::SocketLease(scoped_refptr<DnsSession> session,
+ unsigned server_index,
+ scoped_ptr<DatagramClientSocket> socket)
+ : session_(session), server_index_(server_index), socket_(socket.Pass()) {}
+
+DnsSession::SocketLease::~SocketLease() {
+ session_->FreeSocket(server_index_, socket_.Pass());
+}
+
DnsSession::DnsSession(const DnsConfig& config,
- ClientSocketFactory* factory,
+ scoped_ptr<DnsSocketPool> socket_pool,
const RandIntCallback& rand_int_callback,
NetLog* net_log)
: config_(config),
- socket_factory_(factory),
+ socket_pool_(socket_pool.Pass()),
rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)),
net_log_(net_log),
server_index_(0) {
+ socket_pool_->Initialize(net_log, &config_.nameservers);
}
int DnsSession::NextQueryId() const {
@@ -41,7 +54,34 @@ base::TimeDelta DnsSession::NextTimeout(int attempt) {
return config_.timeout * (1 << (attempt / config_.nameservers.size()));
}
-DnsSession::~DnsSession() {}
+// Allocate a socket, already connected to the server address.
+scoped_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket(
+ unsigned server_index,
+ const NetLog::Source& source) {
+ scoped_ptr<DatagramClientSocket> socket;
-} // namespace net
+ socket = socket_pool_->AllocateSocket(server_index).Pass();
szym 2012/09/26 11:16:12 You don't need Pass() here. It's an Rvalue.
Deprecated (see juliatuttle) 2012/09/26 20:44:50 Done.
+ if (!socket.get()) {
szym 2012/09/26 11:16:12 nit: no need for {}
Deprecated (see juliatuttle) 2012/09/26 20:44:50 Done.
+ return scoped_ptr<SocketLease>(NULL);
+ }
+
+ socket->NetLog().BeginEvent(
+ NetLog::TYPE_SOCKET_IN_USE,
+ source.ToEventParametersCallback());
+
+ SocketLease* lease = new SocketLease(this, server_index, socket.Pass());
+ return scoped_ptr<SocketLease>(lease);
+}
+
+// Release a socket.
+void DnsSession::FreeSocket(
+ unsigned server_index,
+ scoped_ptr<DatagramClientSocket> socket) {
+ CHECK(socket.get());
szym 2012/09/26 11:16:12 I think DCHECK would suffice.
Deprecated (see juliatuttle) 2012/09/26 20:44:50 Done.
+
+ socket->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE);
+ socket_pool_->FreeSocket(server_index, socket.Pass());
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698