VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GNet::HeapClient Class Referenceabstract

A SimpleClient class for client objects that manage their own lifetime on the heap. More...

#include <gheapclient.h>

+ Inheritance diagram for GNet::HeapClient:

Public Member Functions

 HeapClient (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. More...
 
void doDelete (const std::string &reason)
 Calls onDelete() and then does a delayed "delete this".
 
void doDeleteForExit ()
 A destructor method that may be called at program termination when the normal doDelete() mechanism has become unusable. More...
 
- Public Member Functions inherited from GNet::SimpleClient
 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, AddresslocalAddress () const override
 Override from Connection. More...
 
virtual std::pair< bool, AddresspeerAddress () 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::Connection
virtual ~Connection ()
 Destructor.
 
- Public Member Functions inherited from GNet::SocketProtocolSink
virtual ~SocketProtocolSink ()
 Destructor.
 

Protected Member Functions

virtual ~HeapClient ()
 Destructor.
 
virtual void onDelete (const std::string &reason)=0
 Called just before deletion.
 
virtual void onDeleteImp (const std::string &reason)
 An alternative to onDelete() for private implementation classes. More...
 
virtual void onConnecting ()
 Called just before the connection is initiated. More...
 
virtual void onException (std::exception &) g__final override
 Override from GNet::EventExceptionHandler. More...
 
- Protected Member Functions inherited from GNet::SimpleClient
virtual ~SimpleClient ()
 Destructor.
 
StreamSocketsocket ()
 Returns a reference to the socket. Throws if not connected.
 
const StreamSocketsocket () 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...
 

Additional Inherited Members

- Public Types inherited from GNet::SimpleClient
enum  ConnectStatus { Success, Failure, ImmediateSuccess }
 
enum  State {
  Idle, Resolving, Connecting, Connected,
  Socksing, Testing
}
 
typedef std::string::size_type size_type
 
- Static Public Member Functions inherited from GNet::SimpleClient
static bool synchronousDnsDefault ()
 Returns true if DNS queries should normally be synchronous on this platform. More...
 
- Static Protected Member Functions inherited from GNet::SimpleClient
static bool connectError (const std::string &reason)
 Returns true if the reason string implies the SimpleClient::connect() failed. More...
 

Detailed Description

A SimpleClient class for client objects that manage their own lifetime on the heap.

HeapClients are instantiated on the heap and should be deleted by calling their doDelete() method. The doDelete() implementation starts a zero-length timer which does "delete this" when it expires, so it is safe to call doDelete() from within event callbacks.

This class automatically starts connecting after construction using a zero-length timer, so there is no need to call the base class's connect() method.

When the event loop delivers an event callback to a HeapClient and the HeapClient throws a std::exception back up to the event loop the event loop calls the HeapClient again via onException(). The implementation of onException() in HeapClient causes the HeapClient to self-destruct. As a result, the client code can just throw an exception to terminate the connection and delete itself.

Definition at line 54 of file gheapclient.h.

Constructor & Destructor Documentation

GNet::HeapClient::HeapClient ( 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 
)
explicit

Constructor.

All instances must be on the heap. Initiates the connection via a zero-length timer.

Definition at line 26 of file gheapclient.cpp.

Member Function Documentation

void GNet::HeapClient::doDeleteForExit ( )

A destructor method that may be called at program termination when the normal doDelete() mechanism has become unusable.

Definition at line 58 of file gheapclient.cpp.

void GNet::HeapClient::onConnecting ( )
protectedvirtual

Called just before the connection is initiated.

Overridable. The default implementation does nothing.

Reimplemented in GNet::Client.

Definition at line 86 of file gheapclient.cpp.

void GNet::HeapClient::onDeleteImp ( const std::string &  reason)
protectedvirtual

An alternative to onDelete() for private implementation classes.

Gets called before onDelete(). The default implementation does nothing.

Reimplemented in GNet::Client.

Definition at line 82 of file gheapclient.cpp.

void GNet::HeapClient::onException ( std::exception &  e)
overrideprotectedvirtual

Override from GNet::EventExceptionHandler.

Calls doDelete(). Note that the exception text is available via onDelete().

Implements GNet::EventExceptionHandler.

Definition at line 76 of file gheapclient.cpp.


The documentation for this class was generated from the following files: