37 const unsigned int c_port = 208U ;
58 bool resolveReq( std::string host_part, std::string service_part ,
bool udp ) ;
68 virtual void onSecure(
const std::string & ) ;
80 std::string m_request ;
87 m_event_handler(event_handler) ,
105 if( ! m_request.empty() )
107 m_request = host_part +
":" + service_part +
":" + ( udp ?
"udp" :
"tcp" ) +
"\n" ;
119 if( ! m_request.empty() )
133 m_line_buffer.add( p , n ) ;
134 while( m_line_buffer.more() )
138 std::string result = m_line_buffer.line() ;
139 G_DEBUG(
"GNet::ResolverImp::readEvent: \"" << result <<
"\"" ) ;
142 std::string head = pos == std::string::npos ? result : result.substr(0U,pos) ;
143 std::string tail = pos == std::string::npos ? std::string() : result.substr(pos+1U) ;
147 m_outer.resolveCon(
true ,
Address(head) , tail ) ;
151 std::string reason = result ;
167 m_event_handler.onException( e ) ;
173 return ! m_request.empty() ;
190 std::string host_part ;
191 std::string service_part ;
192 if( ! parse(name,host_part,service_part) )
195 return m_imp->resolveReq( host_part , service_part , udp ) ;
203 if( host_part.length() == 0 )
204 host_part =
"0.0.0.0" ;
206 if( service_part.length() == 0 )
209 return m_imp->resolveReq( host_part , service_part , udp ) ;
219 return m_imp->busy() ;
virtual ~Resolver()
Virtual destructor.
virtual void onSecure(const std::string &)
Called once the secure socket protocol has been successfully negotiated.
static Address localhost(unsigned int port=0U)
Returns a localhost ("loopback") address.
A class for making an outgoing connection to a remote server, with support for socket-level protocols...
virtual void onConnect()
Called once connected.
A class for asynchronous TCP name-to-address resolution.
The Address class encapsulates an IP transport address.
bool resolveReq(std::string host_part, std::string service_part, bool udp)
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
std::string::size_type size_type
A std::size_t type.
static Address invalidAddress()
Returns an invalid address.
virtual void resolveCon(bool success, const Address &address, std::string fqdn_or_failure_reason)
Called when the resolution process is complete.
static void trim(std::string &s, const std::string &ws)
Trims both ends of s, taking off any of the 'ws' characters.
virtual void onSendComplete()
Called when all residual data from send() has been sent.
A base class for classes that handle asynchronous socket events.
virtual void onData(const char *, std::string::size_type)
Called when data is read from the socket.
static bool isPrintableAscii(const std::string &s)
Returns true if every character is a 7-bit, non-control character (ie.
static bool validString(const std::string &display_string, std::string *reason=NULL)
Returns true if the display string is valid.
A class which does line buffering.
bool busy() const
Returns true if there is a pending resolve request.
ResolverInfo resolverInfo() const
Returns a ResolverInfo structure containing the result of host() and service() name lookup if availab...
ResolverImp(EventHandler &event_handler, Resolver &resolver, unsigned int port)
virtual void onException(std::exception &)
Called when an exception is thrown out of readEvent(), writeEvent() or exceptionEvent().
bool resolveReq(std::string name, bool udp=false)
Initiates a name-to-address resolution.
Resolver(EventHandler &)
Constructor taking an event handler reference.
A pimple-pattern implementation class for GNet::Resolver.