2
3
6
7
8
9
13#include <restinio/null_mutex.hpp>
14#include <restinio/default_strands.hpp>
16#include <restinio/utils/tagged_scalar.hpp>
36
37
38
39
49
50
51
52
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
83
84
85
89 std::size_t index )
noexcept = 0;
92
93
94
95
96
97
98
102 std::size_t index )
noexcept = 0;
106
107
108
109
110
111
112
113
114
115
116template<
typename Mutex_Type >
126
127
128
129
130
131
132
133
134
135
136
137
138
139
143
144
145
146
147
154
155
156
157
158
159
160
161
162
163
164
165
166
178 not_null_pointer_t< acceptor_callback_iface_t > acceptor,
179 max_parallel_connections_t max_parallel_connections,
180 max_active_accepts_t max_pending_indexes )
193 std::lock_guard< Mutex_Type > lock{
m_lock };
210 auto index_to_activate = [
this]() -> std::optional<std::size_t> {
211 std::lock_guard< Mutex_Type > lock{ m_lock };
216 if( has_free_slots() && !m_pending_indexes.empty() )
218 std::size_t pending_index = m_pending_indexes.back();
219 m_pending_indexes.pop_back();
220 return pending_index;
226 if( index_to_activate )
228 m_acceptor->schedule_next_accept_attempt( *index_to_activate );
233
234
235
236
242 const bool accept_now = [
this, index]() ->
bool {
243 std::lock_guard< Mutex_Type > lock{
m_lock };
252 m_pending_indexes.push_back( index );
259 m_acceptor->call_accept_now( index );
267
268
269
270
271
278 not_null_pointer_t< connection_count_limits::impl::acceptor_callback_iface_t > acceptor,
279 max_parallel_connections_t ,
280 max_active_accepts_t )
292
293
294
303
304
305
306
307
308
309
310
311template<
typename Strand >
315
316
317
318
319
320
321
322
334
335
336
337
338
339
340
341
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375template<
typename Count_Manager >
397 template<
typename Acceptor_Type >
399 Acceptor_Type & acceptor,
400 not_null_pointer_t< Count_Manager > manager )
noexcept
404 m_manager->increment_parallel_connections();
410 m_manager->decrement_parallel_connections();
449
450
451
452
453
454
455
460 template<
typename Acceptor_Type >
470
471
472
473
474
475
476
477
478
479
480
481
482
483
490 Traits::use_connection_count_limiter,
Implementation of connection count limiter for multi-threading mode.
connection_count_limits::impl::actual_limiter_t< std::mutex > base_t
Implementation of connection count limiter for single-threading mode.
connection_count_limits::impl::actual_limiter_t< null_mutex_t > base_t
Template class for connection count limiter for the case when connection count limit is actually used...
Specialization of connection_lifetime_monitor for the case when connection count limiter is not used ...
connection_lifetime_monitor_t(Acceptor_Type &, not_null_pointer_t< noop_connection_count_limiter_t >) noexcept
Helper type for controlling the lifetime of the connection.
connection_lifetime_monitor_t & operator=(connection_lifetime_monitor_t &&other) noexcept
~connection_lifetime_monitor_t()
Count_Manager * m_manager
Pointer to manager object that counts live connections.
friend void swap(connection_lifetime_monitor_t &a, connection_lifetime_monitor_t &b) noexcept
connection_lifetime_monitor_t(connection_lifetime_monitor_t &&other) noexcept
connection_lifetime_monitor_t(Acceptor_Type &acceptor, not_null_pointer_t< Count_Manager > manager) noexcept
connection_lifetime_monitor_t & operator=(const connection_lifetime_monitor_t &)=delete
connection_lifetime_monitor_t(const connection_lifetime_monitor_t &)=delete
std::any m_acceptor
Holder of std::shared_ptr<acceptor_t>.
An interface of acceptor to be used by connection count limiters.
virtual void schedule_next_accept_attempt(std::size_t index) noexcept=0
virtual void call_accept_now(std::size_t index) noexcept=0
Actual implementation of connection count limiter.
std::vector< std::size_t > m_pending_indexes
The storage for holding pending socket's slots.
std::size_t m_active_accepts
The counter of active accept() operations.
Mutex_Type m_lock
Lock object to be used.
actual_limiter_t(actual_limiter_t &&)=delete
const std::size_t m_max_parallel_connections
The limit for parallel connections.
bool has_free_slots() const noexcept
std::size_t m_connections
The counter of active connections.
void decrement_parallel_connections() noexcept
void increment_parallel_connections() noexcept
not_null_pointer_t< acceptor_callback_iface_t > m_acceptor
Mandatory pointer to the acceptor connected with this limiter.
void accept_next(std::size_t index) noexcept
An implementation of connection count limiter for the case when connection count is not limited.
not_null_pointer_t< connection_count_limits::impl::acceptor_callback_iface_t > m_acceptor
Helper template for defining tagged scalar types.
restinio::utils::tagged_scalar_t< std::size_t, max_active_accepts_tag > max_active_accepts_t
A kind of strict typedef for maximum count of active accepts.
restinio::utils::tagged_scalar_t< std::size_t, max_parallel_connections_tag > max_parallel_connections_t
A kind of strict typedef for maximum count of active connections.
asio_ns::strand< default_asio_executor > default_strand_t
A typedef for the default strand type.
default_asio_executor noop_strand_t
A typedef for no-op strand type.
A kind of metafunction that deduces actual types related to connection count limiter in the dependecy...
connection_count_limits::connection_lifetime_monitor_t< limiter_t > lifetime_monitor_t
typename std::conditional< Traits::use_connection_count_limiter, connection_count_limits::connection_count_limiter_t< typename Traits::strand_t >, connection_count_limits::noop_connection_count_limiter_t >::type limiter_t
A class to be used as null_mutex.