RESTinio
Public Member Functions | Private Attributes | List of all members
restinio::connection_state::accepted_t Class Referencefinal

Type of object that tells that new connection has been accepted. More...

#include <connection_state_listener.hpp>

Public Member Functions

 accepted_t (tls_socket_t *tls_socket)
 
RESTINIO_NODISCARD bool is_tls_connection () const noexcept
 Checks if the accepted connection is a TLS-connection. More...
 
template<typename Lambda >
void try_inspect_tls (Lambda &&lambda) const
 Calls the specified lambda-function if the accepted connection is a TLS-connection. More...
 
template<typename Lambda >
decltype(auto) inspect_tls_or_throw (Lambda &&lambda) const
 Calls the specified lambda-function if the accepted connection is a TLS-connection. More...
 
template<typename Lambda , typename T >
inspect_tls_or_default (Lambda &&lambda, T &&default_value) const
 Calls the specified lambda-function if the accepted connection is a TLS-connection. More...
 

Private Attributes

tls_socket_tm_tls_socket
 An optional pointer to TLS-related connection. More...
 

Detailed Description

Type of object that tells that new connection has been accepted.

If a new connection is a TLS-connection then is_tls_connection() returns true and the information about TLS-socket can be inspected via try_inspect_tls(), inspect_tls_or_throw() and inspect_tls_or_default() methods.

Since
v.0.6.0
Examples
sample/tls_inspector/main.cpp.

Definition at line 35 of file connection_state_listener.hpp.

Constructor & Destructor Documentation

◆ accepted_t()

restinio::connection_state::accepted_t::accepted_t ( tls_socket_t tls_socket)
inline

Definition at line 48 of file connection_state_listener.hpp.

Member Function Documentation

◆ inspect_tls_or_default()

template<typename Lambda , typename T >
T restinio::connection_state::accepted_t::inspect_tls_or_default ( Lambda &&  lambda,
T &&  default_value 
) const

Calls the specified lambda-function if the accepted connection is a TLS-connection.

Returns the value of default_value if the accepted connection doens't use TLS.

Lambda function should accept one argument of a type restinio::connection_state::tls_accessor_t (by value of by const reference).

Returns
the value returned by lambda if it is TLS-connection or default_value otherwise. Note that lambda can return a value of a different type and in that case the returned value will be used for constructing of a new value of type T.

Usage example:

class my_cause_visitor_t {
void operator()(const restinio::connection_state::accepted_t & cause) const {
... // Some application-logic.
auto user_name = cause.inspect_tls_or_default(
... // Some application-specific work with TLS-params.
},
std::string{"unknown-user"});
...
}
...
};
void some_state_listener_t::state_changed(
...
restinio::visit(my_cause_visitor_t{...}, notice.cause());
}
Type of object that tells that new connection has been accepted.
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
An object with info about connection to be passed to state listener.
RESTINIO_NODISCARD cause_t cause() const noexcept
Get the cause for the notification.
Accessor to TLS-specific information related to a connection.
Definition: tls.hpp:31
R visit(const Visitor &v, V1 const &arg1)
Definition: variant.hpp:2532

Definition at line 120 of file tls.hpp.

◆ inspect_tls_or_throw()

template<typename Lambda >
decltype(auto) restinio::connection_state::accepted_t::inspect_tls_or_throw ( Lambda &&  lambda) const

Calls the specified lambda-function if the accepted connection is a TLS-connection.

Throws an instance of exception_t if the accepted connection doens't use TLS.

Lambda function should accept one argument of a type restinio::connection_state::tls_accessor_t (by value of by const reference).

Returns
the value returned by lambda.

Usage example:

class my_cause_visitor_t {
void operator()(const restinio::connection_state::accepted_t & cause) const {
... // Some application-logic.
... // Some application-specific work with TLS-params.
});
...
}
...
};
void some_state_listener_t::state_changed(
...
restinio::visit(my_cause_visitor_t{...}, notice.cause());
}
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
Examples
sample/tls_inspector/main.cpp.

Definition at line 109 of file tls.hpp.

◆ is_tls_connection()

RESTINIO_NODISCARD bool restinio::connection_state::accepted_t::is_tls_connection ( ) const
inlinenoexcept

Checks if the accepted connection is a TLS-connection.

Return values
trueif the accepted connection is a TLS-connection.
falseif the accepted connection doesn't use TLS.

Definition at line 61 of file connection_state_listener.hpp.

◆ try_inspect_tls()

template<typename Lambda >
void restinio::connection_state::accepted_t::try_inspect_tls ( Lambda &&  lambda) const

Calls the specified lambda-function if the accepted connection is a TLS-connection.

Do nothing if the accepted connection doens't use TLS.

Lambda function should accept one argument of a type restinio::connection_state::tls_accessor_t (by value of by const reference).

Usage example:

class my_cause_visitor_t {
void operator()(const restinio::connection_state::accepted_t & cause) const {
... // Some application-logic.
... // Some application-specific work with TLS-params.
});
...
}
...
};
void some_state_listener_t::state_changed(
...
restinio::visit(my_cause_visitor_t{...}, notice.cause());
}
void try_inspect_tls(Lambda &&lambda) const
Calls the specified lambda-function if the accepted connection is a TLS-connection.
Definition: tls.hpp:101

Definition at line 101 of file tls.hpp.

Member Data Documentation

◆ m_tls_socket

tls_socket_t* restinio::connection_state::accepted_t::m_tls_socket
private

An optional pointer to TLS-related connection.

Will be nullptr for non-TLS connections.

Since
v.0.6.0

Definition at line 45 of file connection_state_listener.hpp.


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