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

An abstract base class for the GNet::Server's connection to a remote client. More...

#include <gserver.h>

Inheritance diagram for GNet::ServerPeer:
GNet::EventHandler GNet::Connection GNet::SocketProtocolSink GNet::BufferedServerPeer GPop::ServerPeer GSmtp::AdminServerPeer GSmtp::ServerPeer

Public Types

typedef std::string::size_type size_type
 

Public Member Functions

 ServerPeer (Server::PeerInfo)
 Constructor. More...
 
bool send (const std::string &data, std::string::size_type offset=0U)
 Sends data down the socket to the peer. More...
 
void doDelete (const std::string &=std::string())
 Does "onDelete(); delete this". More...
 
std::string logId () const
 Returns an identification string for logging purposes. More...
 
virtual std::pair< bool, AddresslocalAddress () const
 Returns the local address. More...
 
virtual std::pair< bool, AddresspeerAddress () const
 Returns the peer address. More...
 
virtual std::string peerCertificate () const
 Returns the peer's TLS certificate. More...
 
virtual void readEvent ()
 Final override from GNet::EventHandler. More...
 
virtual void writeEvent ()
 Final override from GNet::EventHandler. More...
 
virtual void onException (std::exception &)
 Final override from GNet::EventHandler. More...
 
void doDeleteThis (int)
 Does delete this. Should only be used by the GNet::Server class. 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 ~ServerPeer ()
 Destructor. More...
 
virtual void onDelete (const std::string &reason)=0
 Called just before destruction. More...
 
virtual void onSendComplete ()=0
 Called after flow-control has been released and all residual data sent. More...
 
void sslAccept ()
 Waits for the peer to start a secure session. More...
 
StreamSocketsocket ()
 Returns a reference to the client-server connection socket. More...
 
Serverserver ()
 Returns a pointer to the associated server object. 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...
 

Detailed Description

An abstract base class for the GNet::Server's connection to a remote client.

Instances are created on the heap by the Server::newPeer() override, and they delete themselves when the connection is lost.

See also
GNet::Server, GNet::EventHandler

Definition at line 191 of file gserver.h.

Member Typedef Documentation

typedef std::string::size_type GNet::ServerPeer::size_type

Definition at line 194 of file gserver.h.

Constructor & Destructor Documentation

GNet::ServerPeer::ServerPeer ( Server::PeerInfo  peer_info)
explicit

Constructor.

This constructor is only used from within the override of GServer::newPeer().

Definition at line 33 of file gserver.cpp.

References GNet::Monitor::addServerPeer(), G_ASSERT, G_DEBUG, GNet::Monitor::instance(), and logId().

GNet::ServerPeer::~ServerPeer ( )
protectedvirtual

Destructor.

Note that objects will delete themselves when they detect that the connection has been lost – see doDelete().

Definition at line 48 of file gserver.cpp.

References G_DEBUG, GNet::Monitor::instance(), and GNet::Monitor::removeServerPeer().

Member Function Documentation

void GNet::ServerPeer::doDelete ( const std::string &  reason = std::string())

Does "onDelete(); delete this".

Definition at line 83 of file gserver.cpp.

void GNet::ServerPeer::doDeleteThis ( int  )

Does delete this. Should only be used by the GNet::Server class.

Definition at line 110 of file gserver.cpp.

std::pair< bool, GNet::Address > GNet::ServerPeer::localAddress ( ) const
virtual

Returns the local address.

Pair.first is false on error. Final override from GNet::Connection.

Implements GNet::Connection.

Definition at line 89 of file gserver.cpp.

References G_ASSERT.

std::string GNet::ServerPeer::logId ( ) const

Returns an identification string for logging purposes.

Definition at line 56 of file gserver.cpp.

Referenced by GNet::Server::readEvent(), and ServerPeer().

virtual void GNet::ServerPeer::onDelete ( const std::string &  reason)
protectedpure virtual

Called just before destruction.

(Note that the object typically deletes itself.)

Implemented in GSmtp::AdminServerPeer, GSmtp::ServerPeer, and GPop::ServerPeer.

void GNet::ServerPeer::onException ( std::exception &  e)
virtual

Final override from GNet::EventHandler.

Implements GNet::EventHandler.

Definition at line 77 of file gserver.cpp.

References G_DEBUG.

virtual void GNet::ServerPeer::onSendComplete ( )
protectedpure virtual

Called after flow-control has been released and all residual data sent.

If an exception is thrown in the override then this object catches it and deletes iteself by calling doDelete().

Implemented in GPop::ServerPeer, GSmtp::AdminServerPeer, and GSmtp::ServerPeer.

std::pair< bool, GNet::Address > GNet::ServerPeer::peerAddress ( ) const
virtual

Returns the peer address.

Final override from GNet::Connection.

Implements GNet::Connection.

Definition at line 95 of file gserver.cpp.

std::string GNet::ServerPeer::peerCertificate ( ) const
virtual

Returns the peer's TLS certificate.

Final override from GNet::Connection.

Implements GNet::Connection.

Definition at line 100 of file gserver.cpp.

void GNet::ServerPeer::readEvent ( )
virtual

Final override from GNet::EventHandler.

Reimplemented from GNet::EventHandler.

Definition at line 72 of file gserver.cpp.

bool GNet::ServerPeer::send ( const std::string &  data,
std::string::size_type  offset = 0U 
)

Sends data down the socket to the peer.

Returns false if flow control asserted (see onSendComplete()). Throws on error.

Definition at line 115 of file gserver.cpp.

Server* GNet::ServerPeer::server ( )
protected

Returns a pointer to the associated server object.

Returns NULL if the server has been destroyed.

GNet::StreamSocket & GNet::ServerPeer::socket ( )
protected

Returns a reference to the client-server connection socket.

Definition at line 66 of file gserver.cpp.

References G_ASSERT.

void GNet::ServerPeer::sslAccept ( )
protected

Waits for the peer to start a secure session.

See also GNet::SocketProtocolSink::onSecure().

Definition at line 61 of file gserver.cpp.

void GNet::ServerPeer::writeEvent ( )
virtual

Final override from GNet::EventHandler.

Reimplemented from GNet::EventHandler.

Definition at line 120 of file gserver.cpp.

References G_WARNING.


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