RESTinio

connection_state_listener.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
14#include <restinio/compiler_features.hpp>
15#include <restinio/common_types.hpp>
16#include <restinio/variant.hpp>
17#include <restinio/tls_fwd.hpp>
18
19 namespace restinio
20{
21
22 namespace connection_state
23{
24
35 class accepted_t final
36{
45 tls_socket_t * m_tls_socket;
46
47 public:
48 accepted_t(
49 tls_socket_t * tls_socket )
50 : m_tls_socket{ tls_socket }
51 {}
52
59 RESTINIO_NODISCARD
60 bool
61 is_tls_connection() const noexcept { return nullptr != m_tls_socket; }
62
92 template< typename Lambda >
93 void
94 try_inspect_tls( Lambda && lambda ) const;
95
128 template< typename Lambda >
129 decltype(auto)
130 inspect_tls_or_throw( Lambda && lambda ) const;
131
169 template< typename Lambda, typename T >
170 T
171 inspect_tls_or_default( Lambda && lambda, T && default_value ) const;
172};
173
182 class closed_t final
183{
184};
185
195 class upgraded_to_websocket_t final
196{
197};
198
212 using cause_t = variant_t< accepted_t, closed_t, upgraded_to_websocket_t >;
213
224 class notice_t
225{
226 connection_id_t m_conn_id;
227 endpoint_t m_remote_endpoint;
228 cause_t m_cause;
229
230public :
232 notice_t(
233 connection_id_t conn_id,
234 endpoint_t remote_endpoint,
235 cause_t cause )
236 : m_conn_id{ conn_id }
237 , m_remote_endpoint{ remote_endpoint }
238 , m_cause{ cause }
239 {}
240
242 RESTINIO_NODISCARD
243 connection_id_t
244 connection_id() const noexcept { return m_conn_id; }
245
247 RESTINIO_NODISCARD
248 endpoint_t
249 remote_endpoint() const noexcept { return m_remote_endpoint; }
250
252
257 RESTINIO_NODISCARD
258 cause_t
259 cause() const noexcept { return m_cause; }
260};
261
273 struct noop_listener_t
274{
275 // empty type by design.
276};
277
278} /* namespace connection_state */
279
280} /* namespace restinio */
281
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