![]() |
TSDuck v3.45-4725
MPEG Transport Stream Toolkit
|
Generic TCP server in a Reactor environment. More...
#include <tsReactiveServer.h>


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. | |
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.
|
explicit |
Constructor.
| [in,out] | server | Actual 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. |
| bool ts::ReactiveServer::start | ( | ReactiveServerFactoryInterface * | session_factory, |
| ReactiveServerHandlerInterface * | handler = nullptr, |
||
| const ObjectPtr & | user_data = ObjectPtr() |
||
| ) |
Start the reactive server in the reactor.
| [in] | session_factory | A factory object which is called for each new incoming client session. |
| [in] | handler | Optional handler to receive notification of internal events. |
| [in] | user_data | A shared pointer which will be passed unmodified to handler. |
|
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.
| [in] | on | If true, the event loop of the reactor is exited when the server exits. |
| void ts::ReactiveServer::setExitAfterClientCount | ( | size_t | count | ) |
Mark the server to exit after having accepted a given number of clients.
| [in] | count | Number of clients after which the server shall 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.
| [in] | silent | If true, do not report errors through the logger. |
| void ts::ReactiveServer::abort | ( | bool | silent = false | ) |
Abort all connected clients and exits the server.
| [in] | silent | If true, do not report errors through the logger. |