RESTinio
Public Member Functions | Private Member Functions | Private Attributes | List of all members
restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type > Class Template Reference

Actual implementation of connection count limiter. More...

#include <connection_count_limiter.hpp>

Public Member Functions

 actual_limiter_t (not_null_pointer_t< acceptor_callback_iface_t > acceptor, max_parallel_connections_t max_parallel_connections, max_active_accepts_t max_pending_indexes)
 
 actual_limiter_t (const actual_limiter_t &)=delete
 
 actual_limiter_t (actual_limiter_t &&)=delete
 
void increment_parallel_connections () noexcept
 
void decrement_parallel_connections () noexcept
 
void accept_next (std::size_t index) noexcept
 

Private Member Functions

RESTINIO_NODISCARD bool has_free_slots () const noexcept
 

Private Attributes

Mutex_Type m_lock
 Lock object to be used. More...
 
not_null_pointer_t< acceptor_callback_iface_tm_acceptor
 Mandatory pointer to the acceptor connected with this limiter. More...
 
std::size_t m_active_accepts { 0u }
 The counter of active accept() operations. More...
 
std::size_t m_connections { 0u }
 The counter of active connections. More...
 
const std::size_t m_max_parallel_connections
 The limit for parallel connections. More...
 
std::vector< std::size_t > m_pending_indexes
 The storage for holding pending socket's slots. More...
 

Detailed Description

template<typename Mutex_Type>
class restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >

Actual implementation of connection count limiter.

Note
This is not Copyable nor Moveable type.
Template Parameters
Mutex_TypeType of mutex to be used for protection of limiter object. It is expected to be std::mutex or null_mutex_t.
Since
v.0.6.12

Definition at line 115 of file connection_count_limiter.hpp.

Constructor & Destructor Documentation

◆ actual_limiter_t() [1/3]

template<typename Mutex_Type >
restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::actual_limiter_t ( not_null_pointer_t< acceptor_callback_iface_t acceptor,
max_parallel_connections_t  max_parallel_connections,
max_active_accepts_t  max_pending_indexes 
)
inline

Definition at line 175 of file connection_count_limiter.hpp.

◆ actual_limiter_t() [2/3]

template<typename Mutex_Type >
restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::actual_limiter_t ( const actual_limiter_t< Mutex_Type > &  )
delete

◆ actual_limiter_t() [3/3]

template<typename Mutex_Type >
restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::actual_limiter_t ( actual_limiter_t< Mutex_Type > &&  )
delete

Member Function Documentation

◆ accept_next()

template<typename Mutex_Type >
void restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::accept_next ( std::size_t  index)
inlinenoexcept

This method either calls acceptor_callback_iface_t::call_accept_now() (in that case m_active_accepts is incremented) or stores index into the internal storage.

Definition at line 236 of file connection_count_limiter.hpp.

◆ decrement_parallel_connections()

template<typename Mutex_Type >
void restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::decrement_parallel_connections ( )
inlinenoexcept

Definition at line 202 of file connection_count_limiter.hpp.

◆ has_free_slots()

template<typename Mutex_Type >
RESTINIO_NODISCARD bool restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::has_free_slots ( ) const
inlineprivatenoexcept

Definition at line 169 of file connection_count_limiter.hpp.

◆ increment_parallel_connections()

template<typename Mutex_Type >
void restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::increment_parallel_connections ( )
inlinenoexcept

Definition at line 189 of file connection_count_limiter.hpp.

Member Data Documentation

◆ m_acceptor

template<typename Mutex_Type >
not_null_pointer_t< acceptor_callback_iface_t > restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::m_acceptor
private

Mandatory pointer to the acceptor connected with this limiter.

Definition at line 121 of file connection_count_limiter.hpp.

◆ m_active_accepts

template<typename Mutex_Type >
std::size_t restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::m_active_accepts { 0u }
private

The counter of active accept() operations.

Incremented every time the acceptor_callback_iface_t::call_accept_now() is invoked. Decremented in increment_parallel_connections().

Attention
It seems to be a fragile scheme because if there won't be a call to increment_parallel_connections() after the invocation of acceptor_callback_iface_t::call_accept_now() the value of m_active_accepts will be incorrect. But it is hard to invent a more bulletproof solution and it seems that the missing call to increment_parallel_connections() could be only on the shutdown of the acceptor.

Definition at line 138 of file connection_count_limiter.hpp.

◆ m_connections

template<typename Mutex_Type >
std::size_t restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::m_connections { 0u }
private

The counter of active connections.

This value is incremented in increment_parallel_connections() and decremented in decrement_parallel_connections().

Definition at line 146 of file connection_count_limiter.hpp.

◆ m_lock

template<typename Mutex_Type >
Mutex_Type restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::m_lock
private

Lock object to be used.

Definition at line 118 of file connection_count_limiter.hpp.

◆ m_max_parallel_connections

template<typename Mutex_Type >
const std::size_t restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::m_max_parallel_connections
private

The limit for parallel connections.

Definition at line 149 of file connection_count_limiter.hpp.

◆ m_pending_indexes

template<typename Mutex_Type >
std::vector< std::size_t > restinio::connection_count_limits::impl::actual_limiter_t< Mutex_Type >::m_pending_indexes
private

The storage for holding pending socket's slots.

Note
This storage is used as stack: new indexes are added to the end and are got from the end of the vector (LIFO working scheme).
Attention
The capacity for that storage is preallocated in the constructor so we don't expect any allocations during the usage of m_pending_indexes. This allows accept_next() method to be noexcept. But this works only if max_pending_indexes passed to the constructor is right.

Definition at line 165 of file connection_count_limiter.hpp.


The documentation for this class was generated from the following file: