26 unsigned int response_timeout ,
unsigned int secure_connection_timeout ,
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,*this) ,
35 m_response_timer(*this,&
Client::onResponseTimeout,*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() ;
57 m_event_signal.emit(
"connected" , remoteLocation().address().displayString() +
" " + remoteLocation().name() ) ;
62 m_connection_timer.cancelTimer() ;
63 m_response_timer.cancelTimer() ;
64 m_event_signal.emit( reason.empty() ?
"done" :
"failed" , reason ) ;
65 m_done_signal.emit( reason ) ;
70 if( m_response_timeout != 0U )
71 m_response_timer.startTimer( m_response_timeout ) ;
74 void GNet::Client::onConnectionTimeout()
76 doDelete(
"connection timeout after " +
G::Str::fromUInt(m_connection_timeout) +
"s connecting to " + remoteLocation().displayString() ) ;
79 void GNet::Client::onResponseTimeout()
81 doDelete(
"response timeout after " +
G::Str::fromUInt(m_response_timeout) +
"s talking to " + remoteLocation().displayString() ) ;
86 return m_done_signal ;
91 return m_event_signal ;
96 return m_connected_signal ;
101 m_line_buffer.add( p , n ) ;
104 for(
bool first =
true ; iter.
more() ; first = false )
106 if( first && m_response_timeout != 0U )
107 m_response_timer.cancelTimer() ;
117 return m_line_buffer.eol() ;
std::string lineBufferEndOfLine() const
Returns the line buffer end-of-line string.
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.
const char * lineData() const
See LineBuffer::lineData().
G::Slot::Signal2< std::string, std::string > & eventSignal()
Returns a signal that indicates that something interesting has happened.
virtual ~Client()
Destructor.
Syntactic sugar for calling GNet::LineBuffer iteration methods.
size_t eolSize() const
See LineBuffer::eolSize().
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.
static std::string fromUInt(unsigned int ui)
Converts unsigned int 'ui' to a string.
A configuration structure for GNet::LineBuffer.
void clearInput()
Clears the line buffer.
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.
size_t lineSize() const
See LineBuffer::lineSize().
A signal class for zero-parameter callbacks.
virtual void onSendImp() override
Override from GNet::SimpleClient.
Client(const Location &remote_info, unsigned int connection_timeout=0U, unsigned int response_timeout=0U, unsigned int secure_connection_timeout=0U, LineBufferConfig=LineBufferConfig(), bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault())
Constructor. The connection is initiated asynchronously.
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()
See LineBuffer::more().