Hello.

I'm sharing this just in case there is interest. The real bug in my code
was unrelated to this.

A small test case is attached to help me explain. It's not a real-world
use case.

The 2m file is created with dd:
 dd if=/dev/urandom of=/tmp/2m bs=2M count=1

When running the test case on my laptop, I noticed the following:

 1- All required data is read fast.

 2- dlnow will report a completed transfer early on.
    (It only represents the size of data received/read).

 3- Not all data is flushed after writes
    (unless you uncomment the fflush line).

 4- libcurl will keep waiting until the speed limit is met on a now
    long interval.

 5- Finally, the remaining (unflushed) data is written.

I would have expected libcurl to:

 1- not wait needlessly when there is no more data to receive/read.

 2- not allow the size of data read, and the size written to be out of
    sync for that long. Maybe flushing should be used after writes!
#include <stdio.h>
#include <curl/curl.h>

int simple_progress(void *start, double dltotal, double dlnow, double ultotal, double ulnow) {
  //fflush(stdout);
  //fprintf(stderr, "dur=%lu, dltotal=%f, dlnow=%f, ultotal=%f, ulnow=%f\n", time(NULL) - *(time_t *)start , dltotal, dlnow, ultotal, ulnow);
  return 0;
}

int main(void)
{
  CURL *curl;
  CURLcode res;
  time_t start = time(NULL);

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "file:///tmp/2m");
    curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, 4096);

    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0l);
    curl_easy_setopt(curl , CURLOPT_PROGRESSFUNCTION, &simple_progress);
    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &start);

    res = curl_easy_perform(curl);
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    curl_easy_cleanup(curl);
  }
  return 0;
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to