E-MailRelay

Public Member Functions | Static 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:

## 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
Public Member Functions inherited from GNet::Listener
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...

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

## Constructor & Destructor Documentation

## ◆ Server()

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.

## ◆ ~Server()

GNet::Server::~Server | ( |  | ) |
| override

Destructor.

Definition at line 72 of file gserver.cpp.

## Member Function Documentation

## ◆ address()

GNet::Address GNet::Server::address | ( |  | ) | const
| override virtual

Returns the listening address.

Override from GNet::Listener.

Implements GNet::Listener.

Definition at line 89 of file gserver.cpp.

## ◆ canBind()

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

## ◆ hasPeers()

bool GNet::Server::hasPeers | ( |  | ) | const

Returns true if peers() is not empty.

Definition at line 179 of file gserver.cpp.

## ◆ newPeer()

virtual std::unique_ptr< ServerPeer > GNet::Server::newPeer | ( | ExceptionSinkUnbound | ,
|  | ServerPeerInfo |
| ) |  |
| protected pure 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.

## ◆ peers()

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

Returns the list of ServerPeer objects.

Definition at line 184 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 174 of file gserver.cpp.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gserver.h
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gserver.cpp