Template Class base_resolver

Inheritance Relationships

Base Type

Class Documentation

template<typename Protocol>
class stream_client::resolver::base_resolver : public stream_client::detail::timed_base<Clock>

DNS resolver.

This class wraps usage of boost::asio::ip::basic_resolver to make it timeout-blocked. Used to resolve a hostname:port pair to an iterator of endpoints.

Note

Not thread-safe, concurrent calls of resolve() may mess up timeout handling.

tparam Protocol

Type of result endpoints.

Public Types

using protocol_type = typename std::remove_reference<Protocol>::type
using resolver_type = boost::asio::ip::basic_resolver<protocol_type>
using query_type = typename resolver_type::query
using resolve_flags_type = typename query_type::flags
using iterator_type = typename resolver_type::iterator

Public Functions

base_resolver(std::string host, std::string port, time_duration_type resolve_timeout, ip_family protocol = kDefaultIPFamily, resolve_flags_type resolve_flags = kDefaultFlags)

Parametrized constructor.

Stores remote parameters needed for resolving. Doesn’t do actual resolution, to make it happen call resolve() on constructed instance.

Parameters
  • [in] host – Remote hostname.

  • [in] port – Remote port used in resolved endpoints.

  • [in] resolve_timeout – Default resolve timeout.

  • [in] protocol – Family of IP protocol to resolve (ipv4, ipv6 or any).

  • [in] resolve_flags – A set of flags that determine how name resolution should be performed.

base_resolver(const base_resolver<Protocol> &other) = delete

Copy constructor is not permitted.

base_resolver<Protocol> &operator=(const base_resolver<Protocol> &other) = delete

Copy assignment is not permitted.

base_resolver(base_resolver<Protocol> &&other) = default

Move constructor.

base_resolver<Protocol> &operator=(base_resolver<Protocol> &&other) = default

Move assignment.

virtual ~base_resolver() = default

Destructor.

template<typename Time>
iterator_type resolve(boost::system::error_code &ec, const Time &timeout_or_deadline)

Perform DNS resolve.

Resolve stored hostname into iterator of address:port pairs within specified timeout.

Note

A successful call to this function is guaranteed to return at least one entry.

Template Parameters

Time – Type of timeout_or_deadline, either time_duration_type or time_point_type.

Parameters
  • [in] timeout_or_deadline – Expiration time-point or duration.

  • [out] ec – Set to indicate what error occurred, if any.

Returns

A forward-only iterator that can be used to traverse the list of endpoint entries. Returns a default constructed iterator if an error occurs.

inline iterator_type resolve(boost::system::error_code &ec)

Perform DNS resolve.

Resolve stored hostname into iterator of address:port pairs within default timeout. Timeout can be manipulated with resolve_timeout().

Note

A successful call to this function is guaranteed to return at least one entry.

Parameters

[out] ec – Set to indicate what error occurred, if any.

Returns

A forward-only iterator that can be used to traverse the list of endpoint entries. Returns a default constructed iterator if an error occurs.

inline iterator_type resolve()

Perform DNS resolve.

Resolve stored hostname into iterator of address:port pairs within default timeout. Timeout can be manipulated with resolve_timeout().

Note

A successful call to this function is guaranteed to return at least one entry.

Parameters

[out] ec – Set to indicate what error occurred, if any.

Throws

boost::system::system_error – Thrown on failure.

inline const time_duration_type &resolve_timeout() const

Get resolve operations timeout.

This function used to get current value for resolve() timeout.

Returns

A const reference to the timeout.

inline time_duration_type resolve_timeout(time_duration_type new_resolve_timeout)

Set resolve operations timeout.

This function used to set new value for resolve() timeout.

Returns

Previous timeout value.

Public Static Attributes

static const resolve_flags_type kDefaultFlags = resolve_flags_type::address_configured

Default flags to use with internal DNS query.

static const ip_family kDefaultIPFamily = ip_family::any

Default version of IP protocol to resolve into.