LLFIO  v2.00
llfio_v2_xxx::tls_socket_source_registry Class Reference

A process-wide registry of tls_socket_source. More...

#include "tls_socket_handle.hpp"

Static Public Member Functions

static QUICKCPPLIB_NODISCARD bool empty () noexcept
 True if there are no socket sources known to this registry.
 
static size_t size () noexcept
 The current total number of socket sources known to this registry.
 
static span< tls_socket_source_implementation_informationsources (span< tls_socket_source_implementation_information > tofill, tls_socket_source_implementation_features set=tls_socket_source_implementation_features::none, tls_socket_source_implementation_features mask=tls_socket_source_implementation_features::none) noexcept
 
static tls_socket_source_implementation_information default_source (tls_socket_source_implementation_features set=tls_socket_source_implementation_features::none, tls_socket_source_implementation_features mask=tls_socket_source_implementation_features::none) noexcept
 Convenience overload retrieving TLS socket sources, preferring system over third party implementations.
 
static result< void > register_source (tls_socket_source_implementation_information i) noexcept
 Registers a new source of byte sockets.
 
static void unregister_source (tls_socket_source_implementation_information i) noexcept
 Deregisters a new source of byte sockets.
 

Detailed Description

A process-wide registry of tls_socket_source.

Probably the most common use case for this will be fetching the default source of TLS secured sockets, so here is some example boilerplate:

Blocking:

{c++}
Get a source able to manufacture TLS sockets
tls_socket_source_ptr secure_socket_source =
Get a new TLS socket able to connect
tls_socket_source_handle_ptr sock =
secure_socket_source->connecting_socket(ip::family::v6).value();
Resolve the name "host.org" and service "1234" into an IP address,
and connect to it over TLS. If the remote's TLS certificate is
not trusted by this system, or the remote certificate does not
match the host, this call will fail.
sock->connect("host.org", 1234).value();
Write "Hello" to the connected TLS socket
sock->write(0, {{(const byte *) "Hello", 5}}).value();
Blocking read the response
char buffer[5];
tls_socket_handle::buffer_type b((byte *) buffer, 5);
auto readed = sock->read({{&b, 1}, 0}).value();
if(string_view(buffer, b.size()) != "World") {
abort();
}
With TLS sockets it is important to perform a proper shutdown
rather than hard close
sock->shutdown_and_close().value();
static tls_socket_source_implementation_information default_source(tls_socket_source_implementation_features set=tls_socket_source_implementation_features::none, tls_socket_source_implementation_features mask=tls_socket_source_implementation_features::none) noexcept
Convenience overload retrieving TLS socket sources, preferring system over third party implementation...
Definition: tls_socket_handle.hpp:560
std::unique_ptr< tls_socket_source, detail::tls_socket_source_deleter > tls_socket_source_ptr
A pointer to a TLS socket source.
Definition: tls_socket_handle.hpp:412
result< tls_socket_source_ptr >(* instantiate)() noexcept
Create an instance of this TLS socket source. The instance may be shared or recycled or a singleton.
Definition: tls_socket_handle.hpp:431

Non-blocking:

{c++}
// Get a source able to manufacture TLS sockets
tls_socket_source_ptr secure_socket_source =
// Get a new TLS socket able to connect
tls_socket_source_handle_ptr sock =
secure_socket_source->multiplexable_connecting_socket(ip::family::v6).value();
// Resolve the name "host.org" and service "1234" into an IP address,
// and connect to it over TLS. If the remote's TLS certificate is
// not trusted by this system, or the remote certificate does not
// match the host, this call will fail.
//
// If the connection does not complete within three seconds, fail.
sock->connect("host.org", 1234, std::chrono::seconds(3)).value();
// Write "Hello" to the connected TLS socket
sock->write(0, {{(const byte *) "Hello", 5}}, std::chrono::seconds(3)).value();
// Blocking read the response, but only up to three seconds.
char buffer[5];
tls_socket_handle::buffer_type b((byte *) buffer, 5);
auto readed = sock->read({{&b, 1}, 0}, std::chrono::seconds(3)).value();
if(string_view(buffer, b.size()) != "World") {
abort();
}
// With TLS sockets it is important to perform a proper shutdown
// rather than hard close
sock->shutdown_and_close(std::chrono::seconds(3)).value();

Fuller fat example:

Member Function Documentation

◆ sources()

static span<tls_socket_source_implementation_information> llfio_v2_xxx::tls_socket_source_registry::sources ( span< tls_socket_source_implementation_information tofill,
tls_socket_source_implementation_features  set = tls_socket_source_implementation_features::none,
tls_socket_source_implementation_features  mask = tls_socket_source_implementation_features::none 
)
inlinestaticnoexcept

Fills an array with implementation informations for the TLS socket sources in the registry with features matching set after being masked with mask. The default parameters fetch all sources.


The documentation for this class was generated from the following file: