Boost C++ Libraries

PrevUpHomeNext

Function template tcp

boost::taar::server::tcp — Coroutine that binds, listens, and accepts TCP connections, making connection strands from the executor it is spawned on.

Synopsis

// In header: <boost/taar/server/tcp.hpp>


template<typename SessionHandler> 
  awaitable< void > 
  tcp(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);

Description

Equivalent to the overload taking a connection_executor, with co_await this_coro::executor in its place. Spawn it on the io_context (or thread pool) executor itself:

boost::asio::co_spawn(io, taar::server::tcp("0.0.0.0", "8080", http_session, signals),
    boost::asio::detached);

Spawned on a strand instead, every connection strand would be layered on that strand and all connections would be serialised through it; use the overload taking an explicit connection_executor in that case (or whenever the spawning executor is not the one connections should run on).

Throws:

boost::taar::exception carrying the system error code if name resolution, binding or listening fails.

PrevUpHomeNext