![]() |
boost::taar::server::tcp — Coroutine that binds, listens, and accepts TCP connections.
// In header: <boost/taar/server/tcp.hpp> template<typename SessionHandler> awaitable< void > tcp(boost::asio::any_io_executor connection_executor, std::string bind_host, std::string bind_port, SessionHandler && session_handler, cancellation_signals & signals, std::function< void(boost::asio::ip::tcp::endpoint const &)> local_endpoint_handler = nullptr);
Spawn one instance of this coroutine per listen endpoint. It resolves bind_host / bind_port, opens an acceptor with SO_REUSEADDR, starts listening on max_listen_connections, and then loops accepting connections until cancellation is requested through signals.
Each accepted socket is forwarded to session_handler on its own strand, made from connection_executor, so the io_context may be run by several threads and connections are served in parallel. The handler is responsible for the full lifetime of the connection, typically by invoking a session::http instance.
The acceptor and every connection register themselves with signals, and signals.emit() may be called from any thread. A cancellation slot bound to this coroutine by its spawner also stops it (safely, through the acceptor's strand), though it is no longer needed.
Parameters: |
|
||||||||||||
Throws: |
boost::taar::exception carrying the system error code if name resolution, binding or listening fails. |