- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | List of all members
GNet::Client Class Referenceabstract

A HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering. More...

`#include <gclient.h>`

Inheritance diagram for GNet::Client:

## Public Member Functions
| Client (const ResolverInfo &remote_info, unsigned int connection_timeout=0U, unsigned int response_timeout=0U, unsigned int secure_connection_timeout=0U, const std::string &eol=std::string("\n"), const Address &local_interface=Address(0U), bool privileged=false, bool sync_dns=synchronousDnsDefault())
| Constructor. More...
G::Signal2< std::string, bool > & | doneSignal ()
| Returns a signal that indicates that client processing is complete. More...
G::Signal2< std::string, std::string > & | eventSignal ()
| Returns a signal that indicates that something interesting has happened. More...
G::Signal0 & | connectedSignal ()
| Returns a signal that incidcates that the client has successfully connected to the server. More...
G::Signal0 & | secureSignal ()
| Returns a signal that incidcates that the security layer has been successfully established. More...
Public Member Functions inherited from 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)
| 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 | ~Client ()
| Destructor. More...
virtual bool | onReceive (const std::string &)=0
| Called when a complete line is received from the peer. More...
void | clearInput ()
| Clears any pending input from the server. More...
virtual void | onDeleteImp (const std::string &, bool)
| Override from GNet::HeapClient. More...
virtual void | onConnectImp ()
| Final override from GNet::SimpleClient. More...
virtual void | onData (const char *, SimpleClient::size_type)
| Final override from GNet::SocketProtocolSink. More...
virtual void | onConnecting ()
| Final override from GNet::HeapClient. More...
virtual void | onSendImp ()
| Final override from GNet::SimpleClient. More...
Protected Member Functions inherited from GNet::HeapClient
virtual | ~HeapClient ()
| Destructor. More...
virtual void | onDelete (const std::string &reason, bool can_retry)=0
| Called just before deletion. 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 | onSendComplete ()=0
| Called when all residual data from send() has been sent. 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 | 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 HeapClient class that adds slot/signal signalling, connection/response timeouts, and input line buffering.

The following pure virtual functions must be implemented by derived classes: onConnect(), onReceive(), onDelete(), and onSendComplete().

The intention is that derived classes use the virtual functions for event notification while the slot/signal event notifications are used by the containing object (in particular so that the container is informed when the client object deletes itself).

Definition at line 51 of file gclient.h.

## Constructor & Destructor Documentation

GNet::Client::Client | ( | const ResolverInfo & | remote_info,
|  | unsigned int | connection_timeout = `0U`,
|  | unsigned int | response_timeout = `0U`,
|  | unsigned int | secure_connection_timeout = `0U`,
|  | const std::string & | eol = `std::string("\n")`,
|  | const Address & | local_interface = `Address(0U)`,
|  | bool | privileged = `false`,
|  | bool | sync_dns = `synchronousDnsDefault()`
| ) |  |
| explicit

Constructor.

Definition at line 25 of file gclient.cpp.

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

Destructor.

Reimplemented in GSmtp::Client.

Definition at line 42 of file gclient.cpp.

## Member Function Documentation

void GNet::Client::clearInput | ( |  | ) |
| protected

Clears any pending input from the server.

Definition at line 122 of file gclient.cpp.

G::Signal0 & GNet::Client::connectedSignal | ( |  | ) |

Returns a signal that incidcates that the client has successfully connected to the server.

Definition at line 95 of file gclient.cpp.

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

Returns a signal that indicates that client processing is complete.

The first signal parameter is a failure reason, or the empty string on success. The second parameter gives some idea of whether the connection can be retried later.

Definition at line 85 of file gclient.cpp.

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

Returns a signal that indicates that something interesting has happened.

Typically used for progress logging.

The first signal parameter is one of "connecting", "connected", "sending", "failed" (on error) or "done" (for normal termination).

Definition at line 90 of file gclient.cpp.

void GNet::Client::onConnectImp | ( |  | ) |
| protected virtual

Final override from GNet::SimpleClient.

Reimplemented from GNet::SimpleClient.

Definition at line 51 of file gclient.cpp.

void GNet::Client::onConnecting | ( |  | ) |
| protected virtual

Final override from GNet::HeapClient.

Reimplemented from GNet::HeapClient.

Definition at line 46 of file gclient.cpp.

void GNet::Client::onData | ( | const char * | p,
|  | SimpleClient::size_type | n
| ) |  |
| protected virtual

Final override from GNet::SocketProtocolSink.

Implements GNet::SocketProtocolSink.

Definition at line 105 of file gclient.cpp.

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

Override from GNet::HeapClient.

Reimplemented from GNet::HeapClient.

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

Definition at line 61 of file gclient.cpp.

virtual bool GNet::Client::onReceive | ( | const std::string & |  | ) |
| protected pure virtual

Called when a complete line is received from the peer.

The implementation should return false if it needs to stop further onReceive() calls being generated from data already received and buffered, if for example the object has just deleted itself.

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

void GNet::Client::onSendImp | ( |  | ) |
| protected virtual

Final override from GNet::SimpleClient.

Reimplemented from GNet::SimpleClient.

Definition at line 69 of file gclient.cpp.

G::Signal0 & GNet::Client::secureSignal | ( |  | ) |

Returns a signal that incidcates that the security layer has been successfully established.

Definition at line 100 of file gclient.cpp.

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

- gclient.h
- gclient.cpp