VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GNet::Server Class Referenceabstract

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:

Classes

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

Public Member Functions

 Server (const Address &listening_address)
 Constructor. More...
 
 Server ()
 Default constructor. Initialise with init().
 
void init (const Address &listening_address)
 Initilisation after default construction.
 
virtual ~Server ()
 Destructor.
 
std::pair< bool, Addressaddress () const
 Returns the listening address. More...
 
virtual void readEvent () override
 Override from GNet::EventHandler.
 
virtual void writeEvent () override
 Override from GNet::EventHandler.
 
- Public Member Functions inherited from GNet::EventHandler
virtual ~EventHandler ()
 Destructor.
 
virtual void exceptionEvent ()
 Called for a socket-exception event. More...
 
- Public Member Functions inherited from GNet::EventExceptionHandler
virtual void onException (std::exception &)=0
 Called by the event loop when an exception is thrown out of an event loop callback. More...
 

Static Public Member Functions

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

Protected Member Functions

virtual ServerPeernewPeer (PeerInfo)=0
 A factory method which new()s a ServerPeer-derived object. More...
 
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. More...
 
- Protected Member Functions inherited from GNet::EventExceptionHandler
virtual ~EventExceptionHandler ()
 Destructor.
 

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

Constructor & Destructor Documentation

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

Constructor.

The server listens on the given address, which can be the 'any' address.

Definition at line 141 of file gserver.cpp.

Member Function Documentation

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

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

virtual ServerPeer* GNet::Server::newPeer ( PeerInfo  )
protectedpure 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 nullptr 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 nullptr.

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


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