cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: When you disconnect the client from server...

From: Wei Weng <wweng_at_kencast.com>
Date: Thu, 6 Nov 2003 10:19:25 -0500 (EST)

try this program

I compiled with simply gcc -lcurl test.c

========= test.c ===============

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

size_t callback(void *clientp, double dltotal, double dlnow,
                double ultotal, double ulnow)
{
    printf("dltotal %f, dlnow %f, ultotal %f, ulnow %f\n",
           dltotal, dlnow, ultotal, ulnow);

    return 0;
}

int main()
{
    CURL* curl;
    int res;
    FILE* m_fstream;
    
    curl = curl_easy_init();

    m_fstream = fopen("/home/wweng/Test/vim.tar.bz2", "wb");

    if (!m_fstream)
    {
        printf("Error in opening file\n");
        return 0;
    }
    
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl, CURLOPT_URL,
"ftp://ftp.vim.org/pub/vim/unix/vim-6.2.tar.bz2");
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, m_fstream);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, callback);

    printf("Begin curl_easy_perform\n");
    res = curl_easy_perform(curl);

    if (m_fstream)
        fclose(m_fstream);
    
    curl_easy_cleanup(curl);

    return 1;
}

========== end of test.c ===================

Try to unplug the cable in the middle of transfer, you will see that the
progress function gets called over and over again, the message gets
printed out. And if you plug the cable back in, the transfer resumes, and
goes on.

Please DO NOT fix it if you think libcurl should have quitted. :) This
particular behavior is quite userful to me, but if we can have some
better control, (such as an option of setting how many times libcurl is
going to "retry") it is even better!

Thanks

Wei

On Thu, 6 Nov 2003, Daniel Stenberg wrote:

> On Wed, 5 Nov 2003, Wei Weng wrote:
>
> > The program went into a seemingly endless loop because of the loss of
> > connection. How many times is it going to retry until it bails out?
>
> libcurl doesn't retry connections at all.
>
> > Is there anyway to control that behavior?
>
> Control what behavior?
>
> > BTW if I plug the cable back in, it didn't resume.
>
> Can you please be slightly more specific and include some details?
>
>

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-11-06