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

Unified Diff: net/tools/quic/synchronous_host_resolver.cc

Issue 1004173004: Make the simple QUIC client able to resolve hosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove EXPORT to fix Win Created 5 years, 9 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
« no previous file with comments | « net/tools/quic/synchronous_host_resolver.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/synchronous_host_resolver.cc
diff --git a/net/tools/quic/synchronous_host_resolver.cc b/net/tools/quic/synchronous_host_resolver.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7955186f5d071510338b4c2b07eb9b5fa6b9a801
--- /dev/null
+++ b/net/tools/quic/synchronous_host_resolver.cc
@@ -0,0 +1,109 @@
+// Copyright (c) 2015 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.
+
+#include "net/tools/quic/synchronous_host_resolver.h"
+
+#include "base/at_exit.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/simple_thread.h"
+#include "net/base/host_port_pair.h"
+#include "net/base/net_errors.h"
+#include "net/dns/host_resolver_impl.h"
+#include "net/dns/single_request_host_resolver.h"
+
+namespace net {
+
+namespace tools {
+
+namespace {
+
+class ResolverThread : public base::SimpleThread {
+ public:
+ ResolverThread();
+
+ ~ResolverThread() override;
+
+ // Called on the main thread.
+ int Resolve(const std::string& host, AddressList* addresses);
+
+ // SimpleThread methods:
+ void Run() override;
+
+ private:
+ void OnResolutionComplete(int rv);
+
+ AddressList* addresses_;
+ std::string host_;
+ int rv_;
+
+ base::WaitableEvent resolved_; // Notified when the resolution is complete.
+
+ base::WeakPtrFactory<ResolverThread> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResolverThread);
+};
+
+ResolverThread::ResolverThread()
+ : SimpleThread("resolver_thread"),
+ rv_(ERR_UNEXPECTED),
+ resolved_(true, false),
+ weak_factory_(this) {}
+
+ResolverThread::~ResolverThread() {}
+
+void ResolverThread::Run() {
+ base::AtExitManager exit_manager;
+ base::MessageLoopForIO loop;
+
+ net::HostResolver::Options options;
+ options.max_concurrent_resolves = 6;
+ options.max_retry_attempts = 3u;
+ net::NetLog net_log;
+ scoped_ptr<net::HostResolverImpl> resolver_impl(
+ new net::HostResolverImpl(options, &net_log));
+ SingleRequestHostResolver resolver(resolver_impl.get());
+
+ HostPortPair host_port_pair(host_, 80);
+
+ rv_ = resolver.Resolve(
+ HostResolver::RequestInfo(host_port_pair), DEFAULT_PRIORITY,
+ addresses_,
+ base::Bind(&ResolverThread::OnResolutionComplete,
+ weak_factory_.GetWeakPtr()),
+ BoundNetLog());
+
+ if (rv_ != ERR_IO_PENDING) {
+ resolved_.Signal();
+ }
+
+ while (!resolved_.IsSignaled()) {
+ base::MessageLoop::current()->RunUntilIdle();
+ }
+}
+
+int ResolverThread::Resolve(const std::string& host, AddressList* addresses) {
+ host_ = host;
+ addresses_ = addresses;
+ this->Start();
+ resolved_.Wait();
+ this->Join();
+ return rv_;
+}
+
+void ResolverThread::OnResolutionComplete(int rv) {
+ rv_ = rv;
+ resolved_.Signal();
+}
+
+} // namespace
+
+// static
+int SynchronousHostResolver::Resolve(const std::string& host,
+ AddressList* addresses) {
+ ResolverThread resolver;
+ return resolver.Resolve(host, addresses);
+}
+
+} // namespace tools
+} // namespace net
« no previous file with comments | « net/tools/quic/synchronous_host_resolver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698