D++ (DPP)
C++ Discord API Bot Library
dpp::request_concurrency_queue Class Reference

Represents a timer instance in a pool handling requests to HTTP(S) servers. There are several of these, the total defined by a constant in cluster.cpp, and each one will always receive requests for the same rate limit bucket based on its endpoint portion of the url. This makes rate limit handling reliable and easy to manage. Each of these also has its own mutex, making it thread safe to call and use these from anywhere in the code. More...

#include <queues.h>

+ Collaboration diagram for dpp::request_concurrency_queue:

Public Member Functions

void tick_and_deliver_requests (uint32_t index)
 Timer callback. More...
 
 request_concurrency_queue (class cluster *owner, class request_queue *req_q, uint32_t index)
 Construct a new concurrency queue object. More...
 
 ~request_concurrency_queue ()
 Destroy the concurrency queue object This will stop the timer. More...
 
void terminate ()
 Flags the queue as terminating This will set the internal atomic bool that indicates this queue is to accept no more requests. More...
 
void post_request (std::unique_ptr< http_request > req)
 Post a http_request to this queue. More...
 

Public Attributes

int in_index {0}
 Queue index. More...
 
std::atomic< bool > terminating
 True if ending. More...
 
class request_queuerequests
 Request queue that owns this request_concurrency_queue. More...
 
class clustercreator
 The cluster that owns this request_concurrency_queue. More...
 
std::shared_mutex in_mutex
 Inbound queue mutex thread safety. More...
 
dpp::timer in_timer
 Inbound queue timer. The timer is called every second, and when it wakes up it checks for requests pending to be sent in the queue. If there are any requests and we are not waiting on rate limit, it will send them, else it will wait for the rate limit to expire. More...
 
std::map< std::string, bucket_tbuckets
 Rate-limit bucket counters. More...
 
std::vector< std::unique_ptr< http_request > > requests_in
 Queue of requests to be made. Sorted by http_request::endpoint. More...
 
std::vector< std::unique_ptr< http_request > > removals
 Requests to remove after a set amount of time has passed. More...
 

Detailed Description

Represents a timer instance in a pool handling requests to HTTP(S) servers. There are several of these, the total defined by a constant in cluster.cpp, and each one will always receive requests for the same rate limit bucket based on its endpoint portion of the url. This makes rate limit handling reliable and easy to manage. Each of these also has its own mutex, making it thread safe to call and use these from anywhere in the code.

Constructor & Destructor Documentation

◆ request_concurrency_queue()

dpp::request_concurrency_queue::request_concurrency_queue ( class cluster owner,
class request_queue req_q,
uint32_t  index 
)

Construct a new concurrency queue object.

Parameters
ownerOwning cluster
req_qOwning request queue
indexQueue index number, uniquely identifies this queue for hashing

◆ ~request_concurrency_queue()

dpp::request_concurrency_queue::~request_concurrency_queue ( )

Destroy the concurrency queue object This will stop the timer.

Member Function Documentation

◆ post_request()

void dpp::request_concurrency_queue::post_request ( std::unique_ptr< http_request req)

Post a http_request to this queue.

Parameters
reqhttp_request to post. The pointer will be freed when it has been executed.

◆ terminate()

void dpp::request_concurrency_queue::terminate ( )

Flags the queue as terminating This will set the internal atomic bool that indicates this queue is to accept no more requests.

◆ tick_and_deliver_requests()

void dpp::request_concurrency_queue::tick_and_deliver_requests ( uint32_t  index)

Timer callback.

Parameters
indexIndex ID for this timer

Member Data Documentation

◆ buckets

std::map<std::string, bucket_t> dpp::request_concurrency_queue::buckets

Rate-limit bucket counters.

◆ creator

class cluster* dpp::request_concurrency_queue::creator

The cluster that owns this request_concurrency_queue.

◆ in_index

int dpp::request_concurrency_queue::in_index {0}

Queue index.

◆ in_mutex

std::shared_mutex dpp::request_concurrency_queue::in_mutex

Inbound queue mutex thread safety.

◆ in_timer

dpp::timer dpp::request_concurrency_queue::in_timer

Inbound queue timer. The timer is called every second, and when it wakes up it checks for requests pending to be sent in the queue. If there are any requests and we are not waiting on rate limit, it will send them, else it will wait for the rate limit to expire.

◆ removals

std::vector<std::unique_ptr<http_request> > dpp::request_concurrency_queue::removals

Requests to remove after a set amount of time has passed.

◆ requests

class request_queue* dpp::request_concurrency_queue::requests

Request queue that owns this request_concurrency_queue.

◆ requests_in

std::vector<std::unique_ptr<http_request> > dpp::request_concurrency_queue::requests_in

Queue of requests to be made. Sorted by http_request::endpoint.

◆ terminating

std::atomic<bool> dpp::request_concurrency_queue::terminating

True if ending.

D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0