A class for asynchronous TCP name-to-address resolution. More...
#include <gresolver.h>
Public Member Functions | |
Resolver (EventHandler &) | |
Constructor taking an event handler reference. More... | |
virtual | ~Resolver () |
Virtual destructor. More... | |
bool | resolveReq (std::string name, bool udp=false) |
Initiates a name-to-address resolution. More... | |
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. More... | |
virtual void | resolveCon (bool success, const Address &address, std::string fqdn_or_failure_reason) |
Called when the resolution process is complete. More... | |
bool | busy () const |
Returns true if there is a pending resolve request. More... | |
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. More... | |
static std::string | resolve (ResolverInfo &host_and_service, bool udp=false) |
Does syncronous name resolution. More... | |
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.
|
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 178 of file gresolver_unix.cpp.
|
virtual |
Virtual destructor.
Definition at line 183 of file gresolver_unix.cpp.
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 217 of file gresolver_unix.cpp.
|
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 := <n-1>.<n-2>.<n-3>.<n-4> for ipv4
Definition at line 61 of file gresolver.cpp.
Referenced by GSmtp::FactoryParser::check().
|
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(), GNet::ResolverInfo::service(), G::Str::toUInt(), and GNet::Address::validPort().
Referenced by GNet::SimpleClient::connect().
|
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 212 of file gresolver_unix.cpp.
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 188 of file gresolver_unix.cpp.
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 198 of file gresolver_unix.cpp.