E-MailRelay
Public Member Functions | Protected Member Functions | List of all members
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".
 
- Public Member Functions inherited from GNet::SimpleClient
 SimpleClient (ExceptionHandler &, 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. Call connect() to start connecting.
 
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 connectionState () const override
 Returns the connection state display string. 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.
 
virtual void otherEvent (EventHandler::Reason) override
 Override from GNet::EventHandler.
 
bool send (const std::string &data, std::string::size_type offset=0)
 Sends data to the peer. More...
 
- Public Member Functions inherited from GNet::EventHandler
virtual ~EventHandler ()
 Destructor.
 
- Public Member Functions inherited from GNet::Connection
virtual ~Connection ()
 Destructor.
 

Protected Member Functions

virtual ~HeapClient ()
 Destructor.
 
void finish ()
 Indicates that the last data has been sent and the client is expecting a peer disconnect. More...
 
virtual void onDelete (const std::string &reason)=0
 Called just before deletion.
 
virtual void onDeleteImp (const std::string &reason)
 An alternative to onDelete() for derived classes in the GNet namespace (in practice GNet::Client). More...
 
virtual void onConnecting ()
 Called just before the connection is initiated. More...
 
virtual void onException (std::exception &) g__final override
 Override from GNet::ExceptionHandler. More...
 
- Protected Member Functions inherited from GNet::ExceptionHandler
virtual ~ExceptionHandler ()
 Destructor.
 
- Protected Member Functions inherited from GNet::SimpleClient
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 secureConnect ()
 Starts TLS/SSL client-side negotiation. More...
 
std::string logId () const
 Returns a identification string for logging purposes. More...
 
 SimpleClient (ExceptionHandler &, 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. Call connect() to start connecting.
 
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 connectionState () const override
 Returns the connection state display string. 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.
 
virtual void otherEvent (EventHandler::Reason) override
 Override from GNet::EventHandler.
 
bool send (const std::string &data, std::string::size_type offset=0)
 Sends data to the peer. More...
 
- Protected Member Functions inherited from GNet::EventHandler
virtual ~EventHandler ()
 Destructor.
 
- Protected Member Functions inherited from GNet::Connection
virtual ~Connection ()
 Destructor.
 

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
 
- Public Types inherited from GNet::EventHandler
enum  Reason {
  reason_closed, reason_down, reason_reset, reason_abort,
  reason_other
}
 
- 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 Public Member Functions inherited from GNet::EventHandler
static std::string str (Reason)
 Returns a printable description of the other-event reason. More...
 
- Protected 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
 
- Protected Types inherited from GNet::EventHandler
enum  Reason {
  reason_closed, reason_down, reason_reset, reason_abort,
  reason_other
}
 
- 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...
 
static bool synchronousDnsDefault ()
 Returns true if DNS queries should normally be synchronous on this platform. More...
 
- Static Protected Member Functions inherited from GNet::EventHandler
static std::string str (Reason)
 Returns a printable description of the other-event reason. 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 53 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 25 of file gheapclient.cpp.

Member Function Documentation

void GNet::HeapClient::finish ( )
protected

Indicates that the last data has been sent and the client is expecting a peer disconnect.

The subsequent onDelete() callback will have an empty reason string. The caller should also consider using Socket::shutdown().

Definition at line 87 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 83 of file gheapclient.cpp.

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

An alternative to onDelete() for derived classes in the GNet namespace (in practice GNet::Client).

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

Reimplemented in GNet::Client, and GSmtp::RequestClient.

Definition at line 79 of file gheapclient.cpp.

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

Override from GNet::ExceptionHandler.

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

Implements GNet::ExceptionHandler.

Definition at line 71 of file gheapclient.cpp.


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