E-MailRelay
Classes | Public Types | Public Member Functions | List of all members
GNet::ResolverFuture Class Reference

A 'future' shared-state class for asynchronous name resolution that holds parameters and results of a call to getaddrinfo(), as performed by the run() method. More...

#include <gresolverfuture.h>

Public Types

using Pair = std::pair< Address, std::string >
 
using List = std::vector< Address >
 

Public Member Functions

 ResolverFuture (const std::string &host, const std::string &service, int family, bool dgram, bool for_async_hint=false)
 Constructor for resolving the given host and service names. More...
 
 ~ResolverFuture ()
 Destructor. More...
 
ResolverFuturerun () noexcept
 Does the synchronous name resolution and stores the result. More...
 
Pair get ()
 Returns the resolved address/name pair after run() has completed. More...
 
void get (List &)
 Returns the resolved addresses after run() has completed by appending to the given list. More...
 
bool error () const
 Returns true if name resolution failed or no suitable address was returned. More...
 
std::string reason () const
 Returns the reason for the error(). More...
 
 ResolverFuture (const ResolverFuture &)=delete
 
 ResolverFuture (ResolverFuture &&)=delete
 
void operator= (const ResolverFuture &)=delete
 
void operator= (ResolverFuture &&)=delete
 

Detailed Description

A 'future' shared-state class for asynchronous name resolution that holds parameters and results of a call to getaddrinfo(), as performed by the run() method.

The run() method can be called from a worker thread and the results collected by the main thread using get() once the worker thread has signalled that it has finished. The signalling mechanism is outside the scope of this class (see GNet::FutureEvent).

Eg:

ResolverFuture f( "example.com" , "smtp" , AF_INET , false ) ;
std::thread t( &ResolverFuture::run , f ) ;
...
t.join() ;
Address a = f.get().first ;
if( f.error() ) throw std::runtime_error( f.reason() ) ;
ResolverFuture(const std::string &host, const std::string &service, int family, bool dgram, bool for_async_hint=false)
Constructor for resolving the given host and service names.
ResolverFuture & run() noexcept
Does the synchronous name resolution and stores the result.

Definition at line 56 of file gresolverfuture.h.

Member Typedef Documentation

◆ List

using GNet::ResolverFuture::List = std::vector<Address>

Definition at line 60 of file gresolverfuture.h.

◆ Pair

using GNet::ResolverFuture::Pair = std::pair<Address,std::string>

Definition at line 59 of file gresolverfuture.h.

Constructor & Destructor Documentation

◆ ResolverFuture()

GNet::ResolverFuture::ResolverFuture ( const std::string &  host,
const std::string &  service,
int  family,
bool  dgram,
bool  for_async_hint = false 
)

Constructor for resolving the given host and service names.

Definition at line 30 of file gresolverfuture.cpp.

◆ ~ResolverFuture()

GNet::ResolverFuture::~ResolverFuture ( )

Destructor.

Definition at line 51 of file gresolverfuture.cpp.

Member Function Documentation

◆ error()

bool GNet::ResolverFuture::error ( ) const

Returns true if name resolution failed or no suitable address was returned.

Use after get().

Definition at line 146 of file gresolverfuture.cpp.

◆ get() [1/2]

GNet::ResolverFuture::Pair GNet::ResolverFuture::get ( )

Returns the resolved address/name pair after run() has completed.

Returns default values if an error().

Definition at line 136 of file gresolverfuture.cpp.

◆ get() [2/2]

void GNet::ResolverFuture::get ( List &  list)

Returns the resolved addresses after run() has completed by appending to the given list.

Appends nothing if an error().

Definition at line 128 of file gresolverfuture.cpp.

◆ reason()

std::string GNet::ResolverFuture::reason ( ) const

Returns the reason for the error().

Precondition: error()

Definition at line 151 of file gresolverfuture.cpp.

◆ run()

GNet::ResolverFuture & GNet::ResolverFuture::run ( )
noexcept

Does the synchronous name resolution and stores the result.

Returns *this.

Definition at line 57 of file gresolverfuture.cpp.


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