|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Connection count limiter. More...
#include <rate_limiter.h>

Public Member Functions | |
| connection_limiter (size_t max_connections=1000) | |
| Construct connection limiter. | |
| bool | can_accept () const noexcept |
| Check if a new connection can be accepted. | |
| bool | try_accept () noexcept |
| Try to accept a connection. | |
| void | on_connect () noexcept |
| Register a new connection. | |
| void | on_disconnect () noexcept |
| Unregister a connection. | |
| size_t | current () const noexcept |
| Get current connection count. | |
| size_t | max () const noexcept |
| Get maximum connection limit. | |
| void | set_max (size_t max_connections) noexcept |
| Set maximum connection limit. | |
| size_t | available () const noexcept |
| Get available connection slots. | |
| bool | at_capacity () const noexcept |
| Check if at capacity. | |
Private Attributes | |
| size_t | max_connections_ |
| std::atomic< size_t > | current_connections_ |
Connection count limiter.
Limits the number of concurrent connections to prevent resource exhaustion attacks.
This class is thread-safe. All public methods can be called from multiple threads concurrently.
Definition at line 305 of file rate_limiter.h.
|
inlineexplicit |
Construct connection limiter.
| max_connections | Maximum allowed concurrent connections |
Definition at line 311 of file rate_limiter.h.
|
inlinenodiscardnoexcept |
Check if at capacity.
Definition at line 397 of file rate_limiter.h.
References current_connections_, and max_connections_.
|
inlinenodiscardnoexcept |
Get available connection slots.
Definition at line 388 of file rate_limiter.h.
References current(), current_connections_, and max_connections_.

|
inlinenodiscardnoexcept |
Check if a new connection can be accepted.
Definition at line 319 of file rate_limiter.h.
References current_connections_, and max_connections_.
Referenced by kcenon::network::per_client_connection_limiter::try_accept().

|
inlinenodiscardnoexcept |
Get current connection count.
Definition at line 364 of file rate_limiter.h.
References current_connections_.
Referenced by available(), kcenon::network::per_client_connection_limiter::total_connections(), and try_accept().

|
inlinenodiscardnoexcept |
Get maximum connection limit.
Definition at line 372 of file rate_limiter.h.
References max_connections_.
|
inlinenoexcept |
Register a new connection.
Definition at line 345 of file rate_limiter.h.
References current_connections_.
|
inlinenoexcept |
Unregister a connection.
Definition at line 352 of file rate_limiter.h.
References current_connections_.
Referenced by kcenon::network::connection_guard::release(), and kcenon::network::per_client_connection_limiter::release().

|
inlinenoexcept |
Set maximum connection limit.
| max_connections | New maximum |
Definition at line 380 of file rate_limiter.h.
References max_connections_.
|
inlinenodiscardnoexcept |
Try to accept a connection.
Definition at line 327 of file rate_limiter.h.
References current(), current_connections_, and max_connections_.
Referenced by kcenon::network::per_client_connection_limiter::try_accept().


|
private |
Definition at line 403 of file rate_limiter.h.
Referenced by at_capacity(), available(), can_accept(), current(), on_connect(), on_disconnect(), and try_accept().
|
private |
Definition at line 402 of file rate_limiter.h.
Referenced by at_capacity(), available(), can_accept(), max(), set_max(), and try_accept().