![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
Convenience TcpServer that instantiates a fixed TcpSession type. More...
#include <dfx-server/TcpServerForSession.hpp>
Public Member Functions | |
| TcpServer (Options options, FdWatch::Poller &poller) | |
| Construct a TCP server bound to a poller. | |
| Public Member Functions inherited from dfx::Server::TcpServer | |
| TcpServer (Options options, FdWatch::Poller &poller) | |
| Construct a TCP server bound to a poller. | |
| DISABLE_COPY_AND_MOVE (TcpServer) | |
| TcpServer are not copyable and not movable. | |
| virtual | ~TcpServer () |
| Stop the server and destroy all sessions. | |
| void | setNewSessionCallback (NewSessionCallback cb) |
| Set a callback invoked whenever a new session is accepted. | |
| void | listen () |
| Bind, listen, and register the server socket on the poller. | |
| void | stop () noexcept |
| Stop listening and detach from the poller. This function is safe to call multiple times. | |
| bool | isListening () const noexcept |
| Whether the server socket is currently registered to the poller. | |
| void | terminateSession (TcpSessionPtr session) |
| Terminate (close and remove) a session currently managed by the server. | |
| void | forEachSession (std::move_only_function< void(TcpSessionPtr)> f) |
| Iterate over all currently active sessions. | |
Protected Member Functions | |
| TcpSessionPtr | makeSession (std::string host, std::string serv, TcpServer &server, std::chrono::milliseconds initialTimeout) override |
Create a new session of type T for an accepted connection. | |
Additional Inherited Members | |
| Public Types inherited from dfx::Server::TcpServer | |
| using | NewSessionCallback = std::move_only_function<void (TcpSessionPtr)> |
| Callback invoked when a new session is accepted and created. | |
Convenience TcpServer that instantiates a fixed TcpSession type.
| T | Concrete session type. Must derive from TcpSession. |
TcpServerForSession is a small helper that removes boilerplate for the common case where a server always creates the same session type.
It simply overrides TcpServer::makeSession() and returns: std::make_shared<T>(host, serv, server, initialTimeout).
This is useful when:
T must be constructible with the signature: T(std::string host, std::string serv, TcpServer & server, std::chrono::milliseconds initialTimeout).
|
inlineoverrideprotectedvirtual |
Create a new session of type T for an accepted connection.
| host | Remote host string (typically from getnameinfo / accept). |
| serv | Remote service/port string. |
| server | Reference to the owning server. |
| initialTimeout | Initial inactivity timeout for the new session. |
Implements dfx::Server::TcpServer.
| dfx::Server::TcpServer::TcpServer | ( | Options | options, |
| FdWatch::Poller & | poller ) |
Construct a TCP server bound to a poller.
| options | Server configuration (bind address, port, timeouts). |
| poller | Poller used to watch the listening socket and to run the timer. |