RESTinio
Toggle main menu visibility
Loading...
Searching...
No Matches
restinio
impl
connection_settings.hpp
Go to the documentation of this file.
1
/*
2
restinio
3
*/
4
5
/*!
6
Connection settings.
7
*/
8
9
#
pragma
once
10
11
#
include
<
llhttp
.
h
>
12
13
#
include
<
restinio
/
connection_state_listener
.
hpp
>
14
#
include
<
restinio
/
incoming_http_msg_limits
.
hpp
>
15
16
#
include
<
restinio
/
utils
/
suppress_exceptions
.
hpp
>
17
18
#
include
<
memory
>
19
#
include
<
chrono
>
20
21
namespace
restinio
22
{
23
24
namespace
impl
25
{
26
27
namespace
connection_settings_details
28
{
29
30
/*!
31
* @brief A class for holding actual state listener.
32
*
33
* This class holds shared pointer to actual state listener object and
34
* provides actual call_state_listener() and
35
* call_state_listener_suppressing_exceptions() implementations.
36
*
37
* @since v.0.5.1
38
*/
39
template
<
typename
Listener >
40
struct
state_listener_holder_t
41
{
42
std::shared_ptr< Listener >
m_connection_state_listener
;
43
44
template
<
typename
Settings >
45
state_listener_holder_t
(
46
const
Settings & settings )
47
:
m_connection_state_listener
{ settings.connection_state_listener() }
48
{}
49
50
template
<
typename
Lambda >
51
void
52
call_state_listener
( Lambda && lambda )
const
53
{
54
m_connection_state_listener
->state_changed( lambda() );
55
}
56
57
template
<
typename
Lambda >
58
void
59
call_state_listener_suppressing_exceptions
(
60
Lambda && lambda )
const
noexcept
61
{
62
restinio
::
utils
::suppress_exceptions_quietly( [&] {
63
m_connection_state_listener
->state_changed( lambda() );
64
} );
65
}
66
};
67
68
/*!
69
* @brief A specialization of state_listener_holder for case of
70
* noop_listener.
71
*
72
* This class doesn't hold anything and doesn't do anything.
73
*
74
* @since v.0.5.1
75
*/
76
template
<>
77
struct
state_listener_holder_t
<
connection_state
::
noop_listener_t
>
78
{
79
template
<
typename
Settings >
80
state_listener_holder_t
(
const
Settings & ) {
/* nothing to do */
}
81
82
template
<
typename
Lambda >
83
void
84
call_state_listener
( Lambda &&
/*lambda*/
)
const
noexcept
85
{
86
/* nothing to do */
87
}
88
89
template
<
typename
Lambda >
90
void
91
call_state_listener_suppressing_exceptions
(
92
Lambda &&
/*lambda*/
)
const
noexcept
93
{
94
/* nothing to do */
95
}
96
};
97
98
}
/* namespace connection_settings_details */
99
100
//
101
// connection_settings_t
102
//
103
104
//! Parameters shared between connections.
105
/*!
106
Each connection has access to common params and
107
server-agent throught this object.
108
*/
109
template
<
typename
Traits >
110
struct
connection_settings_t
final
111
:
public
std::enable_shared_from_this<
connection_settings_t
< Traits > >
112
,
public
connection_settings_details
::
state_listener_holder_t
<
113
typename
Traits::
connection_state_listener_t
>
114
{
115
using
timer_manager_t
=
typename
Traits::
timer_manager_t
;
116
using
timer_manager_handle_t
= std::shared_ptr<
timer_manager_t
>;
117
118
using
request_handler_t
=
request_handler_type_from_traits_t
<
Traits
>;
119
120
using
logger_t
=
typename
Traits::
logger_t
;
121
122
using
connection_state_listener_holder_t
=
123
connection_settings_details
::
state_listener_holder_t
<
124
typename
Traits::
connection_state_listener_t
>;
125
126
/*!
127
* @brief An alias for shared-pointer to extra-data-factory.
128
*
129
* @since v.0.6.13
130
*/
131
using
extra_data_factory_handle_t
=
132
std::shared_ptr<
typename
Traits::
extra_data_factory_t
>;
133
134
connection_settings_t
(
const
connection_settings_t
& ) =
delete
;
135
connection_settings_t
(
const
connection_settings_t
&& ) =
delete
;
136
connection_settings_t
&
operator
= (
const
connection_settings_t
& ) =
delete
;
137
connection_settings_t
&
operator
= (
connection_settings_t
&& ) =
delete
;
138
139
template
<
typename
Settings >
140
connection_settings_t
(
141
Settings && settings,
142
llhttp_settings_t parser_settings,
143
timer_manager_handle_t
timer_manager )
144
:
connection_state_listener_holder_t
{ settings }
145
,
m_request_handler
{
settings
.
request_handler
() }
146
,
m_parser_settings
{ parser_settings }
147
,
m_buffer_size
{ settings.buffer_size() }
148
,
m_incoming_http_msg_limits
{ settings.incoming_http_msg_limits() }
149
,
m_read_next_http_message_timelimit
{
150
settings
.
read_next_http_message_timelimit
() }
151
,
m_write_http_response_timelimit
{
152
settings
.
write_http_response_timelimit
() }
153
,
m_handle_request_timeout
{
154
settings
.
handle_request_timeout
() }
155
,
m_max_pipelined_requests
{ settings.max_pipelined_requests() }
156
,
m_logger
{
settings
.
logger
() }
157
,
m_timer_manager
{ std::move( timer_manager ) }
158
,
m_extra_data_factory
{ settings.giveaway_extra_data_factory() }
159
{
160
if
( !m_timer_manager )
161
throw
exception_t{
"timer manager not set"
};
162
163
if
( !m_extra_data_factory )
164
throw
exception_t{
"extra_data_factory is nullptr"
};
165
}
166
167
//! Request handler factory.
168
std
::
unique_ptr
<
request_handler_t
>
m_request_handler
;
169
170
//! Parser settings.
171
/*!
172
Parsing settings are common for each connection.
173
*/
174
const
llhttp_settings_t
m_parser_settings
;
175
176
//! Params from server_settings_t.
177
//! \{
178
std::size_t
m_buffer_size
;
179
180
/*!
181
* @since v.0.6.12
182
*/
183
const
incoming_http_msg_limits_t
m_incoming_http_msg_limits
;
184
185
std::chrono::steady_clock::duration
186
m_read_next_http_message_timelimit
{
std
::
chrono
::
seconds
( 60 ) };
187
188
std::chrono::steady_clock::duration
189
m_write_http_response_timelimit
{
std
::
chrono
::
seconds
( 5 ) };
190
191
std::chrono::steady_clock::duration
192
m_handle_request_timeout
{
std
::
chrono
::
seconds
( 10 ) };
193
194
std::size_t
m_max_pipelined_requests
;
195
196
const
std
::
unique_ptr
<
logger_t
>
m_logger
;
197
//! \}
198
199
//! Create new timer guard.
200
auto
201
create_timer_guard
()
202
{
203
return
m_timer_manager
->create_timer_guard();
204
}
205
206
/*!
207
* @brief Get a reference to extra-data-factory object.
208
*
209
* @since v.0.6.13
210
*/
211
[[nodiscard]]
212
auto
&
213
extra_data_factory
()
const
noexcept
214
{
215
return
*
m_extra_data_factory
;
216
}
217
218
private
:
219
//! Timer factory for timout guards.
220
timer_manager_handle_t
m_timer_manager
;
221
222
/*!
223
* @brief A factory for instances of extra-data incorporated into a request.
224
*
225
* @attention
226
* This value is expected to be not-null.
227
*
228
* @since v.0.6.13
229
*/
230
extra_data_factory_handle_t
m_extra_data_factory
;
231
};
232
233
template
<
typename
Traits >
234
using
connection_settings_handle_t
=
235
std::shared_ptr<
connection_settings_t
< Traits > >;
236
237
}
/* namespace impl */
238
239
}
/* namespace restinio */
restinio::incoming_http_msg_limits_t
A type of holder of limits related to an incoming HTTP message.
Definition
incoming_http_msg_limits.hpp:69
restinio::connection_state
Definition
connection_state_listener.hpp:24
restinio::impl::connection_settings_details
Definition
connection_settings.hpp:28
restinio::impl
Definition
sendfile_operation_default.ipp:15
restinio::impl::connection_settings_handle_t
std::shared_ptr< connection_settings_t< Traits > > connection_settings_handle_t
Definition
connection_settings.hpp:234
restinio::utils
Definition
from_string_details.ipp:5
restinio
Definition
sendfile_operation_default.ipp:12
restinio::connection_state::noop_listener_t
The default no-op state listener.
Definition
connection_state_listener.hpp:271
restinio::impl::connection_settings_details::state_listener_holder_t< connection_state::noop_listener_t >
A specialization of state_listener_holder for case of noop_listener.
Definition
connection_settings.hpp:78
restinio::impl::connection_settings_details::state_listener_holder_t< connection_state::noop_listener_t >::call_state_listener
void call_state_listener(Lambda &&) const noexcept
Definition
connection_settings.hpp:84
restinio::impl::connection_settings_details::state_listener_holder_t< connection_state::noop_listener_t >::state_listener_holder_t
state_listener_holder_t(const Settings &)
Definition
connection_settings.hpp:80
restinio::impl::connection_settings_details::state_listener_holder_t< connection_state::noop_listener_t >::call_state_listener_suppressing_exceptions
void call_state_listener_suppressing_exceptions(Lambda &&) const noexcept
Definition
connection_settings.hpp:91
restinio::impl::connection_settings_details::state_listener_holder_t
A class for holding actual state listener.
Definition
connection_settings.hpp:41
restinio::impl::connection_settings_details::state_listener_holder_t::call_state_listener
void call_state_listener(Lambda &&lambda) const
Definition
connection_settings.hpp:52
restinio::impl::connection_settings_details::state_listener_holder_t::call_state_listener_suppressing_exceptions
void call_state_listener_suppressing_exceptions(Lambda &&lambda) const noexcept
Definition
connection_settings.hpp:59
restinio::impl::connection_settings_details::state_listener_holder_t::state_listener_holder_t
state_listener_holder_t(const Settings &settings)
Definition
connection_settings.hpp:45
restinio::impl::connection_settings_details::state_listener_holder_t::m_connection_state_listener
std::shared_ptr< Listener > m_connection_state_listener
Definition
connection_settings.hpp:42
restinio::impl::connection_settings_t::m_buffer_size
std::size_t m_buffer_size
Params from server_settings_t.
Definition
connection_settings.hpp:178
restinio::impl::connection_settings_t::m_max_pipelined_requests
std::size_t m_max_pipelined_requests
Definition
connection_settings.hpp:194
restinio::impl::connection_settings_t::m_parser_settings
const llhttp_settings_t m_parser_settings
Parser settings.
Definition
connection_settings.hpp:174
restinio::impl::connection_settings_t::logger_t
typename Traits::logger_t logger_t
Definition
connection_settings.hpp:120
restinio::impl::connection_settings_t::request_handler_t
request_handler_type_from_traits_t< Traits > request_handler_t
Definition
connection_settings.hpp:118
restinio::impl::connection_settings_t::operator=
connection_settings_t & operator=(const connection_settings_t &)=delete
restinio::impl::connection_settings_t::m_timer_manager
timer_manager_handle_t m_timer_manager
Timer factory for timout guards.
Definition
connection_settings.hpp:220
restinio::impl::connection_settings_t::m_handle_request_timeout
std::chrono::steady_clock::duration m_handle_request_timeout
Definition
connection_settings.hpp:192
restinio::impl::connection_settings_t::connection_state_listener_holder_t
connection_settings_details::state_listener_holder_t< typename Traits::connection_state_listener_t > connection_state_listener_holder_t
Definition
connection_settings.hpp:122
restinio::impl::connection_settings_t::connection_settings_t
connection_settings_t(Settings &&settings, llhttp_settings_t parser_settings, timer_manager_handle_t timer_manager)
Definition
connection_settings.hpp:140
restinio::impl::connection_settings_t::timer_manager_handle_t
std::shared_ptr< timer_manager_t > timer_manager_handle_t
Definition
connection_settings.hpp:116
restinio::impl::connection_settings_t::m_request_handler
std::unique_ptr< request_handler_t > m_request_handler
Request handler factory.
Definition
connection_settings.hpp:168
restinio::impl::connection_settings_t::operator=
connection_settings_t & operator=(connection_settings_t &&)=delete
restinio::impl::connection_settings_t::connection_settings_t
connection_settings_t(const connection_settings_t &)=delete
restinio::impl::connection_settings_t::extra_data_factory
auto & extra_data_factory() const noexcept
Get a reference to extra-data-factory object.
Definition
connection_settings.hpp:213
restinio::impl::connection_settings_t::m_logger
const std::unique_ptr< logger_t > m_logger
Definition
connection_settings.hpp:196
restinio::impl::connection_settings_t::connection_settings_t
connection_settings_t(const connection_settings_t &&)=delete
restinio::impl::connection_settings_t::timer_manager_t
typename Traits::timer_manager_t timer_manager_t
Definition
connection_settings.hpp:115
restinio::impl::connection_settings_t::m_extra_data_factory
extra_data_factory_handle_t m_extra_data_factory
A factory for instances of extra-data incorporated into a request.
Definition
connection_settings.hpp:230
restinio::impl::connection_settings_t::extra_data_factory_handle_t
std::shared_ptr< typename Traits::extra_data_factory_t > extra_data_factory_handle_t
An alias for shared-pointer to extra-data-factory.
Definition
connection_settings.hpp:131
restinio::impl::connection_settings_t::m_write_http_response_timelimit
std::chrono::steady_clock::duration m_write_http_response_timelimit
Definition
connection_settings.hpp:189
restinio::impl::connection_settings_t::m_incoming_http_msg_limits
const incoming_http_msg_limits_t m_incoming_http_msg_limits
Definition
connection_settings.hpp:183
restinio::impl::connection_settings_t::m_read_next_http_message_timelimit
std::chrono::steady_clock::duration m_read_next_http_message_timelimit
Definition
connection_settings.hpp:186
restinio::impl::connection_settings_t::create_timer_guard
auto create_timer_guard()
Create new timer guard.
Definition
connection_settings.hpp:201
Generated by
1.17.0