Kurlyk
Loading...
Searching...
No Matches
kurlyk::HttpRateLimitHandle Class Reference

RAII handle that owns a registered HTTP rate-limit ID. More...

#include <HttpRateLimitHandle.hpp>

Public Member Functions

 HttpRateLimitHandle (const HttpRateLimitHandle &)=delete
HttpRateLimitHandleoperator= (const HttpRateLimitHandle &)=delete
 ~HttpRateLimitHandle ()
 Destroys the handle and releases the owned rate-limit entry.
long id () const
 Returns immutable rate-limit ID associated with this handle.
 operator bool () const
 Checks whether the handle still owns a valid rate-limit ID.

Private Types

using remove_fn_t = std::function<void(long)>

Private Member Functions

 HttpRateLimitHandle (long id, remove_fn_t remove_fn)
 Creates a handle for a registered rate-limit ID.
void reset ()
 Releases the owned rate-limit entry once.

Private Attributes

long m_id = 0
 Owned rate-limit ID, or 0 after reset.
remove_fn_t m_remove_fn
 Callback that physically removes the rate-limit entry.

Friends

class HttpRateLimiter

Detailed Description

RAII handle that owns a registered HTTP rate-limit ID.

This object is intended to be stored through HttpRateLimitHandlePtr. Each copied std::shared_ptr keeps the corresponding rate-limit entry alive.

When the last shared handle is destroyed, the handle invokes the stored removal callback and physically removes the rate-limit entry from the owning rate limiter.

Note
The handle object itself is non-copyable. Copy HttpRateLimitHandlePtr instead.

Definition at line 22 of file HttpRateLimitHandle.hpp.

Member Typedef Documentation

◆ remove_fn_t

using kurlyk::HttpRateLimitHandle::remove_fn_t = std::function<void(long)>
private

Definition at line 47 of file HttpRateLimitHandle.hpp.

Constructor & Destructor Documentation

◆ HttpRateLimitHandle() [1/2]

kurlyk::HttpRateLimitHandle::HttpRateLimitHandle ( const HttpRateLimitHandle & )
delete

◆ ~HttpRateLimitHandle()

kurlyk::HttpRateLimitHandle::~HttpRateLimitHandle ( )
inline

Destroys the handle and releases the owned rate-limit entry.

Definition at line 28 of file HttpRateLimitHandle.hpp.

◆ HttpRateLimitHandle() [2/2]

kurlyk::HttpRateLimitHandle::HttpRateLimitHandle ( long id,
remove_fn_t remove_fn )
inlineprivate

Creates a handle for a registered rate-limit ID.

Parameters
idRegistered rate-limit ID.
remove_fnCallback used to physically remove the rate-limit entry.

Definition at line 52 of file HttpRateLimitHandle.hpp.

Member Function Documentation

◆ id()

long kurlyk::HttpRateLimitHandle::id ( ) const
inline

Returns immutable rate-limit ID associated with this handle.

Returns
Rate-limit ID, or 0 if the handle has already been reset.

Definition at line 34 of file HttpRateLimitHandle.hpp.

◆ operator bool()

kurlyk::HttpRateLimitHandle::operator bool ( ) const
inlineexplicit

Checks whether the handle still owns a valid rate-limit ID.

Returns
True if the handle owns a non-zero rate-limit ID.

Definition at line 40 of file HttpRateLimitHandle.hpp.

◆ operator=()

HttpRateLimitHandle & kurlyk::HttpRateLimitHandle::operator= ( const HttpRateLimitHandle & )
delete

◆ reset()

void kurlyk::HttpRateLimitHandle::reset ( )
inlineprivate

Releases the owned rate-limit entry once.

The ID is cleared before invoking the removal callback to prevent repeated removal if reset() is ever called more than once.

Definition at line 60 of file HttpRateLimitHandle.hpp.

◆ HttpRateLimiter

friend class HttpRateLimiter
friend

Definition at line 45 of file HttpRateLimitHandle.hpp.

Member Data Documentation

◆ m_id

long kurlyk::HttpRateLimitHandle::m_id = 0
private

Owned rate-limit ID, or 0 after reset.

Definition at line 70 of file HttpRateLimitHandle.hpp.

◆ m_remove_fn

remove_fn_t kurlyk::HttpRateLimitHandle::m_remove_fn
private

Callback that physically removes the rate-limit entry.

Definition at line 71 of file HttpRateLimitHandle.hpp.


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