cURL / Mailing Lists / curl-library / Single Mail

curl-library

Resume transfer question

From: Stanislav Samolenkov <stans_at_fromru.com>
Date: Fri, 16 Aug 2002 14:58:01 +0400 (MSD)

It's uneasy that libcurl doesn't perform transfer
resuming just inside itself. The task is to be
carried on by outer code. Upon receiving termination
code returned by curl_easy_perform() one should
decide retry transfer or abort. Please, advice -
which of the errors (CURLcode) may be considered as
making retry resonable? Which of except
CURLE_PARTIAL_FILE?
 
Suppose transfer interrupted by remote system and I
got CURLE_PARTIAL_FILE. If I start resume transfer I
can encounter another error like
CURLE_COULDNT_CONNECT that may mean remote system
died or FTP server process died. So it is resonable
to retry transfer in some time (10-30 sec, suppose).
There may be also other errors kind of
CURLE_COULDNT_CONNECT. What are they?
 
Currently source code is
 
unsigned long TimeLeft = ulTimeout;
                time_t start_t, curr_t;
                time(&start_t);
 
                int trynum =
CAdvFTPClient::s_NumberOfAttempts;
                bool loop = true;
                                 
                while( loop )
                {
                        // Adjust timeout
                        time(&curr_t);
 
                        TimeLeft = ulTimeout - (curr_t -
start_t);
 
                        if(TimeLeft <= 0)
                        {
                                // Timeout
                                loop = false;
                                break;
                        }
 
                        td.Timeout = TimeLeft;
 
                        // Try to transfer
                        CURLcode res =
CurlTransferFile(&td);
 
                        trynum--;
 
                        // Process result
                        switch( res )
                        {
                                case CURLE_OK:
                                        // Ok
                                        loop = false;
                                break;
                                 
                                case CURLE_PARTIAL_FILE:
                                        // Only part of
file dwonloaded
                                        // Try to resume
transfer
                                        if(trynum > 0)
                                        {
                                                
SLEEP(CAdvFTPClient::s_AfterPartialFileDelay);
                                                
td.ResumeFrom = ftell(td.File);
                                                continue;
                                        }
                                        else
                                        {
                                                loop =
false;
                                        }
                                break;
 
                                // Try to download once
more
                                case
CURLE_COULDNT_CONNECT:
                                case
CURLE_FTP_WEIRD_SERVER_REPLY:
                                case
CURLE_FTP_CANT_RECONNECT:
                                case
CURLE_FTP_COULDNT_RETR_FILE:
                                case
CURLE_FTP_BAD_DOWNLOAD_RESUME:
                                        // Above errors
suggest to retry transfer
                                        if(trynum > 0)
                                        {
                                                
SLEEP(CAdvFTPClient::s_AfterErrorDelay);
                                                
td.ResumeFrom = ftell(td.File);
                                                continue;
                                        }
                                        else
                                        {
                                                loop =
false;
                                        }
                                break;
                                 
                                default:
                                        // Stop transfer
                                        loop = false;
                        }
                }
 
                if(td.CurlCode == CURLE_OK)
                {
                        OnDownloadOk(&td);
                }
                else
                {
                        OnDownLoadError(&td);
                }
 
 
 
 
 

-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
Received on 2002-08-16