E-MailRelay
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:

Public Types

typedef std::string::size_type size_type
 
- Public Types inherited from GNet::EventHandler
enum  Reason {
  reason_closed, reason_down, reason_reset, reason_abort,
  reason_other
}
 

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...
 
bool send (const std::vector< std::pair< const char *, size_t > > &data)
 Overload to send data using scatter-gather segments. More...
 
void doDelete (const std::string &=std::string())
 Calls onDelete() and schedules a "delete this".
 
std::string logId () const
 Returns an identification string for logging purposes.
 
virtual std::pair< bool, Address > localAddress () const override
 Returns the local address. More...
 
virtual std::pair< bool, Address > peerAddress () const override
 Returns the peer address. More...
 
virtual std::string connectionState () const override
 Returns the connection state display string. More...
 
virtual std::string peerCertificate () const override
 Returns the peer's TLS certificate. More...
 
virtual void readEvent () override
 Override from GNet::EventHandler. More...
 
virtual void writeEvent () override
 Override from GNet::EventHandler. More...
 
virtual void otherEvent (EventHandler::Reason) override
 Override from GNet::EventHandler. More...
 
void doDeleteThis (int)
 Does delete this. Should only be used by the GNet::Server class.
 
- Public Member Functions inherited from GNet::EventHandler
virtual ~EventHandler ()
 Destructor.
 
- Public Member Functions inherited from GNet::Connection
virtual ~Connection ()
 Destructor.
 
- Public Member Functions inherited from GNet::SocketProtocolSink
virtual ~SocketProtocolSink ()
 Destructor.
 

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 secureAccept ()
 Waits for the peer to start a secure session. More...
 
StreamSocket & socket ()
 Returns a reference to the client-server connection socket. More...
 
Server * server ()
 Returns a pointer to the associated server object. More...
 
virtual void onException (std::exception &) override
 Override from GNet::ExceptionHandler.
 
- Protected Member Functions inherited from GNet::ExceptionHandler
virtual ~ExceptionHandler ()
 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

- Static Public Member Functions inherited from GNet::EventHandler
static std::string str (Reason)
 Returns a printable description of the other-event reason. 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 173 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 31 of file gserver.cpp.

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 46 of file gserver.cpp.

Member Function Documentation

std::string GNet::ServerPeer::connectionState ( ) const
overridevirtual

Returns the connection state display string.

Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 98 of file gserver.cpp.

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

Returns the local address.

Pair.first is false on error. Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 87 of file gserver.cpp.

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::ServerPeer, GSmtp::AdminServerPeer, and GPop::ServerPeer.

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 GSmtp::ServerPeer, GPop::ServerPeer, and GSmtp::AdminServerPeer.

void GNet::ServerPeer::otherEvent ( EventHandler::Reason  reason)
overridevirtual

Override from GNet::EventHandler.

Calls GNet::SocketProtocol::otherEvent().

Reimplemented from GNet::EventHandler.

Definition at line 71 of file gserver.cpp.

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

Returns the peer address.

Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 93 of file gserver.cpp.

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

Returns the peer's TLS certificate.

Override from GNet::Connection.

Implements GNet::Connection.

Definition at line 103 of file gserver.cpp.

void GNet::ServerPeer::readEvent ( )
overridevirtual

Override from GNet::EventHandler.

Calls GNet::SocketProtocol::readEvent().

Reimplemented from GNet::EventHandler.

Definition at line 76 of file gserver.cpp.

void GNet::ServerPeer::secureAccept ( )
protected

Waits for the peer to start a secure session.

Uses a profile called "server"; see GSsl::Library::addProfile(). The callback GNet::SocketProtocolSink::onSecure() is triggered when the secure session is established.

Definition at line 60 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 true if completely sent; returns false if flow control asserted (see onSendComplete()). If flow control is asserted then there should be no new calls to send() until onSendComplete() is triggered. Throws on error.

Definition at line 118 of file gserver.cpp.

bool GNet::ServerPeer::send ( const std::vector< std::pair< const char *, size_t > > &  data)

Overload to send data using scatter-gather segments.

If false is returned then segment data pointers must stay valid until onSendComplete() is triggered.

Definition at line 123 of file gserver.cpp.

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

Returns a pointer to the associated server object.

Returns nullptr if the server has been destroyed.

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

Returns a reference to the client-server connection socket.

Definition at line 65 of file gserver.cpp.

void GNet::ServerPeer::writeEvent ( )
overridevirtual

Override from GNet::EventHandler.

Calls GNet::SocketProtocol::writeEvent().

Reimplemented from GNet::EventHandler.

Definition at line 128 of file gserver.cpp.


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