77 G_EXCEPTION( DnsError ,
"dns error" ) ;
78 G_EXCEPTION( ConnectError ,
"connect failure" ) ;
79 G_EXCEPTION( NotConnected ,
"socket not connected" ) ;
80 G_EXCEPTION( ResponseTimeout ,
"response timeout" ) ;
81 G_EXCEPTION( IdleTimeout ,
"idle timeout" ) ;
89 unsigned int secure_connection_timeout ,
unsigned int response_timeout ,
unsigned int idle_timeout ) ;
93 bool auto_start{
true} ;
94 bool bind_local_address{
false} ;
95 unsigned int connection_timeout{0U} ;
96 unsigned int secure_connection_timeout{0U} ;
97 unsigned int response_timeout{0U} ;
98 unsigned int idle_timeout{0U} ;
99 Config & set_sync_dns(
bool =
true ) ;
100 Config & set_auto_start(
bool =
true ) ;
101 Config & set_bind_local_address(
bool =
true ) ;
103 Config & set_connection_timeout(
unsigned int ) ;
104 Config & set_secure_connection_timeout(
unsigned int ) ;
105 Config & set_response_timeout(
unsigned int ) ;
106 Config & set_idle_timeout(
unsigned int ) ;
107 Config & set_all_timeouts(
unsigned int ) ;
139 std::pair<bool,Address>
peerAddress()
const override ;
156 bool send(
const std::string & data , std::size_t offset = 0 ) ;
163 bool send(
const std::vector<G::string_view> & data , std::size_t offset = 0 ) ;
172 void doOnDelete( const std::
string & reason ,
bool done ) ;
193 void finish(
bool with_socket_shutdown ) ;
203 virtual
bool onReceive( const
char * data , std::
size_t size , std::
size_t eolsize , std::
size_t linesize ,
char c0 ) = 0 ;
216 virtual
void onDelete( const std::
string & reason ) = 0 ;
232 void readEvent() override ;
233 void writeEvent() override ;
235 void onResolved( std::
string ,
Location ) override ;
236 void onData( const
char * , std::
size_t ) override ;
241 void operator=( const
Client & ) = delete ;
242 void operator=(
Client && ) = delete ;
245 enum class State { Idle , Resolving , Connecting , Connected , Socksing , Disconnected , Testing } ;
246 bool onDataImp(
const char * , std::size_t , std::size_t , std::size_t ,
char ) ;
247 void emit(
const std::string & ) ;
248 void startConnecting() ;
249 void bindLocalAddress(
const Address & ) ;
250 void setState( State ) ;
251 void onStartTimeout() ;
252 void onConnectTimeout() ;
253 void onConnectedTimeout() ;
254 void onResponseTimeout() ;
255 void onIdleTimeout() ;
262 std::unique_ptr<StreamSocket> m_socket ;
263 std::unique_ptr<SocketProtocol> m_sp ;
264 std::unique_ptr<Socks> m_socks ;
266 std::unique_ptr<Resolver> m_resolver ;
268 bool m_bind_local_address ;
271 unsigned int m_secure_connection_timeout ;
272 unsigned int m_connection_timeout ;
273 unsigned int m_response_timeout ;
274 unsigned int m_idle_timeout ;
277 bool m_has_connected ;
286inline GNet::Client::Config & GNet::Client::Config::set_sync_dns(
bool b ) { sync_dns = b ;
return *this ; }
287inline GNet::Client::Config & GNet::Client::Config::set_auto_start(
bool b ) { auto_start = b ;
return *this ; }
288inline GNet::Client::Config & GNet::Client::Config::set_bind_local_address(
bool b ) { bind_local_address = b ;
return *this ; }
289inline GNet::Client::Config & GNet::Client::Config::set_local_address(
const Address & a ) { local_address = a ;
return *this ; }
290inline GNet::Client::Config & GNet::Client::Config::set_connection_timeout(
unsigned int t ) { connection_timeout = t ;
return *this ; }
291inline GNet::Client::Config & GNet::Client::Config::set_secure_connection_timeout(
unsigned int t ) { secure_connection_timeout = t ;
return *this ; }
292inline GNet::Client::Config & GNet::Client::Config::set_response_timeout(
unsigned int t ) { response_timeout = t ;
return *this ; }
293inline GNet::Client::Config & GNet::Client::Config::set_idle_timeout(
unsigned int t ) { idle_timeout = t ;
return *this ; }
The GNet::Address class encapsulates a TCP/UDP transport address.
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.
void secureConnect()
Starts TLS/SSL client-side negotiation.
bool send(const std::string &data, std::size_t offset=0)
Sends data to the peer and starts the response timer (if configured).
void finish(bool with_socket_shutdown)
Indicates that the last data has been sent and the client is expecting a peer disconnect.
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & eventSignal() noexcept
Returns a signal that indicates that something interesting has happened.
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()ed or disconnect()ed.
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.
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.
std::pair< bool, Address > peerAddress() const override
Override from Connection.
void doOnDelete(const std::string &reason, bool done)
Called by ClientPtr (or equivalent) to call onDelete(), just before this client object is deleted.
std::pair< bool, Address > localAddress() const override
Override from Connection.
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 address information for a network connection.
A base class for classes that handle asynchronous events from the event loop.
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...
A configuration structure for GNet::LineBuffer.
Provides information abount 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 structure containing GNet::Client configuration parameters.
An interface used for GNet::Resolver callbacks.