Kurlyk
Toggle main menu visibility
Loading...
Searching...
No Matches
HttpRateLimitHandle.hpp
Go to the documentation of this file.
1
#pragma once
2
#ifndef _KURLYK_HTTP_RATE_LIMIT_HANDLE_HPP_INCLUDED
3
#define _KURLYK_HTTP_RATE_LIMIT_HANDLE_HPP_INCLUDED
4
7
8
namespace
kurlyk
{
9
22
class
HttpRateLimitHandle
{
23
public
:
24
HttpRateLimitHandle
(
const
HttpRateLimitHandle
&) =
delete
;
25
HttpRateLimitHandle
&
operator=
(
const
HttpRateLimitHandle
&) =
delete
;
26
28
~HttpRateLimitHandle
() {
29
reset
();
30
}
31
34
long
id
()
const
{
35
return
m_id
;
36
}
37
40
explicit
operator
bool()
const
{
41
return
m_id
!= 0;
42
}
43
44
private
:
45
friend
class
HttpRateLimiter
;
46
47
using
remove_fn_t
= std::function<void(
long
)>;
48
52
HttpRateLimitHandle
(
long
id
,
remove_fn_t
remove_fn)
53
:
m_id
(
id
),
54
m_remove_fn
(
std
::move(remove_fn)) {}
55
60
void
reset
() {
61
const
long
id
=
m_id
;
62
m_id
= 0;
63
64
if
(
id
!= 0 &&
m_remove_fn
) {
65
m_remove_fn
(
id
);
66
}
67
}
68
69
private
:
70
long
m_id
= 0;
71
remove_fn_t
m_remove_fn
;
72
};
73
78
using
HttpRateLimitHandlePtr
= std::shared_ptr<HttpRateLimitHandle>;
79
80
}
// namespace kurlyk
81
82
#endif
// _KURLYK_HTTP_RATE_LIMIT_HANDLE_HPP_INCLUDED
kurlyk::HttpRateLimitHandle::~HttpRateLimitHandle
~HttpRateLimitHandle()
Destroys the handle and releases the owned rate-limit entry.
Definition
HttpRateLimitHandle.hpp:28
kurlyk::HttpRateLimitHandle::HttpRateLimiter
friend class HttpRateLimiter
Definition
HttpRateLimitHandle.hpp:45
kurlyk::HttpRateLimitHandle::HttpRateLimitHandle
HttpRateLimitHandle(long id, remove_fn_t remove_fn)
Creates a handle for a registered rate-limit ID.
Definition
HttpRateLimitHandle.hpp:52
kurlyk::HttpRateLimitHandle::remove_fn_t
std::function< void(long)> remove_fn_t
Definition
HttpRateLimitHandle.hpp:47
kurlyk::HttpRateLimitHandle::operator=
HttpRateLimitHandle & operator=(const HttpRateLimitHandle &)=delete
kurlyk::HttpRateLimitHandle::m_id
long m_id
Owned rate-limit ID, or 0 after reset.
Definition
HttpRateLimitHandle.hpp:70
kurlyk::HttpRateLimitHandle::m_remove_fn
remove_fn_t m_remove_fn
Callback that physically removes the rate-limit entry.
Definition
HttpRateLimitHandle.hpp:71
kurlyk::HttpRateLimitHandle::id
long id() const
Returns immutable rate-limit ID associated with this handle.
Definition
HttpRateLimitHandle.hpp:34
kurlyk::HttpRateLimitHandle::reset
void reset()
Releases the owned rate-limit entry once.
Definition
HttpRateLimitHandle.hpp:60
kurlyk::HttpRateLimitHandle::HttpRateLimitHandle
HttpRateLimitHandle(const HttpRateLimitHandle &)=delete
kurlyk
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
kurlyk::HttpRateLimitHandlePtr
std::shared_ptr< HttpRateLimitHandle > HttpRateLimitHandlePtr
Shared RAII handle for HTTP rate limits.
Definition
HttpRateLimitHandle.hpp:78
std
Enables use of ClientError with std::error_code.
Definition
ClientErrorCategory.hpp:69
include
kurlyk
http
HttpRequestManager
HttpRateLimitHandle.hpp
Generated by
1.17.0