E-MailRelay
|
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 | 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 | |
Server & | operator= (const Server &)=delete |
Server & | operator= (Server &&)=delete |
![]() | |
virtual | ~Listener ()=default |
Destructor. | |
virtual Address | address () const =0 |
Returns the listening address. More... | |
Protected Member Functions | |
virtual std::unique_ptr< ServerPeer > | newPeer (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... | |
A network server class which listens on a specific port and spins off ServerPeer objects for each incoming connection.
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.
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.
|
override |
Destructor.
Definition at line 89 of file gserver.cpp.
|
overridevirtual |
Returns the listening address.
Override from GNet::Listener.
Implements GNet::Listener.
Definition at line 94 of file gserver.cpp.
bool GNet::Server::hasPeers | ( | ) | const |
Returns true if peers() is not empty.
Definition at line 184 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 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.
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.
|
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.