我有两个线程调用相同的例程来使用curl下载文件。如何使用curl同时打印正在下载的每个文件的进度?我认为curl指针是唯一可以区分正在进行的两次下载回调的变量。每次调用进程回调时,如何使用它来打印每个文件的进度?请建议。谢谢.Below是片段。
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;
}