26 unsigned int response_timeout ,
unsigned int secure_connection_timeout ,
27 const std::string & eol ,
bool bind_local_address ,
const Address & local_address ,
29 HeapClient(remote_info,bind_local_address,local_address,sync_dns,secure_connection_timeout) ,
31 m_connected_signal(true) ,
32 m_connection_timeout(connection_timeout) ,
33 m_response_timeout(response_timeout) ,
34 m_connection_timer(*this,&
Client::onConnectionTimeout,*static_cast<
EventHandler*>(this)) ,
38 if( connection_timeout != 0U )
39 m_connection_timer.startTimer( connection_timeout ) ;
48 m_event_signal.emit(
"connecting" , remoteLocation().displayString() ) ;
53 if( m_connection_timeout != 0U )
54 m_connection_timer.cancelTimer() ;
56 m_connected_signal.emit() ;
58 m_event_signal.emit(
"connected" , remoteLocation().address().displayString() +
" " + remoteLocation().name() ) ;
63 m_connection_timer.cancelTimer() ;
64 m_response_timer.cancelTimer() ;
65 m_event_signal.emit( reason.empty() ?
"done" :
"failed" , reason ) ;
66 m_done_signal.emit( reason ) ;
71 if( m_response_timeout != 0U )
72 m_response_timer.startTimer( m_response_timeout ) ;
75 void GNet::Client::onConnectionTimeout()
77 doDelete(
"connection timeout" ) ;
80 void GNet::Client::onResponseTimeout()
82 doDelete(
"response timeout" ) ;
87 return m_done_signal ;
92 return m_event_signal ;
97 return m_connected_signal ;
102 return m_secure_signal ;
107 m_line_buffer.add(p,n) ;
110 for(
bool first =
true ; iter.
more() ; first = false )
112 if( first && m_response_timeout != 0U )
113 m_response_timer.cancelTimer() ;
115 bool ok = onReceive( iter.
line() ) ;
G::Slot::Signal0 & connectedSignal()
Returns a signal that indicates that the client has successfully connected to the server...
virtual void onConnecting() override
Override from GNet::HeapClient.
virtual void onDeleteImp(const std::string &reason) override
Override from GNet::HeapClient.
virtual void onConnectImp() override
Override from GNet::SimpleClient.
The GNet::Address class encapsulates a TCP/UDP transport address.
G::Slot::Signal2< std::string, std::string > & eventSignal()
Returns a signal that indicates that something interesting has happened.
virtual ~Client()
Destructor.
An iterator class for GNet::LineBuffer that extracts complete lines.
A class that holds a host/service name pair and the preferred address family (if any), and also the results of a name-to-address lookup, ie.
void clearInput()
Clears any pending input from the server.
A SimpleClient class for client objects that manage their own lifetime on the heap.
G::Slot::Signal1< std::string > & doneSignal()
Returns a signal that indicates that client processing is complete.
A base class for classes that handle asynchronous events from the event loop.
A signal class for zero-parameter callbacks.
const std::string & line() const
Returns the current line.
Client(const Location &remote_info, unsigned int connection_timeout=0U, unsigned int response_timeout=0U, unsigned int secure_connection_timeout=0U, const std::string &eol=std::string("\n"), bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault())
Constructor.
G::Slot::Signal0 & secureSignal()
Returns a signal that indicates that the security layer has been successfully established.
virtual void onSendImp() override
Override from GNet::SimpleClient.
A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.
virtual void onData(const char *, SimpleClient::size_type) override
Override from GNet::SocketProtocolSink.
bool more()
Returns true if there is a line() to be had.