16#ifndef ENDPOINTS_RESOLVER_HPP_INCLUDED
17#define ENDPOINTS_RESOLVER_HPP_INCLUDED
19#include "asio/ip/basic_resolver.hpp"
20#include "asio/io_context.hpp"
26#include "nonstd/expected.hpp"
52template <
typename Protocol>
55 asio::ip::basic_resolver<Protocol> m_resolver;
97 std::string_view service_or_port, F&& func) {
102 m_resolver.async_resolve(host_or_intf_name, service_or_port,
103 asio::ip::resolver_base::flags(asio::ip::resolver_base::passive |
104 asio::ip::resolver_base::address_configured),
108 m_resolver.async_resolve(host_or_intf_name, service_or_port,
134 auto make_endpoints(
bool local, std::string_view host_or_intf_name, std::string_view service_or_port) ->
135 nonstd::expected<asio::ip::basic_resolver_results<Protocol>, std::error_code> {
138 auto res = m_resolver.resolve(host_or_intf_name, service_or_port,
139 (local ? asio::ip::resolver_base::flags(asio::ip::resolver_base::passive |
140 asio::ip::resolver_base::address_configured) :
141 asio::ip::resolver_base::flags()), ec);
143 return nonstd::make_unexpected(ec);
Convenience class for resolving names to endpoints suitable for use within the Chops Net IP library (...
Definition endpoints_resolver.hpp:53
void cancel()
Cancel any outstanding async operations.
Definition endpoints_resolver.hpp:117
void make_endpoints(bool local, std::string_view host_or_intf_name, std::string_view service_or_port, F &&func)
Create a sequence of endpoints and return them in a function object callback.
Definition endpoints_resolver.hpp:96
auto make_endpoints(bool local, std::string_view host_or_intf_name, std::string_view service_or_port) -> nonstd::expected< asio::ip::basic_resolver_results< Protocol >, std::error_code >
Create a sequence of endpoints and return them immediately in a container.
Definition endpoints_resolver.hpp:134
endpoints_resolver(asio::io_context &ioc)
Construct with an io_context.
Definition endpoints_resolver.hpp:65