Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Curl:多个下载进度的回调_C_Curl_Libcurl - Fatal编程技术网

Curl:多个下载进度的回调

Curl:多个下载进度的回调,c,curl,libcurl,C,Curl,Libcurl,我有两个线程调用同一个例程来使用curl下载文件。如何使用curl打印同时下载的每个文件的进度?我认为curl-pointer是唯一能够区分两个正在进行的下载的变量。每次调用progress callback时,如何使用它打印每个文件的进度?请给出建议。谢谢。下面是代码片段 struct myprog { char filename[10]; } static int txfrprogress(void *p, curl_off_t dltotal, c

我有两个线程调用同一个例程来使用curl下载文件。如何使用curl打印同时下载的每个文件的进度?我认为curl-pointer是唯一能够区分两个正在进行的下载的变量。每次调用progress callback时,如何使用它打印每个文件的进度?请给出建议。谢谢。下面是代码片段

struct myprog
{
   char filename[10];
}

static int txfrprogress(void *p,
                curl_off_t  dltotal, curl_off_t  dlnow,
                curl_off_t  ultotal, curl_off_t  ulnow)
{
   static L7_uint32 cnt=0;
   L7_uchar8 buf[32] = {0};
   struct myprog *mp = (struct myprog*)p;

   cnt++;
   if(!(cnt%15000)) {
     sprintf(buf,"%3d%%",(int)((dlnow/dltotal)*100));
     printf("Completed %s download for %s\n",buf,mp->filename);
   }

   return 0;
}

int mymain(char *str) 
{
 struct myprog prog= {0};
 char filename[10]={0};
 CURL *curl;
 /*copy namestring received as arguement into filename*/
 curl_global_init(CURL_GLOBAL_DEFAULT);
 strcpy(prog.filename,filename);
 curl = curl_easy_init();
 curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, txfrprogress);
 curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog);
 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
 /*some code**/
 return 0;
}
您可以使用指针指向您的结构,例如,该结构包含标识单个传输所需的任何内容。这可能是一个CURL*、一个数字、一个ID、一个文件名或任何你认为合适的东西。或者所有这些。

您可以使用指针指向您的结构,例如,该结构包含标识单个传输所需的任何内容。这可能是一个CURL*、一个数字、一个ID、一个文件名或任何你认为合适的东西。或者所有这些