78 G_EXCEPTION( DnsError ,
tx(
"dns error") ) ;
79 G_EXCEPTION( ConnectError ,
tx(
"connect failure") ) ;
80 G_EXCEPTION( NotConnected ,
tx(
"socket not connected") ) ;
81 G_EXCEPTION( ResponseTimeout ,
tx(
"response timeout") ) ;
82 G_EXCEPTION( IdleTimeout ,
tx(
"idle timeout") ) ;
90 bool sync_dns {
false} ;
91 bool auto_start {
true} ;
92 bool bind_local_address {
false} ;
93 unsigned int connection_timeout {0U} ;
94 unsigned int response_timeout {0U} ;
95 unsigned int idle_timeout {0U} ;
96 bool no_throw_on_peer_disconnect {
false} ;
101 Config & set_sync_dns(
bool =
true ) noexcept ;
102 Config & set_auto_start(
bool =
true ) noexcept ;
103 Config & set_bind_local_address(
bool =
true ) noexcept ;
105 Config & set_connection_timeout(
unsigned int ) noexcept ;
106 Config & set_secure_connection_timeout(
unsigned int ) noexcept ;
107 Config & set_response_timeout(
unsigned int ) noexcept ;
108 Config & set_idle_timeout(
unsigned int ) noexcept ;
109 Config & set_all_timeouts(
unsigned int ) noexcept ;
110 Config & set_no_throw_on_peer_disconnect(
bool =
true ) noexcept ;
164 bool send(
const std::string & data ) ;
174 bool send(
const std::vector<G::string_view> & data , std::size_t offset = 0 ) ;
228 virtual
bool onReceive( const
char * data ,
std::
size_t size ,
std::
size_t eolsize ,
std::
size_t linesize ,
char c0 ) = 0 ;
257 void readEvent() override ;
258 void writeEvent() override ;
260 void onResolved(
std::
string ,
Location ) override ;
261 void onData( const
char * ,
std::
size_t ) override ;
262 void onPeerDisconnect() override ;
269 bool send( const
char * ,
std::
size_t ) = delete ;
270 bool send( const
char * ) = delete ;
271 bool send( const
std::
string & ,
std::
size_t ) = delete ;
284 bool onDataImp(
const char * , std::size_t , std::size_t , std::size_t ,
char ) ;
285 void emit(
const std::string & ) ;
286 void startConnecting() ;
287 void bindLocalAddress(
const Address & ) ;
288 void setState( State ) ;
289 void onStartTimeout() ;
290 void onConnectTimeout() ;
291 void onConnectedTimeout() ;
292 void onResponseTimeout() ;
293 void onIdleTimeout() ;
299 const Config m_config ;
301 std::unique_ptr<StreamSocket> m_socket ;
302 std::unique_ptr<SocketProtocol> m_sp ;
303 std::unique_ptr<Socks> m_socks ;
305 std::unique_ptr<Resolver> m_resolver ;
309 bool m_has_connected ;
318inline GNet::Client::Config & GNet::Client::Config::set_stream_socket_config(
const StreamSocket::Config & cfg ) { stream_socket_config = cfg ;
return *this ; }
319inline GNet::Client::Config & GNet::Client::Config::set_line_buffer_config(
const LineBuffer::Config & cfg ) { line_buffer_config = cfg ;
return *this ; }
320inline GNet::Client::Config & GNet::Client::Config::set_socket_protocol_config(
const SocketProtocol::Config & cfg ) { socket_protocol_config = cfg ;
return *this ; }
321inline GNet::Client::Config & GNet::Client::Config::set_sync_dns(
bool b )
noexcept { sync_dns = b ;
return *this ; }
322inline GNet::Client::Config & GNet::Client::Config::set_auto_start(
bool b )
noexcept { auto_start = b ;
return *this ; }
323inline GNet::Client::Config & GNet::Client::Config::set_bind_local_address(
bool b )
noexcept { bind_local_address = b ;
return *this ; }
324inline GNet::Client::Config & GNet::Client::Config::set_local_address(
const Address & a ) { local_address = a ;
return *this ; }
325inline GNet::Client::Config & GNet::Client::Config::set_connection_timeout(
unsigned int t )
noexcept { connection_timeout = t ;
return *this ; }
326inline GNet::Client::Config & GNet::Client::Config::set_secure_connection_timeout(
unsigned int t )
noexcept { socket_protocol_config.secure_connection_timeout = t ;
return *this ; }
327inline GNet::Client::Config & GNet::Client::Config::set_response_timeout(
unsigned int t )
noexcept { response_timeout = t ;
return *this ; }
328inline GNet::Client::Config & GNet::Client::Config::set_idle_timeout(
unsigned int t )
noexcept { idle_timeout = t ;
return *this ; }
329inline 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.
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.
Client(ExceptionSink, const Location &remote_location, const Config &)
Constructor.
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 just before ClientPtr destroys the Client as the result of handling an exception.
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 tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
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 timer class template in which the timeout is delivered to the specified method.
A linked list of CallFrame pointers.
A class like c++17's std::string_view.
constexpr const char * tx(const char *p)
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.