curl / Mailing Lists / curl-library / Single Mail

curl-library

Re-using CURL handle

From: Marcin Kolny via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 25 Jul 2017 12:27:51 +0100

Hi,
I'm supporting retry functionality in my application. Currently, every time
when I do the request, I'm duplicating the curl handle, and if request
fails, I'm repeating the request using duplicated curl handle. So it looks
more or less like that:

CURL* handle = curl_easy_init();
/// set handle parameters like timeout, url, etc.
CURL* backup_handle = curl_easy_duphandle(handle);
curl_multi_add_handle(curl_multi_handle, handle);

// and then
if (result == CURLE_OPERATION_TIMEDOUT)
{
  curl_easy_cleanup(handle);
  handle = curl_easy_duphandle(backup_handle);
  curl_multi_add_handle(curl_multi_handle, handle)
}

This works fine, however, I'm wondering if this handle duplication is
necessary. Is it safe to re-use curl handle if the previous request has
failed? So the code would be:

CURL* handle = curl_easy_init();
/// set handle parameters like timeout, url, etc.
curl_multi_add_handle(curl_multi_handle, handle);

// and then
if (result == CURLE_OPERATION_TIMEDOUT)
{
  curl_multi_add_handle(curl_multi_handle, handle)}
}

Thanks,
Marcin

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-07-25