GNet::ServerPeer Class Reference

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

List of all members.

Public Types

typedef std::string::size_type size_type

Public Member Functions

 ServerPeer (Server::PeerInfo)
 Constructor.
bool send (const std::string &data, std::string::size_type offset=0U)
 Sends data down the socket to the peer.
void doDelete (const std::string &=std::string())
 Does "onDelete(); delete this".
std::string logId () const
 Returns an identification string for logging purposes.
virtual std::pair< bool, AddresslocalAddress () const
 Returns the local address.
virtual std::pair< bool, AddresspeerAddress () const
 Returns the peer address.
virtual void readEvent ()
 Final override from GNet::EventHandler.
virtual void writeEvent ()
 Final override from GNet::EventHandler.
virtual void onException (std::exception &)
 Final override from GNet::EventHandler.
void doDeleteThis (int)
 Does delete this. Should only be used by the GNet::Server class.

Protected Member Functions

virtual ~ServerPeer ()
 Destructor.
virtual void onDelete (const std::string &reason)=0
 Called just before destruction.
virtual void onSendComplete ()=0
 Called after flow-control has been released and all residual data sent.
void sslAccept ()
 Waits for the peer to start a secure session.
StreamSocketsocket ()
 Returns a reference to the client-server connection socket.
Serverserver ()
 Returns a pointer to the associated server object.


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 188 of file gserver.h.


Member Typedef Documentation

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

Definition at line 191 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 32 of file gserver.cpp.

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

GNet::ServerPeer::~ServerPeer (  )  [protected, virtual]

Destructor.

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

Definition at line 47 of file gserver.cpp.

References G_DEBUG, GNet::Monitor::instance(), logId(), GNet::Monitor::remove(), and GNet::ServerPeerHandle::reset().


Member Function Documentation

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

References GNet::SocketProtocol::send().

Referenced by GPop::ServerPeer::protocolSend().

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

Does "onDelete(); delete this".

Definition at line 82 of file gserver.cpp.

References onDelete().

Referenced by onException(), GSmtp::AdminServerPeer::onReceive(), and writeEvent().

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

Returns an identification string for logging purposes.

Definition at line 55 of file gserver.cpp.

References GNet::Address::displayString().

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

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

References G_ASSERT.

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

Referenced by GSmtp::ServerPeer::onDelete(), GPop::ServerPeer::onDelete(), GSmtp::AdminServerPeer::onDelete(), and GSmtp::ServerPeer::onSecure().

void GNet::ServerPeer::readEvent (  )  [virtual]

Final override from GNet::EventHandler.

Reimplemented from GNet::EventHandler.

Definition at line 71 of file gserver.cpp.

References GNet::SocketProtocol::readEvent().

void GNet::ServerPeer::writeEvent (  )  [virtual]

Final override from GNet::EventHandler.

Reimplemented from GNet::EventHandler.

Definition at line 114 of file gserver.cpp.

References doDelete(), G_WARNING, onSendComplete(), and GNet::SocketProtocol::writeEvent().

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

Final override from GNet::EventHandler.

Implements GNet::EventHandler.

Definition at line 76 of file gserver.cpp.

References doDelete(), and G_DEBUG.

void GNet::ServerPeer::doDeleteThis ( int   ) 

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

Definition at line 104 of file gserver.cpp.

virtual void GNet::ServerPeer::onDelete ( const std::string &  reason  )  [protected, pure virtual]

Called just before destruction.

(Note that the object typically deletes itself.)

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

Referenced by doDelete().

virtual void GNet::ServerPeer::onSendComplete (  )  [protected, pure 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::AdminServerPeer, GSmtp::ServerPeer, and GPop::ServerPeer.

Referenced by writeEvent().

void GNet::ServerPeer::sslAccept (  )  [protected]

Waits for the peer to start a secure session.

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

Definition at line 60 of file gserver.cpp.

References GNet::SocketProtocol::sslAccept().

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

Returns a reference to the client-server connection socket.

Definition at line 65 of file gserver.cpp.

References G_ASSERT.

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

Returns a pointer to the associated server object.

Returns NULL if the server has been destroyed.


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

Generated on Fri Apr 18 15:56:13 2008 for E-MailRelay by  doxygen 1.5.5