The curl_multi_poll function in conjunction with curl_multi_add_handle - for some reason it never waits for an event and immediately returns:
Simple example:
#include <iostream>
#include <curl.h>
int main()
{
curl_global_init(CURL_GLOBAL_ALL);
CURLM* CURLM_ = curl_multi_init();
CURL* CURL_ = curl_easy_init();
curl_easy_setopt(CURL_, CURLOPT_URL, "https://stackoverflow.com");
int num_desc_events;
curl_multi_add_handle(CURLM_, CURL_); //If this line is deleted, then curl_multi_poll enters waits mode.
if (CURLMcode_ != CURLM_OK)
{
std::cout << "curl_multi_add_handle_status:" << CURLMcode_ << std::endl;
}
while (1)
{
std::cout << "curl_multi_poll_start" << std::endl;
curl_multi_poll(CURLM_, NULL, 0, 100000, &num_desc_events);
if (CURLMcode_ != CURLM_OK)
{
std::cout << "curl_multi_poll_status:" << CURLMcode_ << std::endl;
}
std::cout << "curl_multi_poll_awakened" << std::endl;
std::cout << "num_desc_events:" << num_desc_events << std::endl;
}
curl_multi_cleanup(CURLM_);
curl_global_cleanup();
}
As you can see, this is a very simple code, but it works very strangely or even I would say that it does not work.
From the description of the curl_multi_poll function, it follows that it waits FOREVER until an event occurs on the mult descriptor or a set timeout.
That is, when there is a line with the curl_multi_add_handle function in the code, the curl_multi_poll function does not enter standby mode.
And if the line of code with the curl_multi_add_handle function is removed, then curl_multi_poll works correctly and enters standby mode until the first event, in this case indefinitely or until timeout.
CodePudding user response:
The code doesn't call curl_multi_perform() so it doesn't actually do anything and whatever libcurl wants to do, it still wants to do...
