curl / Mailing Lists / curl-library / Single Mail


RE: curl_easy_perform blocks when ifdown the ntwk interface

From: Matthews, Jeremy via curl-library <>
Date: Tue, 13 Nov 2018 17:41:55 +0000

Thank you for your input.

Well, curl_easy_perform did appear to block. When the interface was down, the function did not return, let alone return an error code.

I have made this change:

< curl_easy_setopt(mhCurl, CURLOPT_CONNECTTIMEOUT, f_lTimeoutSec);
> curl_easy_setopt(mhCurl, CURLOPT_TIMEOUT, f_lTimeoutSec);

...and curl_easy_perform now returns and with the expected return code of 45 (CURLE_INTERFACE_FAILED).

Could there be an issue here with curl_easy_perform (and the earlier option) if the interface is down?

I usually do not fiddle with ifdown and ifup. I was just trying to simulate a network issue.



From: curl-library <> On Behalf Of
Sent: Tuesday, November 13, 2018 5:00 AM
Subject: curl-library Digest, Vol 159, Issue 11

NOTICE: This email was received from an EXTERNAL sender

Send curl-library mailing list submissions to<>

To subscribe or unsubscribe via the World Wide Web, visit<>
or, via email, send a message with subject or body 'help' to<>

You can reach the person managing the list at<>

When replying, please edit your Subject line so it is more specific
than "Re: Contents of curl-library digest..."

Today's Topics:

1. Re: curl_easy_perform blocks when ifdown the ntwk interface


Message: 1
Date: Mon, 12 Nov 2018 13:03:23 +0000
From: doa379 <<>>
Subject: Re: curl_easy_perform blocks when ifdown the ntwk interface
Message-ID: <<>>
Content-Type: text/plain; charset=utf-8; format=flowed

> 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.


Subject: Digest Footer

curl-library mailing list<><>


End of curl-library Digest, Vol 159, Issue 11

Notice: This e-mail together with any attachments may contain information of Ribbon Communications Inc. that
is confidential and/or proprietary for the sole use of the intended recipient. Any review, disclosure, reliance or
distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended
recipient, please notify the sender immediately and then delete all copies, including any attachments.

Received on 2018-11-13