COROIO: NNet::TResolver< TPoller > Class Template Reference
COROIO
 
Loading...
Searching...
No Matches
NNet::TResolver< TPoller > Class Template Reference

Resolves hostnames into IP addresses using a custom poller. More...

#include <resolver.hpp>

Public Member Functions

 TResolver (TPoller &poller, EDNSType defaultType=EDNSType::A)
 Constructs a TResolver using the default resolv configuration.
 
 TResolver (const TResolvConf &conf, TPoller &poller, EDNSType defaultType=EDNSType::A)
 Constructs a TResolver with a specified DNS configuration.
 
 TResolver (TAddress dnsAddr, TPoller &poller, EDNSType defaultType=EDNSType::A)
 Constructs a TResolver using a specific DNS address.
 
TFuture< std::vector< TAddress > > Resolve (const std::string &hostname, EDNSType type=EDNSType::DEFAULT)
 Resolves a hostname to a list of addresses.
 

Detailed Description

template<typename TPoller>
class NNet::TResolver< TPoller >

Resolves hostnames into IP addresses using a custom poller.

The TResolver class provides DNS resolution functionality by sending DNS queries to a nameserver. It supports different DNS record types as specified by EDNSType. Internally, it uses a polling mechanism (provided by the template parameter) for asynchronous operations.

Template Parameters
TPollerThe type of the poller used to manage asynchronous operations.

Example Usage

// Assume TSelect is a poller type with methods Poll() and WakeupReadyHandles()
TSelect poller;
// Create a resolver using the default nameserver specified in /etc/resolv.conf
TResolver<TSelect> resolver(poller);
// Asynchronously resolve a hostname (IPv4 resolution by default)
TFuture<std::vector<TAddress>> futureAddresses = resolver.Resolve("example.com");
// Later (in an asynchronous context) use:
// auto addresses = co_await futureAddresses;
TResolver(TPoller &poller, EDNSType defaultType=EDNSType::A)
Constructs a TResolver using the default resolv configuration.
Poller implementation based on the select() system call.
Definition select.hpp:36
Future type for coroutines returning a value of type T.
Definition corochain.hpp:177

Constructor & Destructor Documentation

◆ TResolver() [1/3]

template<typename TPoller>
NNet::TResolver< TPoller >::TResolver ( TPoller & poller,
EDNSType defaultType = EDNSType::A )

Constructs a TResolver using the default resolv configuration.

The resolver uses DNS nameservers from the default configuration file or as determined by the system.

Parameters
pollerReference to a poller used for asynchronous operations.
defaultTypeThe default DNS record type to use if none is specified in a request.

◆ TResolver() [2/3]

template<typename TPoller>
NNet::TResolver< TPoller >::TResolver ( const TResolvConf & conf,
TPoller & poller,
EDNSType defaultType = EDNSType::A )

Constructs a TResolver with a specified DNS configuration.

This constructor initializes the resolver with nameservers from a given TResolvConf object.

Parameters
confA TResolvConf object containing DNS configuration.
pollerReference to a poller for asynchronous operations.
defaultTypeThe default DNS record type to use for resolution.

◆ TResolver() [3/3]

template<typename TPoller>
NNet::TResolver< TPoller >::TResolver ( TAddress dnsAddr,
TPoller & poller,
EDNSType defaultType = EDNSType::A )

Constructs a TResolver using a specific DNS address.

This variant allows specifying a single DNS nameserver for resolution.

Parameters
dnsAddrThe address of the DNS server.
pollerReference to a poller used for asynchronous operations.
defaultTypeThe default DNS record type for resolution.

Member Function Documentation

◆ Resolve()

template<typename TPoller>
TFuture< std::vector< TAddress > > NNet::TResolver< TPoller >::Resolve ( const std::string & hostname,
EDNSType type = EDNSType::DEFAULT )

Resolves a hostname to a list of addresses.

Sends a DNS query for the specified hostname. If the request type is set to EDNSType::DEFAULT, the default DNS record type (specified in the constructor) is used.

Parameters
hostnameThe name to be resolved.
typeThe DNS record type to query. If EDNSType::DEFAULT is specified, the default type provided to the constructor is used.
Returns
A TFuture containing a vector of TAddress objects with the resolved addresses.

The documentation for this class was generated from the following file: