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

A 'future' object for asynchronous name resolution, in practice holding just enough state for a single call to getaddrinfo(). More...

#include <gresolverfuture.h>

Public Types

typedef std::pair< Address, std::string > Pair
 
typedef std::vector< Address > List
 

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.
 
 ~ResolverFuture ()
 Destructor.
 
void run ()
 Does the name resolution.
 
Pair get ()
 Returns the resolved address/name pair.
 
void get (List &)
 Returns the list of resolved addresses.
 
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...
 

Detailed Description

A 'future' object for asynchronous name resolution, in practice holding just enough state for a single call to getaddrinfo().

The run() method can be called from a worker thread and the results collected by the main thread with get() once the run() has finished.

Signalling completion from worker thread to main thread is out of scope for 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() ) ;

Definition at line 56 of file gresolverfuture.h.

Member Function Documentation

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.

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

Returns the reason for the error().

Precondition: error()

Definition at line 151 of file gresolverfuture.cpp.


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