GNet::HeapClient Class Reference

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

#include <gheapclient.h>

Inheritance diagram for GNet::HeapClient:

GNet::SimpleClient GNet::EventHandler GNet::Connection GNet::SocketProtocolSink GNet::Client GSmtp::Client GSmtp::RequestClient GSmtp::SpamClient

List of all members.

Public Member Functions

 HeapClient (const ResolverInfo &remote_info, const Address &local_interface=Address(0U), bool privileged=false, bool sync_dns=synchronousDnsDefault())
 Constructor.
void doDelete (const std::string &reason)
 Calls onDelete() and then does "delete this".
virtual void onException (std::exception &)
 Final override from GNet::EventHandler.

Protected Member Functions

virtual ~HeapClient ()
 Destructor.
virtual void onDelete (const std::string &reason, bool can_retry)=0
 Called just before deletion.
virtual void onDeleteImp (const std::string &reason, bool can_retry)
 An alternative to onDelete() for private implementation classes.
virtual void onConnecting ()
 Called just before the connection is initiated.


Detailed Description

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

Note that 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. The doDelete() method starts another zero-length timer in order to delete the instance once the stack has unwound.

Note that most errors and exceptions result in HeapClient objects deleting themselves. This is similar to the way the ServerPeer class works on the server side. Exceptions thrown out of event loop callbacks result in the relevant HeapClient object deleting itself. This means that the connection gets destroyed without terminating the application. However, if a second nested exception is thrown out of (eg.) onDelete() then the event loop will terminate.

Definition at line 52 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() 
) [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 35 of file gheapclient.cpp.


Member Function Documentation

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

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

Definition at line 57 of file gheapclient.cpp.

References GNet::SimpleClient::canRetry(), onDelete(), and onDeleteImp().

Referenced by GSmtp::Client::onConnect(), and onException().

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

Final override from GNet::EventHandler.

Implements GNet::EventHandler.

Definition at line 70 of file gheapclient.cpp.

References doDelete(), and G_WARNING.

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

Called just before deletion.

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

Referenced by doDelete().

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 76 of file gheapclient.cpp.

Referenced by doDelete().

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 80 of file gheapclient.cpp.


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

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5