GNet::Server Class Reference

A network server class which listens on a specific port and spins off ServerPeer objects for each incoming connection. More...

#include <gserver.h>

Inheritance diagram for GNet::Server:

GNet::EventHandler GNet::MultiServerImp

List of all members.

Public Member Functions

 Server (unsigned int listening_port)
 Constructor taking a port number.
 Server (const Address &listening_address)
 Constructor.
 Server ()
 Default constructor. Initialise with init().
void init (unsigned int listening_port)
 Initilisation after default construction.
void init (const Address &listening_address)
 Initilisation after default construction.
virtual ~Server ()
 Destructor.
std::pair< bool, Addressaddress () const
 Returns the listening address.
virtual void readEvent ()
 Final override from GNet::EventHandler.
virtual void writeEvent ()
 Final override from GNet::EventHandler.
virtual void onException (std::exception &e)
 Final override from GNet::EventHandler.

Static Public Member Functions

static bool canBind (const Address &listening_address, bool do_throw)
 Checks that the specified address can be bound.

Protected Member Functions

virtual ServerPeernewPeer (PeerInfo)=0
 A factory method which new()s a ServerPeer-derived object.
void serverCleanup ()
 May be called from the derived class destructor in order to trigger early deletion of peer objects, before the derived part of the server disappears.

Classes

struct  PeerInfo
 A structure used in GNet::Server::newPeer(). More...


Detailed Description

A network server class which listens on a specific port and spins off ServerPeer objects for each incoming connection.

See also:
GNet::ServerPeer

Definition at line 82 of file gserver.h.


Constructor & Destructor Documentation

GNet::Server::Server ( unsigned int  listening_port  )  [explicit]

Constructor taking a port number.

The server listens on all local interfaces.

Definition at line 130 of file gserver.cpp.

References init().

GNet::Server::Server ( const Address listening_address  )  [explicit]

Constructor.

The server listens only on the specific (local) interface.

Definition at line 135 of file gserver.cpp.

References init().

GNet::Server::Server (  ) 

Default constructor. Initialise with init().

Definition at line 140 of file gserver.cpp.

GNet::Server::~Server (  )  [virtual]

Destructor.

Definition at line 173 of file gserver.cpp.

References serverCleanup().


Member Function Documentation

bool GNet::Server::canBind ( const Address listening_address,
bool  do_throw 
) [static]

Checks that the specified address can be bound.

Throws CannotBind if the address cannot be bound and 'do_throw' is true.

Definition at line 163 of file gserver.cpp.

References GNet::Socket::canBindHint(), GNet::Address::displayString(), and s.

Referenced by GNet::MultiServer::canBind().

void GNet::Server::init ( unsigned int  listening_port  ) 

Initilisation after default construction.

Definition at line 145 of file gserver.cpp.

Referenced by Server().

void GNet::Server::init ( const Address listening_address  ) 

Initilisation after default construction.

Definition at line 150 of file gserver.cpp.

References GNet::Address::displayString(), and G_DEBUG.

std::pair< bool, GNet::Address > GNet::Server::address (  )  const

Returns the listening address.

Pair.first is false if not properly init()ialised.

Definition at line 212 of file gserver.cpp.

References GNet::Address::invalidAddress(), and result.

Referenced by GNet::MultiServer::serverReport().

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

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

Final override from GNet::EventHandler.

Reimplemented from GNet::EventHandler.

Definition at line 288 of file gserver.cpp.

References G_DEBUG.

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

Final override from GNet::EventHandler.

Implements GNet::EventHandler.

Definition at line 206 of file gserver.cpp.

References G_ERROR.

virtual ServerPeer* GNet::Server::newPeer ( PeerInfo   )  [protected, pure virtual]

A factory method which new()s a ServerPeer-derived object.

This method is called when a new connection comes into this server. The new ServerPeer object is used to represent the state of the client/server connection.

The new ServerPeer object manages its own lifetime doing a "delete this" when the network connection disappears. But the Server also deletes remaining peers during its destruction.

The implementation should pass the 'PeerInfo' parameter through to the ServerPeer base-class constructor.

Should return NULL for non-fatal errors. It is expected that a typical server process will terminate if newPeer() throws, so most implementations will catch any exceptions and return NULL.

Implemented in GNet::MultiServerImp.

Referenced by readEvent().

void GNet::Server::serverCleanup (  )  [protected]

May be called from the derived class destructor in order to trigger early deletion of peer objects, before the derived part of the server disappears.

If this is called from the most-derived Server class then it allows ServerPeer objects to use their Server object safely during destruction.

Definition at line 178 of file gserver.cpp.

Referenced by GNet::MultiServerImp::cleanup(), and ~Server().


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