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>
34
35
36
37
47
48
49
50
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
81
82
83
87 std::size_t index )
noexcept = 0;
90
91
92
93
94
95
96
100 std::size_t index )
noexcept = 0;
104
105
106
107
108
109
110
111
112
113
114template<
typename Mutex_Type >
124
125
126
127
128
129
130
131
132
133
134
135
136
137
141
142
143
144
145
152
153
154
155
156
157
158
159
160
161
162
163
164
176 not_null_pointer_t< acceptor_callback_iface_t > acceptor,
177 max_parallel_connections_t max_parallel_connections,
178 max_active_accepts_t max_pending_indexes )
191 std::lock_guard< Mutex_Type > lock{
m_lock };
208 auto index_to_activate = [
this]() -> std::optional<std::size_t> {
209 std::lock_guard< Mutex_Type > lock{ m_lock };
214 if( has_free_slots() && !m_pending_indexes.empty() )
216 std::size_t pending_index = m_pending_indexes.back();
217 m_pending_indexes.pop_back();
218 return pending_index;
224 if( index_to_activate )
226 m_acceptor->schedule_next_accept_attempt( *index_to_activate );
231
232
233
234
240 const bool accept_now = [
this, index]() ->
bool {
241 std::lock_guard< Mutex_Type > lock{
m_lock };
250 m_pending_indexes.push_back( index );
257 m_acceptor->call_accept_now( index );
265
266
267
268
269
276 not_null_pointer_t< connection_count_limits::impl::acceptor_callback_iface_t > acceptor,
277 max_parallel_connections_t ,
278 max_active_accepts_t )
290
291
292
301
302
303
304
305
306
307
308
309template<
typename Strand >
313
314
315
316
317
318
319
320
332
333
334
335
336
337
338
339
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373template<
typename Count_Manager >
380 not_null_pointer_t< Count_Manager > manager )
noexcept
401 swap( a.m_manager, b.m_manager );
408 other.m_manager =
nullptr;
424
425
426
427
428
429
430
436 not_null_pointer_t< noop_connection_count_limiter_t > )
noexcept
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457template<
typename Traits >
462 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 ...
Helper type for controlling the lifetime of the connection.
connection_lifetime_monitor_t & operator=(connection_lifetime_monitor_t &&other) noexcept
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 & operator=(const connection_lifetime_monitor_t &)=delete
not_null_pointer_t< Count_Manager > m_manager
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_parallel_connections_tag > max_parallel_connections_t
A kind of strict typedef for maximum count of active connections.
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.
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...
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
connection_count_limits::connection_lifetime_monitor_t< limiter_t > lifetime_monitor_t
A class to be used as null_mutex.