curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Recovering from dropped connections with multi curl

From: doa379 <doa379_at_gmail.com>
Date: Wed, 15 Mar 2017 15:50:46 +0000

>> The problem I am having is with dropped internet connections when this
>> function is already running. In such situations I would like U = 0 so
>> that the main loop ends and the function returns back to its origin.
>> This isn't happening. Most of the time after the internet connection
>> is dropped and then re-established, the function is stuck in the main
>> while loop with U != 0.
>
> I suppose that's simply because libcurl didn't actually trigger an error
> for those cases so all that happened was that when the internet
> connection "dropped" your transfers stalled, waiting for the
> connectivity to come back. TCP is after all designed to work exactly
> like that.
>
> If you want to detect that better, you should consider setting
> CURLOPT_TCP_KEEPALIVE and/or to use some timeouts like
> CURLOPT_LOW_SPEED_LIMIT / CURLOPT_LOW_SPEED_TIME.
>

I'm still trying to work this out. I'm finding that the main function is
still getting unnecessarily stuck in the main while (U) loop for my
application. I would like the function to end whether or not data has
been received. I don't wish for it to keep hanging around at all. I
would appreciate any further suggestions.

Initialized easy_handle(s) eh:
curl_easy_setopt(eh, CURLOPT_TCP_KEEPALIVE, 1L);
curl_easy_setopt(eh, CURLOPT_TCP_KEEPIDLE, 10L);
curl_easy_setopt(eh, CURLOPT_TCP_KEEPINTVL, 2L);
curl_easy_setopt(eh, CURLOPT_LOW_SPEED_LIMIT, 1000L);
curl_easy_setopt(eh, CURLOPT_LOW_SPEED_TIME, 10L);

Main function:
// start
while (U)
{
   curl_multi_perform(curl_handle, &U);

   while ((msg = curl_multi_info_read(curl_handle, &Q)))
   {
     eh = msg->easy_handle;
     curl_easy_getinfo(eh, CURLINFO_RESPONSE_CODE, &http_response);

     if (msg->msg == CURLMSG_DONE &&
         (msg->data.result == CURLE_COULDNT_CONNECT ||
         msg->data.result == CURLE_OPERATION_TIMEDOUT ||
         msg->data.result == CURLE_COULDNT_RESOLVE_HOST ||
         http_response == 0 ||
         http_response == 200 ||
         http_response == 206));

     else U = 0;
   }

   if (U)
   {
     // FD Settings
   }
}

while ((msg = curl_multi_info_read(curl_handle, &Q)))
{
   eh = msg->easy_handle;
   curl_multi_remove_handle(curl_handle, eh);
   curl_easy_cleanup(eh);
}
// end
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-03-15