VideoTools
|
A class for making an outgoing connection to a remote server, with support for socket-level protocols such as TLS/SSL and SOCKS 4a. More...
#include <gsimpleclient.h>
Public Types | |
enum | ConnectStatus { Success, Failure, ImmediateSuccess } |
enum | State { Idle, Resolving, Connecting, Connected, Socksing, Testing } |
typedef std::string::size_type | size_type |
Public Member Functions | |
SimpleClient (const Location &remote_info, bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U) | |
Constructor. | |
void | connect () |
Initates a connection to the remote server. More... | |
bool | connected () const |
Returns true if connected to the peer. | |
virtual std::pair< bool, Address > | localAddress () const override |
Override from Connection. More... | |
virtual std::pair< bool, Address > | peerAddress () const override |
Override from Connection. More... | |
virtual std::string | peerCertificate () const override |
Returns the peer's TLS certificate. More... | |
Location | remoteLocation () const |
Returns a Location structure containing the result of host() and service() name lookup if available. More... | |
void | updateLocation (const Location &) |
Updates the constructor's Location object with the given one as long as both objects have the same host and service name. More... | |
virtual void | readEvent () override |
Override from GNet::EventHandler. | |
virtual void | writeEvent () override |
Override from GNet::EventHandler. | |
bool | send (const std::string &data, std::string::size_type offset=0) |
Returns true if all sent, or false if flow control was asserted. More... | |
Public Member Functions inherited from GNet::EventHandler | |
virtual | ~EventHandler () |
Destructor. | |
virtual void | exceptionEvent () |
Called for a socket-exception event. More... | |
Public Member Functions inherited from GNet::EventExceptionHandler | |
virtual void | onException (std::exception &)=0 |
Called by the event loop when an exception is thrown out of an event loop callback. More... | |
Public Member Functions inherited from GNet::Connection | |
virtual | ~Connection () |
Destructor. | |
Public Member Functions inherited from GNet::SocketProtocolSink | |
virtual | ~SocketProtocolSink () |
Destructor. | |
Static Public Member Functions | |
static bool | synchronousDnsDefault () |
Returns true if DNS queries should normally be synchronous on this platform. More... | |
Protected Member Functions | |
virtual | ~SimpleClient () |
Destructor. | |
StreamSocket & | socket () |
Returns a reference to the socket. Throws if not connected. | |
const StreamSocket & | socket () const |
Returns a const reference to the socket. Throws if not connected. | |
virtual void | onConnect ()=0 |
Called once connected. | |
virtual void | onConnectImp () |
An alternative to onConnect() for private implementation classes. More... | |
virtual void | onSendComplete ()=0 |
Called when all residual data from send() has been sent. | |
virtual void | onSendImp () |
Called from within send(). | |
void | sslConnect () |
Starts TLS/SSL client-side negotiation. | |
std::string | logId () const |
Returns a identification string for logging purposes. More... | |
Protected Member Functions inherited from GNet::EventExceptionHandler | |
virtual | ~EventExceptionHandler () |
Destructor. | |
Protected Member Functions inherited from GNet::SocketProtocolSink | |
virtual void | onData (const char *, size_t)=0 |
Called when data is read from the socket. | |
virtual void | onSecure (const std::string &peer_certificate)=0 |
Called once the secure socket protocol has been successfully negotiated. More... | |
Static Protected Member Functions | |
static bool | connectError (const std::string &reason) |
Returns true if the reason string implies the SimpleClient::connect() failed. More... | |
A class for making an outgoing connection to a remote server, with support for socket-level protocols such as TLS/SSL and SOCKS 4a.
The class handles name-to-address resolution, deals with connection issues, reads incoming data, and manages flow-control when sending. The implementation uses the SocketProtocol class in order to do TLS/SSL; see sslConnect().
Name-to-address lookup is performed if the supplied Location object does not contain an address. This can be done synchronously or asynchronously. The results of the lookup can be obtained via the remoteLocation() method and possibly fed back to the next SimpleClient that connects to the same host/service in order to implement name lookup cacheing (see GNet::ClientPtr). However, most operating systems implement their own name lookup cacheing, so this is not terribly useful in practice.
Definition at line 60 of file gsimpleclient.h.
void GNet::SimpleClient::connect | ( | ) |
Initates a connection to the remote server.
Calls back to onConnect() when complete (non-reentrantly). Throws on error.
Definition at line 102 of file gsimpleclient.cpp.
|
staticprotected |
Returns true if the reason string implies the SimpleClient::connect() failed.
Definition at line 272 of file gsimpleclient.cpp.
|
overridevirtual |
Override from Connection.
Returns the local address. Pair.first is false on error. Override from GNet::Connection.
Implements GNet::Connection.
Definition at line 305 of file gsimpleclient.cpp.
|
protected |
Returns a identification string for logging purposes.
Not guaranteed to stay the same during the lifetime of the object.
Definition at line 66 of file gsimpleclient.cpp.
|
protectedvirtual |
An alternative to onConnect() for private implementation classes.
The default implementation does nothing.
Reimplemented in GNet::Client.
Definition at line 333 of file gsimpleclient.cpp.
|
overridevirtual |
Override from Connection.
Returns the peer address. Pair.first is false on error. Override from GNet::Connection.
Implements GNet::Connection.
Definition at line 313 of file gsimpleclient.cpp.
|
overridevirtual |
Returns the peer's TLS certificate.
Override from GNet::Connection.
Implements GNet::Connection.
Definition at line 321 of file gsimpleclient.cpp.
GNet::Location GNet::SimpleClient::remoteLocation | ( | ) | const |
Returns a Location structure containing the result of host() and service() name lookup if available.
Definition at line 74 of file gsimpleclient.cpp.
bool GNet::SimpleClient::send | ( | const std::string & | data, |
std::string::size_type | offset = 0 |
||
) |
Returns true if all sent, or false if flow control was asserted.
Throws on error.
Definition at line 337 of file gsimpleclient.cpp.
|
static |
Returns true if DNS queries should normally be synchronous on this platform.
Used to default the relevant constructor parameter.
Definition at line 388 of file gsimpleclient.cpp.
void GNet::SimpleClient::updateLocation | ( | const Location & | update | ) |
Updates the constructor's Location object with the given one as long as both objects have the same host and service name.
This is only useful immediately after construction and before re-entering the event loop.
Definition at line 79 of file gsimpleclient.cpp.