2#ifndef _KURLYK_HTTP_MULTI_REQUEST_HANDLER_HPP_INCLUDED
3#define _KURLYK_HTTP_MULTI_REQUEST_HANDLER_HPP_INCLUDED
19 for (
auto& context : context_list) {
20# if __cplusplus >= 201402L
21 auto handler = std::make_unique<HttpRequestHandler>(std::move(context));
23 auto handler = std::unique_ptr<HttpRequestHandler>(
new HttpRequestHandler(std::move(context)));
25 CURL* curl = handler->get_curl();
36 CURL* curl = handler->get_curl();
46 int still_running = 0;
47 CURLMcode res = curl_multi_perform(
m_multi_handle, &still_running);
48 if (res != CURLM_OK)
return false;
51 while (CURLMsg* message = curl_multi_info_read(
m_multi_handle, &pending_messages)) {
52 if (message->msg != CURLMSG_DONE)
continue;
55 if (still_running == 0) {
70 void cancel_request_by_id(
const std::unordered_map<uint64_t, std::list<std::function<
void()>>>& to_cancel) {
73 uint64_t
id = (*it)->get_request_id();
74 if (!to_cancel.count(
id)) {
86 std::vector<std::unique_ptr<HttpRequestHandler>>
m_handlers;
92 CURL* curl = message->easy_handle;
95 curl_easy_getinfo(curl, CURLINFO_PRIVATE, &ptr);
99 if (!handler->handle_curl_message(message)) {
void cancel_request_by_id(const std::unordered_map< uint64_t, std::list< std::function< void()> > > &to_cancel)
Cancels HTTP requests based on their unique IDs.
std::list< std::unique_ptr< HttpRequestContext > > m_failed_requests
List of failed request contexts.
void handle_completed_request(CURLMsg *message)
Handles the completion of a single request.
bool process()
Processes the requests within the handler.
std::list< std::unique_ptr< HttpRequestContext > > extract_failed_requests()
Extracts the list of failed requests.
std::vector< std::unique_ptr< HttpRequestHandler > > m_handlers
Collection of active request handlers.
HttpBatchRequestHandler(std::vector< std::unique_ptr< HttpRequestContext > > &context_list)
Constructs a handler for managing multiple HTTP requests asynchronously.
~HttpBatchRequestHandler()
Cleans up the multi handle and removes all request handles.
CURLM * m_multi_handle
libcurl multi handle.
Manages asynchronous HTTP requests, including handling responses, retries, and error processing.
Primary namespace for the Kurlyk library, encompassing initialization, request management,...