1

I need to know the status of my download using libcurl in C. I found that I have to use CURLOPT_PROGRESSFUNCTION.

int progress_func(void* ptr, double TotalToDownload, double NowDownloaded, 
                    double TotalToUpload, double NowUploaded)
{
   //Bla bla
}

curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);

I can't understand two things: 1) This function progress_func "how often" is called? 2) How can I pass other parameters to progress_func function? Because I have to write the connection status (speed, tot downloaded) in a file with a variable url, so I have to pass this url to the function.

Thanks

usta
  • 6,699
  • 3
  • 22
  • 39
phcaze
  • 1,707
  • 5
  • 27
  • 58
  • See http://stackoverflow.com/questions/10614062/libcurl-console-progress-bar-for-file-download/10614757#10614757 for a detailed answer on progress bars. – jmc Jun 08 '12 at 10:28

1 Answers1

3

See CURLOPT_PROGRESSDATA:

struct my_progress_data_struct
{
    /* Some data fields */
};

struct my_progress_data_struct progress_data;

curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &progress_data);

The data will be passed in the ptr argument of the progress callback.

As for the first question, according to the API reference the callback will be called "roughly once per second or sooner".

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621