summaryrefslogtreecommitdiff
path: root/louloulibs/network/dns_handler.hpp
diff options
context:
space:
mode:
authorVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:40 +0530
committerVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:40 +0530
commiteda4b75b1cff83336e87da90efca9fd6b4ced2c7 (patch)
tree491317ce50b5d19bc434ccc4b448d1bc70520177 /louloulibs/network/dns_handler.hpp
parent716c40e4ec45f8d538695225f4f06d541d959084 (diff)
parent0f14fe83ef53b08bd8fa09670c82f4996c329bdc (diff)
downloadbiboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.gz
biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.bz2
biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.xz
biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.zip
New upstream version 3.0upstream/3.0
Diffstat (limited to 'louloulibs/network/dns_handler.hpp')
-rw-r--r--louloulibs/network/dns_handler.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/louloulibs/network/dns_handler.hpp b/louloulibs/network/dns_handler.hpp
new file mode 100644
index 0000000..fd1729d
--- /dev/null
+++ b/louloulibs/network/dns_handler.hpp
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <louloulibs.h>
+#ifdef CARES_FOUND
+
+class TCPSocketHandler;
+class Poller;
+class DNSSocketHandler;
+
+# include <ares.h>
+# include <memory>
+# include <string>
+# include <vector>
+
+/**
+ * Class managing DNS resolution. It should only be statically instanciated
+ * once in SocketHandler. It manages ares channel and calls various
+ * functions of that library.
+ */
+
+class DNSHandler
+{
+public:
+ DNSHandler();
+ ~DNSHandler() = default;
+ DNSHandler(const DNSHandler&) = delete;
+ DNSHandler(DNSHandler&&) = delete;
+ DNSHandler& operator=(const DNSHandler&) = delete;
+ DNSHandler& operator=(DNSHandler&&) = delete;
+
+ void gethostbyname(const std::string& name, ares_host_callback callback,
+ void* socket_handler, int family);
+ /**
+ * Call ares_fds to know what fd needs to be watched by the poller, create
+ * or destroy DNSSocketHandlers depending on the result.
+ */
+ void watch_dns_sockets(std::shared_ptr<Poller>& poller);
+ /**
+ * Destroy and stop watching all the DNS sockets. Then de-init the channel
+ * and library.
+ */
+ void destroy();
+ void remove_all_sockets_from_poller();
+ ares_channel& get_channel();
+
+ static DNSHandler instance;
+
+private:
+ /**
+ * The list of sockets that needs to be watched, according to the last
+ * call to ares_fds. DNSSocketHandlers are added to it or removed from it
+ * in the watch_dns_sockets() method
+ */
+ std::vector<std::unique_ptr<DNSSocketHandler>> socket_handlers;
+ ares_channel channel;
+};
+
+#endif /* CARES_FOUND */