TSDuck v3.45-4725
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::ReactiveServer Class Reference

Generic TCP server in a Reactor environment. More...

#include <tsReactiveServer.h>

Inheritance diagram for ts::ReactiveServer:
Collaboration diagram for ts::ReactiveServer:

Public Member Functions

 ReactiveServer (ReactiveTCPServer &server)
 Constructor.
 
virtual ~ReactiveServer () override
 Destructor.
 
void abort (bool silent=false)
 Abort all connected clients and exits the server.
 
void exit (bool silent=false)
 Mark the server to exit when the last active client terminates.
 
void setExitAfterClientCount (size_t count)
 Mark the server to exit after having accepted a given number of clients.
 
void setExitEventLoop (bool on)
 Specify if the event loop of the reactor shall be exited when the server exits.
 
bool start (ReactiveServerFactoryInterface *session_factory, ReactiveServerHandlerInterface *handler=nullptr, const ObjectPtr &user_data=ObjectPtr())
 Start the reactive server in the reactor.
 

Detailed Description

Generic TCP server in a Reactor environment.

This class works on an application-provided ReactiveTCPServer, meaning that any specialized subclass such as ReactiveTLSServer can be used. The (subclass of) ReactiveTCPServer object and its associated (subclass of) TCPServer must be initialized in the application, up to and including listen(). The calls to accept() are performed by the ReactiveServer.

This server automatically creates sessions when incoming clients connect and automatically deletes the session object when they disconnect. The "session" objects are created by an instance of ReactiveServerFactoryInterface. The session object class must implement ReactiveServerSessionInterface.

Note that one session object is always allocated in advance to catch the next incoming client.

A session object is deleted after the underlying socket is closed. More precisely, the deletion occurs in an independent reactor handler, shortly after the socket is closed. This means that if the closing occurs deep in a cascade of calls involving methods or handlers in the session object, that session object remains valid all along the return chain of those calls. When the deletion occurs, no method of the session object is present in the stack frames. However, the application shall take care that no further handler will be called later on that session object because it will no longer exist.

Constructor & Destructor Documentation

◆ ReactiveServer()

ts::ReactiveServer::ReactiveServer ( ReactiveTCPServer server)
explicit

Constructor.

Parameters
[in,out]serverActual reactive server. This can also be a subclass such as ReactiveTLSServer. The associated Reactor will be used for all event dispatching. A reference to server is kept inside "this" object. The server object must remain valid as long as "this" object exists.

Member Function Documentation

◆ start()

bool ts::ReactiveServer::start ( ReactiveServerFactoryInterface session_factory,
ReactiveServerHandlerInterface handler = nullptr,
const ObjectPtr user_data = ObjectPtr() 
)

Start the reactive server in the reactor.

Parameters
[in]session_factoryA factory object which is called for each new incoming client session.
[in]handlerOptional handler to receive notification of internal events.
[in]user_dataA shared pointer which will be passed unmodified to handler.
Returns
True on success, false on error.

◆ setExitEventLoop()

void ts::ReactiveServer::setExitEventLoop ( bool  on)
inline

Specify if the event loop of the reactor shall be exited when the server exits.

This could be implemented in a handleServerExited() handler in the application but, since this is a common usage, provide a more straightforward way.

Parameters
[in]onIf true, the event loop of the reactor is exited when the server exits.

◆ setExitAfterClientCount()

void ts::ReactiveServer::setExitAfterClientCount ( size_t  count)

Mark the server to exit after having accepted a given number of clients.

Parameters
[in]countNumber of clients after which the server shall exit.

◆ exit()

void ts::ReactiveServer::exit ( bool  silent = false)

Mark the server to exit when the last active client terminates.

No more new client will be accepted. If no client is currenly connected, the server exits immediately.

Parameters
[in]silentIf true, do not report errors through the logger.

◆ abort()

void ts::ReactiveServer::abort ( bool  silent = false)

Abort all connected clients and exits the server.

Parameters
[in]silentIf true, do not report errors through the logger.

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