80 G_EXCEPTION( DnsError ,
tx(
"dns error") )
81 G_EXCEPTION( ConnectError ,
tx(
"connect failure") )
82 G_EXCEPTION( NotConnected ,
tx(
"socket not connected") )
83 G_EXCEPTION( ResponseTimeout ,
tx(
"response timeout") )
84 G_EXCEPTION( IdleTimeout ,
tx(
"idle timeout") )
92 bool sync_dns {
false} ;
93 bool auto_start {
true} ;
94 bool bind_local_address {
false} ;
95 unsigned int connection_timeout {0U} ;
96 unsigned int response_timeout {0U} ;
97 unsigned int idle_timeout {0U} ;
98 bool no_throw_on_peer_disconnect {
false} ;
103 Config & set_sync_dns(
bool =
true ) noexcept ;
104 Config & set_auto_start(
bool =
true ) noexcept ;
105 Config & set_bind_local_address(
bool =
true ) noexcept ;
107 Config & set_connection_timeout(
unsigned int ) noexcept ;
108 Config & set_response_timeout(
unsigned int ) noexcept ;
109 Config & set_idle_timeout(
unsigned int ) noexcept ;
110 Config & set_all_timeouts(
unsigned int ) noexcept ;
111 Config & set_no_throw_on_peer_disconnect(
bool =
true ) noexcept ;
165 bool send(
const std::string & data ) ;
172 bool send( std::string_view data ) ;
175 bool send(
const std::vector<std::string_view> & data , std::size_t offset = 0 ) ;
229 virtual
bool onReceive( const
char * data ,
std::
size_t size ,
std::
size_t eolsize ,
std::
size_t linesize ,
char c0 ) = 0 ;
259 void readEvent() override ;
260 void writeEvent() override ;
262 void onResolved(
std::
string ,
Location ) override ;
263 void onData( const
char * ,
std::
size_t ) override ;
264 void onPeerDisconnect() override ;
271 bool send( const
char * ,
std::
size_t ) = delete ;
272 bool send( const
char * ) = delete ;
273 bool send( const
std::
string & ,
std::
size_t ) = delete ;
286 bool onDataImp(
const char * , std::size_t , std::size_t , std::size_t ,
char ) ;
287 void emit(
const std::string & ) ;
288 void startConnecting() ;
289 void bindLocalAddress(
const Address & ) ;
290 void setState( State ) ;
291 void onStartTimeout() ;
292 void onConnectTimeout() ;
293 void onConnectedTimeout() ;
294 void onResponseTimeout() ;
295 void onIdleTimeout() ;
301 const Config m_config ;
303 std::unique_ptr<StreamSocket> m_socket ;
304 std::unique_ptr<SocketProtocol> m_sp ;
305 std::unique_ptr<Socks> m_socks ;
307 std::unique_ptr<Resolver> m_resolver ;
309 State m_state {State::Idle} ;
310 bool m_finished {
false} ;
311 bool m_has_connected {
false} ;
312 Timer<Client> m_start_timer ;
313 Timer<Client> m_connect_timer ;
314 Timer<Client> m_connected_timer ;
315 Timer<Client> m_response_timer ;
316 Timer<Client> m_idle_timer ;
318 std::string m_event_logging_string ;
321inline GNet::Client::Config & GNet::Client::Config::set_stream_socket_config(
const StreamSocket::Config & cfg ) { stream_socket_config = cfg ;
return *this ; }
322inline GNet::Client::Config & GNet::Client::Config::set_line_buffer_config(
const LineBuffer::Config & cfg ) { line_buffer_config = cfg ;
return *this ; }
323inline GNet::Client::Config & GNet::Client::Config::set_socket_protocol_config(
const SocketProtocol::Config & cfg ) { socket_protocol_config = cfg ;
return *this ; }
324inline GNet::Client::Config & GNet::Client::Config::set_sync_dns(
bool b )
noexcept { sync_dns = b ;
return *this ; }
325inline GNet::Client::Config & GNet::Client::Config::set_auto_start(
bool b )
noexcept { auto_start = b ;
return *this ; }
326inline GNet::Client::Config & GNet::Client::Config::set_bind_local_address(
bool b )
noexcept { bind_local_address = b ;
return *this ; }
327inline GNet::Client::Config & GNet::Client::Config::set_local_address(
const Address & a ) { local_address = a ;
return *this ; }
328inline GNet::Client::Config & GNet::Client::Config::set_connection_timeout(
unsigned int t )
noexcept { connection_timeout = t ;
return *this ; }
329inline GNet::Client::Config & GNet::Client::Config::set_response_timeout(
unsigned int t )
noexcept { response_timeout = t ;
return *this ; }
330inline GNet::Client::Config & GNet::Client::Config::set_idle_timeout(
unsigned int t )
noexcept { idle_timeout = t ;
return *this ; }
331inline GNet::Client::Config & GNet::Client::Config::set_no_throw_on_peer_disconnect(
bool b )
noexcept { no_throw_on_peer_disconnect = b ;
return *this ; }
The GNet::Address class encapsulates a TCP/UDP transport address.
static Address defaultAddress()
Returns a default address, being the IPv4 wildcard address with a zero port number.
A class for making an outgoing connection to a remote server, with support for socket-level protocols...
virtual void onSendComplete()=0
Called when all residual data from send() has been sent.
void disconnect()
Aborts the connection and destroys the object's internal state, resulting in a zombie object.
std::string peerCertificate() const override
Returns the peer's TLS certificate.
std::string peerAddressString(bool with_port=true) const
Returns the peer address display string or the empty string if not connected().
void secureConnect()
Starts TLS/SSL client-side negotiation.
~Client() override
Destructor.
bool secureConnectCapable() const
Returns true if currently connected and secureConnect() can be used.
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & eventSignal() noexcept
Returns a signal that indicates that something interesting has happened.
Client(EventState, const Location &remote_location, const Config &)
Constructor.
Address localAddress() const override
Returns the local address.
StreamSocket & socket()
Returns a reference to the socket. Throws if not connected.
std::string connectionState() const override
Returns the connection state display string.
bool finished() const
Returns true if finish() has been called.
void finish()
Indicates that the last data has been sent and the client is expecting a peer disconnect.
LineBufferState lineBuffer() const
Returns information about the state of the internal line-buffer.
bool hasConnected() const
Returns true if ever connected().
bool connected() const
Returns true if connected to the peer.
virtual bool onReceive(const char *data, std::size_t size, std::size_t eolsize, std::size_t linesize, char c0)=0
Called with received data.
Location remoteLocation() const
Returns a Location structure, including the result of name lookup if available.
Address peerAddress() const override
Returns the peer address.
bool send(const std::string &data)
Sends data to the peer and starts the response timer (if configured).
virtual void onConnect()=0
Called once connected.
void connect()
Initiates a connection to the remote server.
void doOnDelete(const std::string &reason, bool done)
This should be called by the Client owner (typically ClientPtr) just before this Client object is del...
virtual void onDelete(const std::string &reason)=0
Called from doOnDelete(), typically just before a ClientPtr destroys the Client as the result of hand...
void clearInput()
Clears the input LineBuffer and cancels the response timer if running.
An abstract interface which provides information about a network connection.
A base class for classes that have a file descriptor and handle asynchronous events from the event lo...
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
A mixin base class that identifies the source of an exception when delivered to GNet::ExceptionHandle...
Provides information about the state of a line buffer.
A class that does line buffering, supporting auto-detection of line endings and fixed-size block extr...
A class that represents the remote target for out-going client connections.
An interface used by GNet::SocketProtocol to deliver data from a socket.
A derivation of GNet::Socket for a stream socket.
A linked list of CallFrame pointers.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().
A structure containing GNet::Client configuration parameters.
A configuration structure for GNet::LineBuffer.
An interface used for GNet::Resolver callbacks.
A configuration structure for GNet::SocketProtocol.
A configuration structure for GNet::StreamSocket.