I have some C++ code which sends REST requests periodically. Here are some 
options that are set and then the curl_easy_perform call (a HEAD message is 
being sent):

     curl_easy_setopt(mhCurl, CURLOPT_HTTPHEADER, chunk);
     curl_easy_setopt(mhCurl, CURLOPT_URL, f_szUrl.c_str());
     curl_easy_setopt(mhCurl, CURLOPT_CONNECTTIMEOUT, f_lTimeoutSec);
     curl_easy_setopt(mhCurl, CURLOPT_CUSTOMREQUEST, NULL);
     curl_easy_setopt(mhCurl, CURLOPT_NOBODY, 1L);
     curl_easy_setopt(mhCurl, CURLOPT_POST, 0L);
     curl_easy_setopt(mhCurl, CURLOPT_UPLOAD, 0L);
     curl_easy_setopt(mhCurl, CURLOPT_HEADERDATA, (void *)&rsp);
     ret = curl_easy_perform(mhCurl);

This is in executable running in Linux. At the Linux command line, if I do an 
ifdown on the network interface upon which the message is sent, then 
curl_easy_perform blocks and does not return.

The CURLOPT_CONNECTTIMEOUT value is 3 seconds, but that doesn't appear to be 
having an effect.

How do I get curl_easy_perform to return if the network interface is down? Is 
there an option to do this?

I noticed that there is a curl_multi_perform that doesn't block, but I'm hoping 
to not go that route, because that would require a different handle type that 
is used in multiple places in the code.

Should the interface somehow be checked before calling curl_easy_perform?



If the network is down, curl_easy_perform sends a return code. These are the timeout settings I regularly use:

const long dl_lowspeed_bytes = 1000; /* 1K */
const long dl_lowspeed_time = 10; /* sec */
/* bytes/sec */
curl_easy_setopt(<easy_handle>, CURLOPT_LOW_SPEED_LIMIT, dl_lowspeed_bytes);
/* seconds while below low speed limit before aborting */
curl_easy_setopt(<easy_handle>, CURLOPT_LOW_SPEED_TIME, dl_lowspeed_time);

There is no reason to fiddle with the Debian tools ifdown or ifup. Info: ifdown only works on the network interface and not the network connection.

Second, the curl multi handle is useful if you're doing a batch transfer (many connections in one go). You can still use it but it's not necessary for simple or one off transfers, or unless in scenarios where you have to care about rate limitation.
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html

Reply via email to