hi dear:
i met a problem.
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.
curl/libcurl version
libcurl.so.4.7.0
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>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/vfs.h>
#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, &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, &lnRet); if ((CURLE_OK == res) &&
(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
> 1.txt &
please help me .
thanks
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.se/mail/etiquette.html