- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
GNet::ClientPtr< TClient > Class Template Reference

A smart pointer class for GNet::HeapClient. More...

`#include <gclientptr.h>`

## Public Member Functions
| ClientPtr (TClient *p=NULL, bool preserve_resolver_info=false)
| Constructor. More...
| ~ClientPtr ()
| Destructor. More...
bool | busy () const
| Returns true if the pointer is not NULL. More...
void | reset (TClient *p=NULL)
| Resets the pointer. More...
TClient * | get ()
| Returns the pointer, or NULL if deleted. More...
TClient * | operator-> ()
| Returns the pointer. Throws if deleted. More...
const TClient * | operator-> () const
| Returns the pointer. Throws if deleted. More...
G::Signal2< std::string, bool > & | doneSignal ()
| Returns a signal which indicates that client processing is complete and the client instance has deleted itself. More...
G::Signal2< std::string, std::string > & | eventSignal ()
| Returns a signal which indicates something interesting. More...
G::Signal0 & | connectedSignal ()
| Returns a signal which indicates that the connection has been established successfully. More...
ResolverInfo | resolverInfo () const
| Returns the current or last client's ResolverInfo. More...
void | releaseForExit ()
| Can be called on program termination when there may be no TimerList or EventLoop instances. More...
void | cleanupForExit ()
| Can be called on program termination when there may be no TimerList or EventLoop instances. More...

## Detailed Description

### template<typename TClient>
class GNet::ClientPtr< TClient >

A smart pointer class for GNet::HeapClient.

Keeps track of when the contained instance deletes itself and also does some signal forwarding so that the user of the smart pointer can work with the smart pointers signals and not worry about the client objects' signals.

When the smart pointer goes out of scope while it is managing a client object then the client object is told to delete itself asynchronously using the HeapClient class's doDelete() mechanism.

The smart pointer also optionally maintains an internal ResolverInfo object so that name resolution results can be retained from one contained client object to the next. If the smart pointer is loaded with a new client that has the same host and service name in its ResolverInfo as the previous client then the resolved address is propagated into the new client so that name lookup is short-circuited within the SimpleClient code. The danger with this is that the name lookup becomes stale, so it is probably only a good idea for local addresses and/or short-lived objects.

Definition at line 60 of file gclientptr.h.

## Constructor & Destructor Documentation

template<typename TClient>

GNet::ClientPtr< TClient >::ClientPtr | ( | TClient * | p = `NULL`,
|  | bool | preserve_resolver_info = `false`
| ) |  |
| explicit

Constructor.

< should p->doDelete() here

Definition at line 133 of file gclientptr.h.

template<typename TClient >

GNet::ClientPtr< TClient >::~ClientPtr | ( |  | ) |

Destructor.

Definition at line 154 of file gclientptr.h.

## Member Function Documentation

template<typename TClient >

bool GNet::ClientPtr< TClient >::busy | ( |  | ) | const

Returns true if the pointer is not NULL.

Definition at line 275 of file gclientptr.h.

template<typename TClient >

void GNet::ClientPtr< TClient >::cleanupForExit | ( |  | ) |

Can be called on program termination when there may be no TimerList or EventLoop instances.

The client is destructed so all relevant destructors should avoid doing anything with timers or the network (possibly even just closing sockets).

Definition at line 174 of file gclientptr.h.

template<typename TClient >

G::Signal0 & GNet::ClientPtr< TClient >::connectedSignal | ( |  | ) |

Returns a signal which indicates that the connection has been established successfully.

Definition at line 229 of file gclientptr.h.

template<typename TClient >

G::Signal2< std::string, bool > & GNet::ClientPtr< TClient >::doneSignal | ( |  | ) |

Returns a signal which indicates that client processing is complete and the client instance has deleted itself.

The first signal parameter is the failure reason and the second is a 'can-retry' flag.

Definition at line 217 of file gclientptr.h.

Referenced by GSmtp::AdminServerPeer::AdminServerPeer(), GSmtp::ProtocolMessageForward::ProtocolMessageForward(), and Main::Run::Run().

template<typename TClient >

G::Signal2< std::string, std::string > & GNet::ClientPtr< TClient >::eventSignal | ( |  | ) |

Returns a signal which indicates something interesting.

Definition at line 223 of file gclientptr.h.

Referenced by Main::Run::Run().

template<typename TClient >

TClient * GNet::ClientPtr< TClient >::get | ( |  | ) |

Returns the pointer, or NULL if deleted.

Definition at line 269 of file gclientptr.h.

template<typename TClient >

TClient * GNet::ClientPtr< TClient >::operator-> | ( |  | ) |

Returns the pointer. Throws if deleted.

Definition at line 281 of file gclientptr.h.

template<typename TClient >

const TClient * GNet::ClientPtr< TClient >::operator-> | ( |  | ) | const

Returns the pointer. Throws if deleted.

Definition at line 289 of file gclientptr.h.

template<typename TClient >

void GNet::ClientPtr< TClient >::releaseForExit | ( |  | ) |

Can be called on program termination when there may be no TimerList or EventLoop instances.

The client object leaks.

Definition at line 164 of file gclientptr.h.

template<typename TClient>

void GNet::ClientPtr< TClient >::reset | ( | TClient * | p = `NULL` | ) |

Resets the pointer.

Definition at line 197 of file gclientptr.h.

template<typename TClient >

ResolverInfo GNet::ClientPtr< TClient >::resolverInfo | ( |  | ) | const

Returns the current or last client's ResolverInfo.

Definition at line 297 of file gclientptr.h.

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

- gclientptr.h