Chops Net IP
Loading...
Searching...
No Matches
chops::net::endpoints_resolver< Protocol > Class Template Reference

Convenience class for resolving names to endpoints suitable for use within the Chops Net IP library (or with the Asio API). More...

#include <endpoints_resolver.hpp>

Public Member Functions

 endpoints_resolver (asio::io_context &ioc)
 Construct with an io_context.
 
template<typename F >
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.
 
void cancel ()
 Cancel any outstanding async operations.
 
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.
 

Detailed Description

template<typename Protocol>
class chops::net::endpoints_resolver< Protocol >

Convenience class for resolving names to endpoints suitable for use within the Chops Net IP library (or with the Asio API).

This class does not add much functionality above what is already present in the Asio library, but does automate the flags for local resolves.

Many times only one endpoint is needed, for example a TCP acceptor local endpoint or a UDP local endpoint. In this case the first entry of an endpoint sequence can be used.

Name resolving will not be performed if the host name is already in dotted numeric or hexadecimal (ipV6) form, or if the host name is empty (common for when the local host IP address is meant to be "INADDR_ANY", such as a TCP acceptor local endpoint).

For the methods taking a function object callback it is the applications responsibility to ensure that the memory context is still valid when the callback is invoked. A typical idiom is to use std::shared_from_this as part of the function object callback member.

Constructor & Destructor Documentation

◆ endpoints_resolver()

template<typename Protocol >
chops::net::endpoints_resolver< Protocol >::endpoints_resolver ( asio::io_context & ioc)
inlineexplicit

Construct with an io_context.

Parameters
iocasio::io_context used in the resolver.

Member Function Documentation

◆ make_endpoints() [1/2]

template<typename Protocol >
auto chops::net::endpoints_resolver< Protocol >::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>
inline

Create a sequence of endpoints and return them immediately in a container.

This function performs synchronous (blocking) name resolution instead of asynchronous resolution. The interface is the same as the async method (taking a function object) except that a container of endpoints is returned instead of a function object callback invocation happening at a later point.

Returns
expected, on success contains asio::ip::basic_resolver_results<Protocol>, where Protocol is either asio::ip::tcp or asio::ip::udp; on failure returns a std::error_code.

◆ make_endpoints() [2/2]

template<typename Protocol >
template<typename F >
void chops::net::endpoints_resolver< Protocol >::make_endpoints ( bool local,
std::string_view host_or_intf_name,
std::string_view service_or_port,
F && func )
inline

Create a sequence of endpoints and return them in a function object callback.

This method always returns before the function object callback is invoked.

Parameters
localIf true, create endpoints for a local endpoint; specifically the "passive" flag is set.
host_or_intf_nameA host or interface name; if empty it can be used for a local endpoint where it specifies an "any" ("INADDR_ANY") address; if not empty it is used for the remote host name or for a local interface name where an address lookup is desired.
service_or_portA service name or port number; if empty all resolved endpoints will have a port number of zero.
funcFunction object which will be invoked when the name resolution completes. The signature of the callback:
// TCP:
void (std::error_code err, asio::ip::basic_resolver_results<asio::ip::tcp>);
// UDP:
void (std::error_code err, asio::ip::basic_resolver_results<asio::ip::udp>);

If an error occurs, the error code is set accordingly.


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