E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | 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:

## Classes
struct | PeerInfo
| A structure used in GNet::Server::newPeer(). More...

## Public Member Functions
| Server (ExceptionHandler &, const Address &listening_address)
| Constructor. More...
| Server (ExceptionHandler &)
| 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 | otherEvent (Reason)
| Called for a socket-exception event or a socket-close event on windows. More...

## Static Public Member Functions
static bool | canBind (const Address &listening_address, bool do_throw)
| Checks that the specified address can be bound. More...
Static Public Member Functions inherited from GNet::EventHandler
static std::string | str (Reason)
| Returns a printable description of the other-event reason. 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...

## Additional Inherited Members
Public Types inherited from GNet::EventHandler
enum | Reason { reason_closed, reason_down, reason_reset, reason_abort, reason_other }

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

## Constructor & Destructor Documentation

GNet::Server::Server | ( | ExceptionHandler & | eh,
|  | const Address & | listening_address
| ) |  |

Constructor.

The server listens on the given address, which can be the 'any' address.

Definition at line 141 of file gserver.cpp.

## Member Function Documentation

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

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

virtual ServerPeer* GNet::Server::newPeer | ( | PeerInfo |  | ) |
| protected pure 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.

void GNet::Server::serverCleanup | ( |  | ) |
| 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 184 of file gserver.cpp.

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

- /tmp/slackrepo/SBo/slackrepo.S3SYfd/build_emailrelay/emailrelay-2.0.1/src/gnet/gserver.h
- /tmp/slackrepo/SBo/slackrepo.S3SYfd/build_emailrelay/emailrelay-2.0.1/src/gnet/gserver.cpp