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() fails with ResolveErrorReason.NOT_INITIALIZED.

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 4

enumResolveErrorReason : ubyte

Reason a DNS resolution request was not queued.

UNSPECIFIED = 0Not a real domain error; the default-constructed payload value.
NOT_INITIALIZEDThe resolver has no loop or no worker pool (`null` at `create()`).
NO_SLOTSThe event loop has no free DNS slots.

Recoverable failure of a DNS resolution request.

Fields
ResolveErrorReason reasonWhy the request was not queued.
int errnoReserved; OS errors do not apply to slot allocation.

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