Hello! I have a problem with adding/removing handlers with running multi_handler. The use case is quite common: i need to make several requests and retry then in case of failure. I'm using curl_multi to run those requests in parallel and i remove handlers for the failed requests from the curl multi handler and replace them with a new ones. It can be written in pseudocode as:
auto multi_handle = curl_multi_init(); while(have_tasks){ auto easy_handle = curl_easy_init(); curl_multi_add_handle(multi_handle, easy_handle); curl_easy_setopt(m_handle, CURLOPT_URL, "http://www.example.org"); } //Here goes the main loop curl_multi_perform(multi_handle, &running_handles); while(running_handles>0){ curl_multi_wait(multi_handle) while(curl_multi_info_read(multi_handle) { if(CURLMSG_DONE) { //success curl_multi_remove_handle(multi_handle, easy_handle); curl_easy_cleanup(easy_handle); } else { //Failure, need to retry curl_multi_remove_handle(multi_handle, easy_handle); curl_easy_cleanup(easy_handle); auto easy_handle = curl_easy_init(); curl_multi_add_handle(multi_handle, easy_handle); curl_easy_setopt(m_handle, CURLOPT_URL, "http://www.example.org"); } curl_multi_perform(multi_handle, &running_handles); } The full code (with stripped error handling and data handling) is published at [1] The problem is that when i have just a single request to process and that request fails for some reason, so it's get recreated, the following curl_multi_perform returns running_handlers equal to zero, despite that fact, that i just added a new unprocessed handle, which is not what i expect. So, the question is - what i'm doing wrong and what is the correct way to implement retries in that case, without recreating new multi handle? [1] https://pastebin.com/Tk7LEe5f
------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.html