- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

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 ResolverInfo &remote_info, const Address &local_interface=Address(0U), bool privileged=false, 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". More...
virtual void | onException (std::exception &)
| Final override from GNet::EventHandler. More...
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 ResolverInfo &remote_info, const Address &local_address=Address(0U), bool privileged=false, bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U)
| Constructor. More...
void | connect ()
| Initates a connection to the remote server. More...
bool | connected () const
| Returns true if connected to the peer. More...
virtual std::pair< bool, Address > | localAddress () const
| Override from Connection. More...
virtual std::pair< bool, Address > | peerAddress () const
| Override from Connection. More...
virtual std::string | peerCertificate () const
| Returns the peer's TLS certificate. More...
ResolverInfo | resolverInfo () const
| Returns a ResolverInfo structure containing the result of host() and service() name lookup if available. More...
void | updateResolverInfo (const ResolverInfo &)
| Updates the constructor's ResolverInfo object with the given one as long as both objects have the same host and service name. More...
virtual void | readEvent ()
| Final override from GNet::EventHandler. More...
virtual void | writeEvent ()
| Final override from GNet::EventHandler. More...
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. More...
virtual void | exceptionEvent ()
| Called for an exception event. More...
Public Member Functions inherited from GNet::Connection
virtual | ~Connection ()
| Destructor. More...
Public Member Functions inherited from GNet::SocketProtocolSink
virtual | ~SocketProtocolSink ()
| Destructor. More...

## Protected Member Functions
virtual | ~HeapClient ()
| Destructor. More...
virtual void | onDelete (const std::string &reason, bool can_retry)=0
| Called just before deletion. More...
virtual void | onDeleteImp (const std::string &reason, bool can_retry)
| An alternative to onDelete() for private implementation classes. More...
virtual void | onConnecting ()
| Called just before the connection is initiated. More...
Protected Member Functions inherited from GNet::SimpleClient
virtual | ~SimpleClient ()
| Destructor. More...
StreamSocket & | socket ()
| Returns a reference to the socket. Throws if not connected. More...
const StreamSocket & | socket () const
| Returns a const reference to the socket. Throws if not connected. More...
virtual void | onConnect ()=0
| Called once connected. More...
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. More...
virtual void | onSendImp ()
| Called from within send(). More...
void | sslConnect ()
| Starts TLS/SSL client-side negotiation. More...
std::string | logId () const
| Returns a identification string for logging purposes. More...
Protected Member Functions inherited from GNet::SocketProtocolSink
virtual void | onData (const char *, std::string::size_type)=0
| Called when data is read from the socket. More...
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, Retry, ImmediateSuccess }
enum | State { Idle, Resolving, Connecting, Connected, Socksing }
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 | canRetry (const std::string &reason)
| Parses the given failure reason and returns true if the client can reasonably retry at some later time. 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() causing 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 ResolverInfo & | remote_info,
|  | const Address & | local_interface = `Address(0U)`,
|  | bool | privileged = `false`,
|  | 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.

GNet::HeapClient::~HeapClient | ( |  | ) |
| protected virtual

Destructor.

Definition at line 36 of file gheapclient.cpp.

## Member Function Documentation

void GNet::HeapClient::doDelete | ( | const std::string & | reason | ) |

Calls onDelete() and then does a delayed "delete this".

Definition at line 63 of file gheapclient.cpp.

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 | ( |  | ) |
| protected virtual

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.

virtual void GNet::HeapClient::onDelete | ( | const std::string & | reason,
|  | bool | can_retry
| ) |  |
| protected pure virtual

Called just before deletion.

Implemented in GSmtp::Client, GSmtp::RequestClient, and GSmtp::SpamClient.

void GNet::HeapClient::onDeleteImp | ( | const std::string & | reason,
|  | bool | can_retry
| ) |  |
| protected virtual

An alternative to onDelete() for private implementation classes.

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

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

Definition at line 82 of file gheapclient.cpp.

void GNet::HeapClient::onException | ( | std::exception & | e | ) |
| virtual

Final override from GNet::EventHandler.

Implements GNet::EventHandler.

Definition at line 76 of file gheapclient.cpp.

References G_WARNING.

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

- gheapclient.h
- gheapclient.cpp