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>

Classes

struct  Result
 Result structure for GNet::ResolverFuture::get(). More...
 

Public Types

using List = std::vector< Address >
 

Public Member Functions

 ResolverFuture (const std::string &host, const std::string &service, int family, const Resolver::Config &)
 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...
 
Result get ()
 Returns the resolved address after run() has completed. More...
 
void get (List &)
 Returns by reference 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
 
ResolverFutureoperator= (const ResolverFuture &)=delete
 
ResolverFutureoperator= (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, const Resolver::Config &)
Constructor for resolving the given host and service names.
ResolverFuture & run() noexcept
Does the synchronous name resolution and stores the result.

Definition at line 57 of file gresolverfuture.h.

Member Typedef Documentation

◆ List

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

Definition at line 65 of file gresolverfuture.h.

Constructor & Destructor Documentation

◆ ResolverFuture()

GNet::ResolverFuture::ResolverFuture ( const std::string &  host,
const std::string &  service,
int  family,
const Resolver::Config config 
)

Constructor for resolving the given host and service names.

Definition at line 32 of file gresolverfuture.cpp.

◆ ~ResolverFuture()

GNet::ResolverFuture::~ResolverFuture ( )

Destructor.

Definition at line 54 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 159 of file gresolverfuture.cpp.

◆ get() [1/2]

GNet::ResolverFuture::Result GNet::ResolverFuture::get ( )

Returns the resolved address after run() has completed.

Returns a default address if an error().

Definition at line 149 of file gresolverfuture.cpp.

◆ get() [2/2]

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

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

Appends nothing if an error().

Definition at line 141 of file gresolverfuture.cpp.

◆ reason()

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

Returns the reason for the error().

Precondition: error()

Definition at line 164 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 70 of file gresolverfuture.cpp.


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