RESTinio
Loading...
Searching...
No Matches
connection_state_listener.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
11
12#pragma once
13
16#include <restinio/tls_fwd.hpp>
17
18#include <variant>
19
20namespace restinio
21{
22
24{
25
36class accepted_t final
37{
47
48public:
50 tls_socket_t * tls_socket )
51 : m_tls_socket{ tls_socket }
52 {}
53
60 [[nodiscard]]
61 bool
62 is_tls_connection() const noexcept { return nullptr != m_tls_socket; }
63
93 template< typename Lambda >
94 void
95 try_inspect_tls( Lambda && lambda ) const;
96
129 template< typename Lambda >
130 decltype(auto)
131 inspect_tls_or_throw( Lambda && lambda ) const;
132
170 template< typename Lambda, typename T >
171 T
172 inspect_tls_or_default( Lambda && lambda, T && default_value ) const;
173};
174
183class closed_t final
184{
185};
186
197{
198};
199
209using cause_t = std::variant< accepted_t, closed_t, upgraded_to_websocket_t >;
210
222{
226
227public :
230 connection_id_t conn_id,
232 cause_t cause )
233 : m_conn_id{ conn_id }
235 , m_cause{ cause }
236 {}
237
239 [[nodiscard]]
241 connection_id() const noexcept { return m_conn_id; }
242
244 [[nodiscard]]
246 remote_endpoint() const noexcept { return m_remote_endpoint; }
247
249
254 [[nodiscard]]
255 cause_t
256 cause() const noexcept { return m_cause; }
257};
258
271{
272 // empty type by design.
273};
274
275} /* namespace connection_state */
276
277} /* namespace restinio */
278
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
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
tls_socket_t * m_tls_socket
An optional pointer to TLS-related connection.
void try_inspect_tls(Lambda &&lambda) const
Calls the specified lambda-function if the accepted connection is a TLS-connection.
Definition tls.hpp:101
bool is_tls_connection() const noexcept
Checks if the accepted connection is a TLS-connection.
Type of object that tells that the connection has been closed.
endpoint_t remote_endpoint() const noexcept
Get the remote endpoint for the connection.
connection_id_t connection_id() const noexcept
Get the connection id.
notice_t(connection_id_t conn_id, endpoint_t remote_endpoint, cause_t cause)
Initializing constructor.
cause_t cause() const noexcept
Get the cause for the notification.
Type of object that tells that the connection has been upgraded to WebSocket.
Detection of compiler version and absence of various features.
std::variant< accepted_t, closed_t, upgraded_to_websocket_t > cause_t
A type for the representation of the current state of a connection.
asio_ns::ip::tcp::endpoint endpoint_t
An alias for endpoint type from Asio.
impl::tls_socket_t tls_socket_t
A public alias for the actual implementation of TLS-socket.
Definition tls_fwd.hpp:30
std::uint64_t connection_id_t
Type for ID of connection.
Forward declarations for TLS-related things.