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>
Public Member Functions | |
Server (ExceptionSink, const Address &listening_address, ServerPeerConfig, ServerConfig) | |
Constructor. 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 | |
void | operator= (const Server &)=delete |
void | operator= (Server &&)=delete |
![]() | |
virtual | ~Listener ()=default |
Destructor. | |
virtual Address | address () const =0 |
Returns the listening address. 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 std::unique_ptr< ServerPeer > | newPeer (ExceptionSinkUnbound, 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 | ( | ExceptionSink | es, |
const Address & | listening_address, | ||
ServerPeerConfig | server_peer_config, | ||
ServerConfig | server_config | ||
) |
Constructor.
The server listens on the given address, which can be the 'any' address. The ExceptionSink is used for exceptions relating to the listening socket, not the server peers.
Definition at line 34 of file gserver.cpp.
|
override |
Destructor.
Definition at line 72 of file gserver.cpp.
|
overridevirtual |
Returns the listening address.
Override from GNet::Listener.
Implements GNet::Listener.
Definition at line 89 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 77 of file gserver.cpp.
bool GNet::Server::hasPeers | ( | ) | const |
Returns true if peers() is not empty.
Definition at line 179 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 pass 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.
Implemented in GNet::MultiServerImp.
std::vector< std::weak_ptr< GNet::ServerPeer > > GNet::Server::peers | ( | ) |
Returns the list of ServerPeer objects.
Definition at line 184 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 174 of file gserver.cpp.