cURL / Mailing Lists / curl-library / Single Mail


Re: check internet connection with curl

From: Nikolai Kondrashov <>
Date: Fri, 25 Apr 2008 00:33:00 +0400

Meir Yanovich wrote:
> not so simple i don't want to show to the user any error , the program
> itself needs to do its best to recover when connection to the internet is
> loss there will be endless loop that will preform this checking every N
> seconds / min so now i trying to figure it what will be the best way to
> preform this check
BTW, If your request doesn't require some resources your program doesn't
posess (like uploading some user-specified file), you could just retry the
very request which needs the Internet connection you are waiting for.

I.e. instead of constantly sending HEAD's just try to send your GET/POST and
don't tell the user anything (well, maybe some little unobtrusive status
message), if curl_easy_perform returns CURLE_CONNECTION_FAILED or related,
and disturb the user only on grave matters.

Something like that:

while ((rc = curl_easy_perform(curl)) != CURLE_OK)
    switch (rc)
            fprintf(stderr, "Request failed: %s\n", curl_easy_strerror(rc));

fprintf(stderr, "Done\n");

Received on 2008-04-24