shill: Create an asynchronous resolver object
Resolve DNS requests using the c-ares library but
using the shill event loop to handle events.
BUG=chromium-os:21664
TEST=New unit test
Change-Id: I99776b6cc74977d31198c67357c42a75f4047942
Reviewed-on: https://gerrit.chromium.org/gerrit/10328
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/shill_ares.h b/shill_ares.h
new file mode 100644
index 0000000..33c10fb
--- /dev/null
+++ b/shill_ares.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2011 The Chromium OS 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 SHILL_ARES_H_
+#define SHILL_ARES_H_
+
+#include <ares.h>
+
+#include <base/lazy_instance.h>
+
+namespace shill {
+
+// A "ares.h" abstraction allowing mocking in tests.
+class Ares {
+ public:
+ virtual ~Ares();
+
+ static Ares *GetInstance();
+
+ // ares_destroy
+ virtual void Destroy(ares_channel channel);
+
+ // ares_gethostbyname
+ virtual void GetHostByName(ares_channel channel,
+ const char *hostname,
+ int family,
+ ares_host_callback callback,
+ void *arg);
+
+ // ares_getsock
+ virtual int GetSock(ares_channel channel,
+ ares_socket_t *socks,
+ int numsocks);
+
+ // ares_init_options
+ virtual int InitOptions(ares_channel *channelptr,
+ struct ares_options *options,
+ int optmask);
+
+ // ares_process_fd
+ virtual void ProcessFd(ares_channel channel,
+ ares_socket_t read_fd,
+ ares_socket_t write_fd);
+
+ // ares_set_local_dev
+ virtual void SetLocalDev(ares_channel channel, const char *local_dev_name);
+
+ // ares_timeout
+ virtual struct timeval *Timeout(ares_channel channel,
+ struct timeval *maxtv,
+ struct timeval *tv);
+
+ protected:
+ Ares();
+
+ private:
+ friend struct base::DefaultLazyInstanceTraits<Ares>;
+
+ DISALLOW_COPY_AND_ASSIGN(Ares);
+};
+
+} // namespace shill
+
+#endif // SHILL_ARES_H_