eve.aio.dns

Asynchronous DNS resolution.

This module provides high-level asynchronous DNS resolution built on top of the EVE event loop and a thread pool. It follows the EVE principles of zero-allocation and non-blocking I/O by offloading blocking libc calls to worker threads.

Thread Pool Requirement

DNS resolution uses getaddrinfo() which is a blocking C library call. EVE offloads it to a ThreadPool so the event loop thread is never blocked. You must create and start a ThreadPool before calling resolve():

auto loop = EventLoop.create();
auto pool = ThreadPool.create(2);
pool.start();              // must call before resolve()
scope (exit) pool.shutdown();

auto resolver = DnsResolver.create(loop, pool);
resolver.resolve("example.com", callback);

If no pool is provided (or null), resolve() returns false.

Timeout

EVE does not impose a built-in DNS timeout. Use CancelSource with a timer to enforce application-level timeouts (see book/dns_with_timeout.d).

Concurrency

The number of simultaneous DNS queries is limited by dnsCapacity in EventLoopConfig (default: 4). Increase it if your application issues many concurrent lookups. Worker threads in the pool execute resolution in parallel.

See Also

Types 1

Resolver for translating hostnames to IP addresses.

Requires a running ThreadPool to perform resolution. See module documentation for setup instructions.

Example:

auto resolver = DnsResolver.create(loop, pool);
resolver.resolve("localhost", (ref l, t, addrs, err) @safe nothrow {
    // handle result
});

Fields
EventLoop * _loop
Methods
DnsResolver create(ref EventLoop loop, ThreadPool pool = null) static @trustedCreate a new DNS resolver associated with an event loop.
bool resolve(scope const(char)[] hostname, EventLoop.DnsWatcherCallback callback, CancelToken cancel = CancelToken .invalid) @trustedAsynchronously resolve a hostname.
void performResolution(Token token) @trusted
DnsError mapDnsError(int err) static pure @safe nothrow @nogc