An abstract base class for the GNet::Server's connection to a remote client. More...
#include <gserver.h>
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, Address > | localAddress () const |
Returns the local address. More... | |
virtual std::pair< bool, Address > | peerAddress () 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... | |
StreamSocket & | socket () |
Returns a reference to the client-server connection socket. More... | |
Server * | server () |
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... | |
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.
typedef std::string::size_type GNet::ServerPeer::size_type |
|
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().
|
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().
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.
|
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().
|
protectedpure virtual |
Called just before destruction.
(Note that the object typically deletes itself.)
Implemented in GSmtp::AdminServerPeer, GSmtp::ServerPeer, and GPop::ServerPeer.
|
virtual |
Final override from GNet::EventHandler.
Implements GNet::EventHandler.
Definition at line 77 of file gserver.cpp.
References G_DEBUG.
|
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.
|
virtual |
Returns the peer address.
Final override from GNet::Connection.
Implements GNet::Connection.
Definition at line 95 of file gserver.cpp.
|
virtual |
Returns the peer's TLS certificate.
Final override from GNet::Connection.
Implements GNet::Connection.
Definition at line 100 of file gserver.cpp.
|
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.
|
protected |
Returns a pointer to the associated server object.
Returns NULL if the server has been destroyed.
|
protected |
Returns a reference to the client-server connection socket.
Definition at line 66 of file gserver.cpp.
References G_ASSERT.
|
protected |
Waits for the peer to start a secure session.
See also GNet::SocketProtocolSink::onSecure().
Definition at line 61 of file gserver.cpp.
|
virtual |
Final override from GNet::EventHandler.
Reimplemented from GNet::EventHandler.
Definition at line 120 of file gserver.cpp.
References G_WARNING.