curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

bug: downloading application will restart during the low network using libcurl.so.4

From: via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 6 Apr 2021 11:00:52 +0800

hi dear:
&nbsp; i &nbsp;met a problem.
&nbsp; when i use curl Executable file to download application with --limit-rate 10k it will download successfully. however, i use the libcurl to download application. when it almost finish, it will restart to download , the dlnow parameter will be zero, and re-download the application. it doesn't reach timeout.
&nbsp;&nbsp;

curl/libcurl version
 
libcurl.so.4.7.0 &nbsp;

curl 7.73.0 (x86_64-pc-linux-gnu)

operating system

 

ubuntu
 
 
./curl --limit-rate 10k -o http://139.9.131.244:6080/toms/downloads/APP/FD1C79ED97C1A34A22269865B2CCC7920C4BFFAF1EBA69D90C1020B7260D9873/ECR/0.9.66/ECR_0.9.66.NLD
 
 

 
#include "curl/curl.h"
 #include <stdio.h&gt;
 #include <stdlib.h&gt;
 #include <string.h&gt;
 #include <unistd.h&gt;
 #include <errno.h&gt;
 #include <sys/types.h&gt;
 #include <sys/stat.h&gt;
 #include <dirent.h&gt;
 #include <fcntl.h&gt;
 #include <sys/vfs.h&gt;

#define APP_FAIL (-1)
 #define APP_SUCC (0)

double gunHaveLoadFileSize = 0;

static size_t ProWriteDataFunc(void *buffer, size_t size, size_t nmemb, void user_p)
 {
 int nLen = write(((int *)user_p), buffer, size * nmemb);
 printf("dltotal ---- %d---\n", nLen);
 return nLen;
 }

static int HandleProgressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
 {
printf("dltotal ---- %lf---- dlnow %lf have %lf %lf\n", dltotal, dlnow, gunHaveLoadFileSize+ dlnow, gunHaveLoadFileSize); if(dltotal <=0 || dlnow <= 0) { return 0; } printf("process .... %lf %lf \n", dlnow+gunHaveLoadFileSize, dltotal+gunHaveLoadFileSize); return 0;
}

int main(int argc, char *argv[])
 {
 CURL *pCurl;
 CURLcode res;
 long lnRet;
 int i = 0;
curl_global_init(CURL_GLOBAL_ALL); pCurl = curl_easy_init(); if (NULL == pCurl) { printf("------init----fail----\n"); curl_global_cleanup(); return APP_FAIL; } int fd = open(argv[1], O_RDWR|O_CREAT|O_SYNC, 0666); if (fd <= 0){ printf("-----open file fail---\n"); curl_easy_cleanup(pCurl); curl_global_cleanup(); return APP_FAIL; } curl_easy_setopt(pCurl, CURLOPT_URL, argv[2]);
// curl_easy_setopt(pCurl, CURLOPT_VERBOSE, 1L);
 // curl_easy_setopt(pCurl, CURLOPT_DEBUGFUNCTION, ProOnDebug);
 curl_easy_setopt(pCurl, CURLOPT_CONNECTTIMEOUT, 20L);
 curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, 600L);
 curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYPEER, 0L);
 curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYHOST, 0L);
 curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, ProWriteDataFunc);
 curl_easy_setopt(pCurl, CURLOPT_FOLLOWLOCATION, 1);
 curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &amp;fd);
 curl_easy_setopt(pCurl, CURLOPT_PROGRESSDATA, NULL);
curl_easy_setopt(pCurl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(pCurl, CURLOPT_PROGRESSFUNCTION, HandleProgressCallback); curl_easy_setopt(pCurl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) 10 * 1024); for (i = 0; i<3; i++) { res = curl_easy_perform(pCurl); if (CURLE_OK == res) break; } close(fd); if(res == CURLE_OK) { res = curl_easy_getinfo(pCurl, CURLINFO_RESPONSE_CODE, &amp;lnRet); if ((CURLE_OK == res) &amp;&amp; (lnRet == 200)) { printf("success :res = %d, lnRet =%d\n", res, lnRet); } else { if(lnRet == 206) { printf("Partical content 206 SUCC\n"); } else { printf("download fail del lfs_del\n"); remove(argv[1]); } } } else { printf("FAIL: res = %d\n", res); } curl_easy_cleanup(pCurl); curl_global_cleanup(); return res;
 

}`
 ./a.out 1.NLD http://139.9.131.244:6080/toms/downloads/APP/FD1C79ED97C1A34A22269865B2CCC7920C4BFFAF1EBA69D90C1020B7260D9873/ECR/0.9.66/ECR_0.9.66.NLD &gt; 1.txt &amp;







please help me .

&nbsp;thanks

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.se/mail/etiquette.html
Received on 2021-04-06