E-MailRelay
Classes | Public Member Functions | Protected Member Functions | List of all members
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:
+ Collaboration diagram for GNet::Server:

Classes

struct  Config
 A configuration structure for GNet::Server. More...
 

Public Member Functions

 Server (EventState, const Address &listening_address, const ServerPeer::Config &, const Config &)
 Constructor. More...
 
 Server (EventState, Descriptor listening_fd, const ServerPeer::Config &, const Config &)
 Constructor overload for adopting an externally-managed listening file descriptor. More...
 
 ~Server () override
 Destructor. More...
 
Address address () const override
 Returns the listening address. More...
 
std::vector< std::weak_ptr< GNet::ServerPeer > > peers ()
 Returns the list of ServerPeer objects. More...
 
bool hasPeers () const
 Returns true if peers() is not empty. More...
 
 Server (const Server &)=delete
 
 Server (Server &&)=delete
 
Serveroperator= (const Server &)=delete
 
Serveroperator= (Server &&)=delete
 
- Public Member Functions inherited from GNet::Listener
virtual ~Listener ()=default
 Destructor.
 
virtual Address address () const =0
 Returns the listening address. More...
 

Protected Member Functions

virtual std::unique_ptr< ServerPeernewPeer (EventStateUnbound, ServerPeerInfo &&)=0
 A factory method which new()s a ServerPeer-derived object. More...
 
void serverCleanup ()
 Should be called by the most-derived class's destructor in order to trigger early deletion of peer objects before the derived part of the server disappears. 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 50 of file gserver.h.

Constructor & Destructor Documentation

◆ Server() [1/2]

GNet::Server::Server ( EventState  es,
const Address listening_address,
const ServerPeer::Config server_peer_config,
const Config server_config 
)

Constructor.

The server listens on the given address, which can be the 'any' address. The EventState is used for exceptions relating to the listening socket, not the server peers.

Definition at line 50 of file gserver.cpp.

◆ Server() [2/2]

GNet::Server::Server ( EventState  es,
Descriptor  listening_fd,
const ServerPeer::Config server_peer_config,
const Config server_config 
)

Constructor overload for adopting an externally-managed listening file descriptor.

Definition at line 36 of file gserver.cpp.

◆ ~Server()

GNet::Server::~Server ( )
override

Destructor.

Definition at line 89 of file gserver.cpp.

Member Function Documentation

◆ address()

GNet::Address GNet::Server::address ( ) const
overridevirtual

Returns the listening address.

Override from GNet::Listener.

Implements GNet::Listener.

Definition at line 94 of file gserver.cpp.

◆ hasPeers()

bool GNet::Server::hasPeers ( ) const

Returns true if peers() is not empty.

Definition at line 184 of file gserver.cpp.

◆ newPeer()

virtual std::unique_ptr< ServerPeer > GNet::Server::newPeer ( EventStateUnbound  ,
ServerPeerInfo &&   
)
protectedpure virtual

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

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

The implementation should std::move the 'ServerPeerInfo' parameter through to the ServerPeer base-class constructor.

The implementation 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.

◆ peers()

std::vector< std::weak_ptr< GNet::ServerPeer > > GNet::Server::peers ( )

Returns the list of ServerPeer objects.

The returned ServerPeer objects must not outlive this Server.

Definition at line 189 of file gserver.cpp.

◆ serverCleanup()

void GNet::Server::serverCleanup ( )
protected

Should be called by the most-derived class's destructor in order to trigger early deletion of peer objects before the derived part of the server disappears.

This prevents slicing if the destructor of the most-derived ServerPeer makes use of the most-derived Server.

Definition at line 179 of file gserver.cpp.


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