Boost C++ Libraries

PrevUpHomeNext

Function template tls

boost::taar::server::tls — Coroutine that accepts TCP connections and runs a TLS handshake on each before handing the encrypted stream to session_handler.

Synopsis

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


template<typename SessionHandler> 
  awaitable< void > 
  tls(boost::asio::any_io_executor connection_executor, std::string bind_host, 
      std::string bind_port, boost::asio::ssl::context & tls, 
      SessionHandler && session_handler, cancellation_signals & signals, 
      std::function< void(boost::asio::ip::tcp::endpoint const &)> local_endpoint_handler = nullptr, 
      std::chrono::steady_clock::duration handshake_timeout = std::chrono::seconds {30});

Description

Same binding and cancellation behaviour as tcp. A connection whose handshake fails or takes longer than handshake_timeout is dropped without involving the session. The session receives a boost::taar::session::tls_stream, so pair this acceptor with boost::taar::session::https (or basic_https<Context>).

Parameters:

connection_executor

The executor every connection strand is made from, normally the io_context (or thread pool) executor itself; see server::tcp.

bind_host

Host or address to bind.

bind_port

Port string; "0" lets the OS pick.

tls

The TLS context holding certificate, key and options. Must outlive the server.

session_handler

Invoked as session_handler(tls_stream, signals).

signals

Cancellation pool shared with the sessions; see tcp for threading.

local_endpoint_handler

Optional callback with the bound endpoint.

handshake_timeout

Upper bound for the TLS handshake.

Throws:

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

PrevUpHomeNext