Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::connection_guard Class Reference

RAII guard for connection limiting. More...

#include <rate_limiter.h>

Collaboration diagram for kcenon::network::connection_guard:
Collaboration graph

Public Member Functions

 connection_guard (connection_limiter &limiter)
 Construct guard and try to accept connection.
 
 connection_guard (const connection_guard &)=delete
 Non-copyable.
 
connection_guardoperator= (const connection_guard &)=delete
 
 connection_guard (connection_guard &&other) noexcept
 Movable.
 
connection_guardoperator= (connection_guard &&other) noexcept
 
 ~connection_guard ()
 
bool accepted () const noexcept
 Check if connection was accepted.
 
 operator bool () const noexcept
 Explicit bool conversion.
 
void release () noexcept
 Release the connection early.
 

Private Attributes

connection_limiterlimiter_
 
bool accepted_
 

Detailed Description

RAII guard for connection limiting.

Automatically registers/unregisters connection on construction/destruction.

Definition at line 411 of file rate_limiter.h.

Constructor & Destructor Documentation

◆ connection_guard() [1/3]

kcenon::network::connection_guard::connection_guard ( connection_limiter & limiter)
inlineexplicit

Construct guard and try to accept connection.

Parameters
limiterConnection limiter
Examples
/home/runner/work/network_system/network_system/src/internal/utils/rate_limiter.h.

Definition at line 417 of file rate_limiter.h.

418 : limiter_(&limiter)
419 , accepted_(limiter.try_accept()) {}

◆ connection_guard() [2/3]

kcenon::network::connection_guard::connection_guard ( const connection_guard & )
delete

Non-copyable.

◆ connection_guard() [3/3]

kcenon::network::connection_guard::connection_guard ( connection_guard && other)
inlinenoexcept

Movable.

Definition at line 426 of file rate_limiter.h.

427 : limiter_(other.limiter_)
428 , accepted_(other.accepted_) {
429 other.accepted_ = false;
430 }

◆ ~connection_guard()

kcenon::network::connection_guard::~connection_guard ( )
inline
Examples
/home/runner/work/network_system/network_system/src/internal/utils/rate_limiter.h.

Definition at line 442 of file rate_limiter.h.

442 {
443 release();
444 }
void release() noexcept
Release the connection early.

References release().

Here is the call graph for this function:

Member Function Documentation

◆ accepted()

bool kcenon::network::connection_guard::accepted ( ) const
inlinenodiscardnoexcept

Check if connection was accepted.

Returns
true if connection was successfully accepted
Examples
/home/runner/work/network_system/network_system/src/internal/utils/rate_limiter.h.

Definition at line 450 of file rate_limiter.h.

450 {
451 return accepted_;
452 }

References accepted_.

◆ operator bool()

kcenon::network::connection_guard::operator bool ( ) const
inlineexplicitnoexcept

Explicit bool conversion.

Definition at line 457 of file rate_limiter.h.

457 {
458 return accepted_;
459 }

References accepted_.

◆ operator=() [1/2]

connection_guard & kcenon::network::connection_guard::operator= ( connection_guard && other)
inlinenoexcept

Definition at line 432 of file rate_limiter.h.

432 {
433 if (this != &other) {
434 release();
435 limiter_ = other.limiter_;
436 accepted_ = other.accepted_;
437 other.accepted_ = false;
438 }
439 return *this;
440 }

References accepted_, limiter_, and release().

Here is the call graph for this function:

◆ operator=() [2/2]

connection_guard & kcenon::network::connection_guard::operator= ( const connection_guard & )
delete

◆ release()

void kcenon::network::connection_guard::release ( )
inlinenoexcept

Release the connection early.

Examples
/home/runner/work/network_system/network_system/src/internal/utils/rate_limiter.h.

Definition at line 464 of file rate_limiter.h.

464 {
465 if (accepted_ && limiter_) {
467 accepted_ = false;
468 }
469 }
void on_disconnect() noexcept
Unregister a connection.

References accepted_, limiter_, and kcenon::network::connection_limiter::on_disconnect().

Referenced by operator=(), and ~connection_guard().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ accepted_

bool kcenon::network::connection_guard::accepted_
private

◆ limiter_

connection_limiter* kcenon::network::connection_guard::limiter_
private

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