2
3
6
7
11#include <restinio/traits.hpp>
12#include <restinio/impl/tls_socket.hpp>
21
22
23
24
25
26
27
28
29
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
99template<
typename Lambda >
107template<
typename Lambda >
112 throw exception_t{ "an attempt to call inspect_tls for "
113 "non-TLS-connection" };
118template<
typename Lambda,
typename T >
125 return default_value;
135 typename Timer_Factory,
138 typename Strand = asio_ns::strand< default_asio_executor > >
160template <
typename Connection,
typename Start_Read_CB,
typename Failed_CB >
165 Start_Read_CB start_read_cb,
166 Failed_CB failed_cb )
168 socket.async_handshake(
169 asio_ns::ssl::stream_base::server,
170 [ start_read_cb = std::move( start_read_cb ),
171 failed_cb = std::move( failed_cb ),
172 con = con.shared_from_this() ](
const asio_ns::error_code & ec ){
186
187
188template <
typename Settings >
202 asio_ns::ssl::context context ) &
204 m_tls_context = std::make_shared< asio_ns::ssl::context >(
205 std::move( context ) );
212 asio_ns::ssl::context context ) &&
214 return std::move(
this->tls_context( std::move( context ) ) );
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
248 std::shared_ptr< asio_ns::ssl::context > shared_context ) &
250 m_tls_context = std::move( shared_context );
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
289 std::shared_ptr< asio_ns::ssl::context > shared_context ) &&
291 return std::move(
this->tls_context( std::move(shared_context) ) );
296
297
298
299
300
301 std::shared_ptr< asio_ns::ssl::context >
304 return std::move(m_tls_context);
311 return static_cast< Settings & >( *
this );
340 template <
typename Settings >
343 asio_ns::io_context & io_context )
347 m_sockets.reserve( settings.concurrent_accepts_count() );
349 while( m_sockets.size() < settings.concurrent_accepts_count() )
351 m_sockets.emplace_back( m_io_context, m_tls_context );
362 return m_sockets.at( idx );
371 std::swap( res, m_sockets.at( idx ) );
380 return m_sockets.size();
decltype(auto) inspect_tls_or_throw(Lambda &&lambda) const
Calls the specified lambda-function if the accepted connection is a TLS-connection.
T inspect_tls_or_default(Lambda &&lambda, T &&default_value) const
Calls the specified lambda-function if the accepted connection is a TLS-connection.
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.
Accessor to TLS-specific information related to a connection.
tls_accessor_t(tls_socket_t &tls_socket)
auto native_handle() const noexcept
Get the access to native handle behind Asio's ssl_stream.
tls_socket_t & m_tls_socket
Exception class for all exceptions thrown by RESTinio.
exception_t(const char *err)
A custom socket storage for tls_socket_t.
asio_ns::io_context & m_io_context
tls_socket_t & socket(std::size_t idx)
virtual ~socket_supplier_t()=default
auto concurrent_accept_sockets_count() const
The number of sockets that can be used for cuncurrent accept operations.
std::shared_ptr< asio_ns::ssl::context > m_tls_context
std::vector< tls_socket_t > m_sockets
auto move_socket(std::size_t idx)
socket_supplier_t(Settings &settings, asio_ns::io_context &io_context)
Socket adapter for asio::ssl::stream< asio::ip::tcp::socket >.
socket_t & asio_ssl_stream()
Get an access to underlying Asio's socket.
Customizes extra settings needed for working with socket.
Settings & tls_context(std::shared_ptr< asio_ns::ssl::context > shared_context) &
Setup a shared TLS-context for server's settings.
socket_type_dependent_settings_t()=default
Settings && tls_context(std::shared_ptr< asio_ns::ssl::context > shared_context) &&
Setup a shared TLS-context for server's settings.
Settings & upcast_reference()
std::shared_ptr< asio_ns::ssl::context > m_tls_context
Settings && tls_context(asio_ns::ssl::context context) &&
Setup an exclusive TLS-context for server's settings.
~socket_type_dependent_settings_t()=default
socket_type_dependent_settings_t(socket_type_dependent_settings_t &&)=default
Settings & tls_context(asio_ns::ssl::context context) &
Setup an exclusive TLS-context for server's settings.
std::shared_ptr< asio_ns::ssl::context > giveaway_tls_context()
Get away the TLS-context from settings.
tls_socket_t * make_tls_socket_pointer_for_state_listener(tls_socket_t &socket) noexcept
std::function< request_handling_status_t(request_handle_t) > default_request_handler_t
traits_t< Timer_Factory, Logger, Request_Handler, Strand, tls_socket_t > tls_traits_t
impl::tls_socket_t tls_socket_t
A public alias for the actual implementation of TLS-socket.
void prepare_connection_and_start_read(tls_socket_t &socket, Connection &con, Start_Read_CB start_read_cb, Failed_CB failed_cb)
Customizes connection init routine with an additional step: perform handshake and only then start rea...