connection_state_listener.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/compiler_features.hpp>
#include <restinio/common_types.hpp>
#include <restinio/variant.hpp>
#include <restinio/tls_fwd.hpp>
namespace restinio
{
namespace connection_state
{
class accepted_t final
{
tls_socket_t * m_tls_socket;
public:
accepted_t(
tls_socket_t * tls_socket )
: m_tls_socket{ tls_socket }
{}
RESTINIO_NODISCARD
bool
is_tls_connection() const noexcept { return nullptr != m_tls_socket; }
template< typename Lambda >
void
try_inspect_tls( Lambda && lambda ) const;
template< typename Lambda >
decltype(auto)
inspect_tls_or_throw( Lambda && lambda ) const;
template< typename Lambda, typename T >
T
inspect_tls_or_default( Lambda && lambda, T && default_value ) const;
};
class closed_t final
{
};
class upgraded_to_websocket_t final
{
};
using cause_t = variant_t< accepted_t, closed_t, upgraded_to_websocket_t >;
class notice_t
{
connection_id_t m_conn_id;
endpoint_t m_remote_endpoint;
cause_t m_cause;
public :
notice_t(
connection_id_t conn_id,
endpoint_t remote_endpoint,
cause_t cause )
: m_conn_id{ conn_id }
, m_remote_endpoint{ remote_endpoint }
, m_cause{ cause }
{}
RESTINIO_NODISCARD
connection_id_t
connection_id() const noexcept { return m_conn_id; }
RESTINIO_NODISCARD
endpoint_t
remote_endpoint() const noexcept { return m_remote_endpoint; }
RESTINIO_NODISCARD
cause_t
cause() const noexcept { return m_cause; }
};
struct noop_listener_t
{
// empty type by design.
};
} /* namespace connection_state */
} /* namespace restinio */
nonstd::variants::variant
Definition: variant.hpp:1301
restinio::connection_state::accepted_t
Type of object that tells that new connection has been accepted.
Definition: connection_state_listener.hpp:36
restinio::connection_state::accepted_t::accepted_t
accepted_t(tls_socket_t *tls_socket)
Definition: connection_state_listener.hpp:48
restinio::connection_state::accepted_t::inspect_tls_or_throw
decltype(auto) inspect_tls_or_throw(Lambda &&lambda) const
Calls the specified lambda-function if the accepted connection is a TLS-connection.
Definition: tls.hpp:109
restinio::connection_state::accepted_t::is_tls_connection
RESTINIO_NODISCARD bool is_tls_connection() const noexcept
Checks if the accepted connection is a TLS-connection.
Definition: connection_state_listener.hpp:61
restinio::connection_state::accepted_t::inspect_tls_or_default
T inspect_tls_or_default(Lambda &&lambda, T &&default_value) const
Calls the specified lambda-function if the accepted connection is a TLS-connection.
Definition: tls.hpp:120
restinio::connection_state::accepted_t::m_tls_socket
tls_socket_t * m_tls_socket
An optional pointer to TLS-related connection.
Definition: connection_state_listener.hpp:45
restinio::connection_state::accepted_t::try_inspect_tls
void try_inspect_tls(Lambda &&lambda) const
Calls the specified lambda-function if the accepted connection is a TLS-connection.
Definition: tls.hpp:101
restinio::connection_state::closed_t
Type of object that tells that the connection has been closed.
Definition: connection_state_listener.hpp:183
restinio::connection_state::notice_t
An object with info about connection to be passed to state listener.
Definition: connection_state_listener.hpp:225
restinio::connection_state::notice_t::m_conn_id
connection_id_t m_conn_id
Definition: connection_state_listener.hpp:226
restinio::connection_state::notice_t::m_remote_endpoint
endpoint_t m_remote_endpoint
Definition: connection_state_listener.hpp:227
restinio::connection_state::notice_t::cause
RESTINIO_NODISCARD cause_t cause() const noexcept
Get the cause for the notification.
Definition: connection_state_listener.hpp:259
restinio::connection_state::notice_t::connection_id
RESTINIO_NODISCARD connection_id_t connection_id() const noexcept
Get the connection id.
Definition: connection_state_listener.hpp:244
restinio::connection_state::notice_t::m_cause
cause_t m_cause
Definition: connection_state_listener.hpp:228
restinio::connection_state::notice_t::remote_endpoint
RESTINIO_NODISCARD endpoint_t remote_endpoint() const noexcept
Get the remote endpoint for the connection.
Definition: connection_state_listener.hpp:249
restinio::connection_state::notice_t::notice_t
notice_t(connection_id_t conn_id, endpoint_t remote_endpoint, cause_t cause)
Initializing constructor.
Definition: connection_state_listener.hpp:232
restinio::connection_state::upgraded_to_websocket_t
Type of object that tells that the connection has been upgraded to WebSocket.
Definition: connection_state_listener.hpp:196
restinio::impl::tls_socket_t
Socket adapter for asio::ssl::stream< asio::ip::tcp::socket >.
Definition: tls_socket.hpp:37
common_types.hpp
compiler_features.hpp
Detection of compiler version and absence of various features.
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
restinio
Definition: asio_include.hpp:21
restinio::endpoint_t
asio_ns::ip::tcp::endpoint endpoint_t
An alias for endpoint type from Asio.
Definition: common_types.hpp:177
restinio::connection_id_t
std::uint64_t connection_id_t
Type for ID of connection.
Definition: common_types.hpp:174
restinio::connection_state::noop_listener_t
The default no-op state listener.
Definition: connection_state_listener.hpp:274
tls_fwd.hpp
Forward declarations for TLS-related things.
variant.hpp
const
#define const
Definition: zconf.h:230