~singpolyma/biboumi

ref: ffb402f0adb9f808c7b8bc9616e71f7b3f8931ac biboumi/src/network/dns_handler.cpp -rw-r--r-- 942 bytes
ffb402f0 — louiz’ Drop support for botan < 2.0 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <biboumi.h>
#ifdef UDNS_FOUND

#include <network/dns_socket_handler.hpp>
#include <network/dns_handler.hpp>
#include <network/poller.hpp>

#include <utils/timed_events.hpp>

#include <udns.h>
#include <cerrno>
#include <cstring>

class Resolver;

using namespace std::string_literals;

std::unique_ptr<DNSSocketHandler> DNSHandler::socket_handler{};

DNSHandler::DNSHandler(std::shared_ptr<Poller>& poller)
{
  dns_init(nullptr, 0);
  const auto socket = dns_open(nullptr);
  if (socket == -1)
    throw std::runtime_error("Failed to initialize udns socket: "s + strerror(errno));

  DNSHandler::socket_handler = std::make_unique<DNSSocketHandler>(poller, socket);
}

void DNSHandler::destroy()
{
  DNSHandler::socket_handler.reset(nullptr);
  dns_close(nullptr);
}

void DNSHandler::watch()
{
  DNSHandler::socket_handler->watch();
}

void DNSHandler::unwatch()
{
  DNSHandler::socket_handler->unwatch();
}

#endif /* UDNS_FOUND */