GNet::Resolver Class Reference

A class for asynchronous TCP name-to-address resolution. More...

#include <gresolver.h>

Inheritance diagram for GNet::Resolver:

GNet::ClientResolver

List of all members.

Public Member Functions

 Resolver (EventHandler &)
 Constructor taking an event handler reference.
virtual ~Resolver ()
 Virtual destructor.
bool resolveReq (std::string name, bool udp=false)
 Initiates a name-to-address resolution.
bool resolveReq (std::string host_name, std::string service_name, bool udp=false)
 Alternative form of ResolveReq(std::string,bool) with separate hostname and service name parameters.
virtual void resolveCon (bool success, const Address &address, std::string fqdn_or_failure_reason)
 Called when the resolution process is complete.
bool busy () const
 Returns true if there is a pending resolve request.

Static Public Member Functions

static bool parse (const std::string &in, std::string &host_or_address, std::string &service_or_port)
 Parses a string that contains a hostname or ip address plus a server name or port number.
static std::string resolve (ResolverInfo &host_and_service, bool udp=false)
 Does syncronous name resolution.


Detailed Description

A class for asynchronous TCP name-to-address resolution.

(The motivation for a fully asynchronous interface is so that GUIs and single-threaded servers are not blocked during DNS lookup. However, simple clients, especially those without a GUI, can reasonably use synchronous lookup.)

Definition at line 45 of file gresolver.h.


Constructor & Destructor Documentation

GNet::Resolver::Resolver ( EventHandler event_handler  )  [explicit]

Constructor taking an event handler reference.

The supplied event handler's onException() method is called if an exception is thrown out of (eg.) resolveCon().

Definition at line 171 of file gresolver_unix.cpp.

GNet::Resolver::~Resolver (  )  [virtual]

Virtual destructor.

Definition at line 176 of file gresolver_unix.cpp.


Member Function Documentation

bool GNet::Resolver::parse ( const std::string &  in,
std::string &  host_or_address,
std::string &  service_or_port 
) [static]

Parses a string that contains a hostname or ip address plus a server name or port number.

Returns false if not valid.

The input format should be: {<host-name>|<host-address>}:{<service-name>|<port-number>} where host-address := <n1>.<n2>.<n3>.<n4> for ipv4

Definition at line 61 of file gresolver.cpp.

Referenced by GSmtp::FactoryParser::check(), and resolveReq().

bool GNet::Resolver::resolveReq ( std::string  name,
bool  udp = false 
)

Initiates a name-to-address resolution.

Returns false on error, in which case a confirmation will not be generated.

Postcondition: state == resolving (returns true) Postcondition: state == idle (returns false)

Definition at line 181 of file gresolver_unix.cpp.

References parse(), and GNet::ResolverImp::resolveReq().

bool GNet::Resolver::resolveReq ( std::string  host_name,
std::string  service_name,
bool  udp = false 
)

Alternative form of ResolveReq(std::string,bool) with separate hostname and service name parameters.

A zero-length host_name defaults to "0.0.0.0". A zero-length service name defaults to "0".

Definition at line 191 of file gresolver_unix.cpp.

References GNet::ResolverImp::resolveReq().

void GNet::Resolver::resolveCon ( bool  success,
const Address address,
std::string  fqdn_or_failure_reason 
) [virtual]

Called when the resolution process is complete.

Overridable. This default implementation does nothing. This function is never called from within resolveReq().

Precondition: state == resolving Postcondition: state == idle

Reimplemented in GNet::ClientResolver.

Definition at line 205 of file gresolver_unix.cpp.

Referenced by GNet::ResolverImp::onData(), and GNet::ResolverImp::onException().

bool GNet::Resolver::busy (  )  const

Returns true if there is a pending resolve request.

Postcondition: state == resolving <= returns true Postcondition: state == idle <= returns false

Definition at line 210 of file gresolver_unix.cpp.

References GNet::ResolverImp::busy().

std::string GNet::Resolver::resolve ( ResolverInfo host_and_service,
bool  udp = false 
) [static]

Does syncronous name resolution.

Fills in the name and address fields of the supplied ResolverInfo structure. The returned error string is zero length on success. Not implemented on all platforms.

Definition at line 27 of file gresolver.cpp.

References GNet::ResolverInfo::host(), G::Str::isNumeric(), G::Str::isUInt(), result, GNet::ResolverInfo::service(), G::Str::toUInt(), and GNet::Address::validPort().

Referenced by GNet::SimpleClient::connect().


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

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5