VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 Location &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"), bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault())
 Constructor.
 
G::Slot::Signal1< std::string > & doneSignal ()
 Returns a signal that indicates that client processing is complete. More...
 
G::Slot::Signal2< std::string,
std::string > & 
eventSignal ()
 Returns a signal that indicates that something interesting has happened. More...
 
G::Slot::Signal0connectedSignal ()
 Returns a signal that indicates that the client has successfully connected to the server. More...
 
G::Slot::Signal0secureSignal ()
 Returns a signal that indicates that the security layer has been successfully established. More...
 
- Public Member Functions inherited from 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)
 Constructor. More...
 
void doDelete (const std::string &reason)
 Calls onDelete() and then does a delayed "delete this".
 
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 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.
 
void connect ()
 Initates a connection to the remote server. More...
 
bool connected () const
 Returns true if connected to the peer.
 
virtual std::pair< bool, AddresslocalAddress () const override
 Override from Connection. More...
 
virtual std::pair< bool, AddresspeerAddress () const override
 Override from Connection. 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.
 
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.
 
virtual void exceptionEvent ()
 Called for a socket-exception event. More...
 
- Public Member Functions inherited from GNet::Connection
virtual ~Connection ()
 Destructor.
 
- Public Member Functions inherited from GNet::SocketProtocolSink
virtual ~SocketProtocolSink ()
 Destructor.
 

Protected Member Functions

virtual ~Client ()
 Destructor.
 
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.
 
virtual void onDeleteImp (const std::string &reason) override
 Override from GNet::HeapClient.
 
virtual void onConnectImp () override
 Override from GNet::SimpleClient.
 
virtual void onData (const char *, SimpleClient::size_type) override
 Override from GNet::SocketProtocolSink.
 
virtual void onConnecting () override
 Override from GNet::HeapClient.
 
virtual void onSendImp () override
 Override from GNet::SimpleClient.
 
- Protected Member Functions inherited from GNet::HeapClient
virtual ~HeapClient ()
 Destructor.
 
virtual void onDelete (const std::string &reason)=0
 Called just before deletion.
 
virtual void onException (std::exception &) g__final override
 Override from GNet::EventExceptionHandler. More...
 
- Protected Member Functions inherited from GNet::SimpleClient
virtual ~SimpleClient ()
 Destructor.
 
StreamSocketsocket ()
 Returns a reference to the socket. Throws if not connected.
 
const StreamSocketsocket () const
 Returns a const reference to the socket. Throws if not connected.
 
virtual void onConnect ()=0
 Called once connected.
 
virtual void onSendComplete ()=0
 Called when all residual data from send() has been sent.
 
void sslConnect ()
 Starts TLS/SSL client-side negotiation.
 
std::string logId () const
 Returns a identification string for logging purposes. More...
 
- Protected Member Functions inherited from GNet::EventExceptionHandler
virtual ~EventExceptionHandler ()
 Destructor.
 
- Protected Member Functions inherited from GNet::SocketProtocolSink
virtual void onData (const char *, size_t)=0
 Called when data is read from the socket.
 
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, ImmediateSuccess }
 
enum  State {
  Idle, Resolving, Connecting, Connected,
  Socksing, Testing
}
 
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 connectError (const std::string &reason)
 Returns true if the reason string implies the SimpleClient::connect() failed. 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 49 of file gclient.h.

Member Function Documentation

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

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

Definition at line 95 of file gclient.cpp.

G::Slot::Signal1< std::string > & 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::Slot::Signal2< std::string, std::string > & GNet::Client::eventSignal ( )

Returns a signal that indicates that something interesting has happened.

The first signal parameter is one of "connecting", "connected", "sending", "failed" (on error) or "done" (for normal termination). Derived clases may emit other events over this channel.

Definition at line 90 of file gclient.cpp.

virtual bool GNet::Client::onReceive ( const std::string &  )
protectedpure 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.

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

Returns a signal that indicates 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: