boost::corosio::resolver

An asynchronous DNS resolver for coroutine I/O.

Synopsis

class resolver
    : public io_object

Description

This class provides asynchronous DNS resolution operations that return awaitable types. Each operation participates in the affine awaitable protocol, ensuring coroutines resume on the correct executor.

Thread Safety

Distinct objects: Safe. Shared objects: Unsafe. A resolver must not have concurrent resolve operations.

Semantics

Wraps platform DNS resolution (getaddrinfo/getnameinfo). Operations dispatch to OS resolver APIs via the io_context thread pool.

Example

io_context ioc;
resolver r(ioc);

// Using structured bindings
auto [ec, results] = co_await r.resolve("www.example.com", "https");
if (ec)
    co_return;

for (auto const& entry : results)
    std::cout << entry.get_endpoint().port() << std::endl;

// Or, to convert errors into exceptions:
auto [ec2, results2] = co_await r.resolve("www.example.com", "https");
if (ec2)
    throw std::system_error(ec2);

Base Classes

Name

Description

io_object

Base class for platform I/O objects.

Types

Name

Description

handle

RAII wrapper for I/O object implementation lifetime.

implementation

Backend interface for DNS resolution operations.

io_service

Service interface for I/O object lifecycle management.

Member Functions

Name

Description

resolver [constructor] [deleted]

Constructors

~resolver [destructor] [virtual]

Destructor.

operator= [deleted]

Move assignment operator.

cancel

Cancel any pending asynchronous operations.

context

Return the execution context.

resolve

resolve overloads

Protected Member Functions

Name

Description

resolver [constructor]

Construct from handle

operator= [deleted]

Move assign from another I/O object.

Protected Static Member Functions

Name

Description

create_handle

Create a handle bound to a service found in the context.

Protected Data Members

Name

Description

h_

The platform I/O handle owned by this object.

Derived Classes

Name

Description

native_resolver

An asynchronous DNS resolver with devirtualized operations.

Created with MrDocs