VideoTools
|
A network server class which listens on a specific port and spins off ServerPeer objects for each incoming connection. More...
#include <gserver.h>
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, Address > | address () 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 ServerPeer * | newPeer (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. | |
A network server class which listens on a specific port and spins off ServerPeer objects for each incoming connection.
|
explicit |
Constructor.
The server listens on the given address, which can be the 'any' address.
Definition at line 141 of file gserver.cpp.
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.
|
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.
|
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.
|
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.