Class Server

Inheritance Relationships

Base Type

  • public felix::asyncmsg::Server

Class Documentation

class Server : public felix::asyncmsg::Server

Represents a TCP server listening for incoming connections.

This class provides methods to accept new connections requiested by peers and callbacks that are invoked when connections are accepted or when an error occurs. Each accepted connection spawns a Session.

Public Functions

explicit Server(boost::asio::io_service &ioService, NetworkConfig config, std::function<void(const EndPointAddress&)> onShutdownCb, std::function<void(const ConnectionEvent&)> addEventCb, BaseEventLoop *eventloop, bool useAsioEventLoop, Mode mode)

Create a Server object.

Create a server to listen for incoming connections. The ioService is shared by all servers.

Parameters:
  • ioService – The boost::asio::io_service object used for asynchronous I/O operations

  • config – The network configuration settings

  • connectionClosedCb – The callback to be invoked when a connection is closed

  • onShutdownCb – The callback to be invoked when the server is closed

  • eventloop – A shared pointer to the event loop

  • useAsioEventLoop – Flag whether asio event loop is used or not

  • mode – The Mode specifying how to integrate boost asio events into the event loop

void startAccept()

Start accepting sessions.

To be called after construction has finished and after the server started listening.

void onAccept(std::shared_ptr<felix::asyncmsg::Session> session) override

Callback called when a connection is accepted.

Store the newly created session. Keep accepting connections.

Parameters:

session – The session that was accepted

void onAcceptError(const boost::system::error_code &error, std::shared_ptr<felix::asyncmsg::Session> session) override

Callback called when accepting a connection fails.

Call on_connection_refused_cb callback. Keep accepting connections.

Parameters:
  • error – The error code

  • session – The session that was not accepted

void shutdown()

Stop listening and Asynchronously close all sessions accepted by this server.

Throws:

FailedCloseListenEndpoint – If stopping the server failed