cURL / Mailing Lists / curl-library / Single Mail


Re: Progress function trigger time

From: Rob Ward <>
Date: Wed, 30 Nov 2011 11:52:45 +0000

On 30 November 2011 11:04, Saidus Bounderra <> wrote:

> Hi !! excuse me [?] for my confusion but if you can be more specific
> telling me
> where to put the timestamp & in which way !!
> thanks you
> -------------------------------------------------------------------
> List admin:
> Etiquette:

I think Daniel is referring to a mechanism such as the following(note this
is a hacky implementation and needs some cleaning up, you may also want to
use another source for the time etc but is does give a basic idea for how
tit can be implemented so something only happens in the progress function
every so often).

#include <stdio.h>
#include <curl/curl.h>
#include <sys/time.h>

struct timeval lastrun;

static int progress(void *p,
                    double dltotal, double dlnow,
                    double ultotal, double ulnow)
  struct timeval tv;

  if( (tv.tv_sec - lastrun.tv_sec) >= PROGRESS_INTERVAL)

    fprintf(stderr, "UP: %g of %g DOWN: %g of %g\r\n",
          ulnow, ultotal, dlnow, dltotal);
    //printf("\nnot doing anything\n");

  return 0;

static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
  int written = fwrite(ptr, size, nmemb, (FILE *)stream);
  return written;

int main(void)
  CURL *curl;
  CURLcode res=0;
  static const char *bodyfilename = "body.out";
  FILE *bodyfile;

  curl = curl_easy_init();
  if(curl) {

    bodyfile = fopen(bodyfilename,"w");
    if (bodyfile == NULL) {
      return -1;
    curl_easy_setopt(curl, CURLOPT_URL, "
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, bodyfile);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t)5000);

    res = curl_easy_perform(curl);

      fprintf(stderr, "%s\n", curl_easy_strerror(res));

    /* always cleanup */

  return (int)res;

Rob Ward

List admin:

Received on 2011-11-30