diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-07-09 13:02:37 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-02-23 13:56:08 +0100 |
commit | b86547dc1ef407ca3838444533bc7145e32a0d90 (patch) | |
tree | 3aa692def62796a5debe705ebc29d40b311e38cb /src/network/dns_socket_handler.hpp | |
parent | a17135720e77c03e66679852198e46a070d56f4d (diff) | |
download | biboumi-b86547dc1ef407ca3838444533bc7145e32a0d90.tar.gz biboumi-b86547dc1ef407ca3838444533bc7145e32a0d90.tar.bz2 biboumi-b86547dc1ef407ca3838444533bc7145e32a0d90.tar.xz biboumi-b86547dc1ef407ca3838444533bc7145e32a0d90.zip |
Implement async DNS resolution using c-ares
fix #2533
Diffstat (limited to 'src/network/dns_socket_handler.hpp')
-rw-r--r-- | src/network/dns_socket_handler.hpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/network/dns_socket_handler.hpp b/src/network/dns_socket_handler.hpp new file mode 100644 index 0000000..beb47d9 --- /dev/null +++ b/src/network/dns_socket_handler.hpp @@ -0,0 +1,46 @@ +#ifndef DNS_SOCKET_HANDLER_HPP +# define DNS_SOCKET_HANDLER_HPP + +#include <config.h> +#ifdef CARES_FOUND + +#include <network/socket_handler.hpp> +#include <ares.h> + +/** + * Manage a socket returned by ares_fds. We do not create, open or close the + * socket ourself: this is done by c-ares. We just call ares_process_fd() + * with the correct parameters, depending on what can be done on that socket + * (Poller reported it to be writable or readeable) + */ + +class DNSSocketHandler: public SocketHandler +{ +public: + explicit DNSSocketHandler(std::shared_ptr<Poller> poller, const socket_t socket); + ~DNSSocketHandler(); + /** + * Just call dns_process_fd, c-ares will do its work of send()ing or + * recv()ing the data it wants on that socket. + */ + void on_recv() override final; + void on_send() override final; + /** + * Do nothing, because we are always considered to be connected, since the + * connection is done by c-ares and not by us. + */ + void connect() override final; + /** + * Always true, see the comment for connect() + */ + bool is_connected() const override final; + +private: + DNSSocketHandler(const DNSSocketHandler&) = delete; + DNSSocketHandler(DNSSocketHandler&&) = delete; + DNSSocketHandler& operator=(const DNSSocketHandler&) = delete; + DNSSocketHandler& operator=(DNSSocketHandler&&) = delete; +}; + +#endif // CARES_FOUND +#endif // DNS_SOCKET_HANDLER_HPP |