cURL / Mailing Lists / curl-library / Single Mail

curl-library

Frequent calling of user progress callback

From: Bryan Henderson <bryanh_at_giraffe-data.com>
Date: 17 Mar 2007 19:10:01 +0000

Here is a patch to make the user progress get called as often as
Curl_pgrs() gets called, while the statistics get updated no more than
once each second and the builtin progress bar displays no more than
once each second.

This is meant to make transfers more interruptible.

The patch basically just moves a section of code, but in the process
has to convert a couple of gotos to structured code, so there is
indentation change and the patch is huge. Here is the diff ignoring
whitespace changes:

  == CHANGES TO lib/progress.c 1.81 (2007.03.11) ==
  == NOT A PATCH ==

@@ -281,8 +281,9 @@
      (data->progress.timespent>0?data->progress.timespent:1));
 
   if(data->progress.lastshow == Curl_tvlong(now))
- return 0; /* never update this more than once a second if the end isn't
+ ; /* never update this more than once a second if the end isn't
                  reached */
+ else {
   data->progress.lastshow = now.tv_sec;
 
   /* Let's do the "current speed" thing, which should use the fastest
@@ -343,22 +344,8 @@
       (data->progress.ulspeed>data->progress.dlspeed)?
       data->progress.ulspeed:data->progress.dlspeed;
 
- if(data->progress.flags & PGRS_HIDE)
- return 0;
-
- else if(data->set.fprogress) {
- /* There's a callback set, so we call that instead of writing
- anything ourselves. This really is the way to go. */
- result= data->set.fprogress(data->set.progress_client,
- (double)data->progress.size_dl,
- (double)data->progress.downloaded,
- (double)data->progress.size_ul,
- (double)data->progress.uploaded);
- if(result)
- failf(data, "Callback aborted");
- return result;
- }
-
+ if(!(data->progress & PGRS_HIDE) && !data->set.fprogress)
+ {
   /* Figure out the estimated time of arrival for the upload */
   if((data->progress.flags & PGRS_UL_SIZE_KNOWN) &&
      (data->progress.ulspeed>0) &&
@@ -419,6 +406,21 @@
 
   /* we flush the output stream to make it appear as soon as possible */
   fflush(data->set.err);
+ }
+ }
+
+ if(data->set.fprogress && !(data->progress & PGRS_HIDE)) {
+ /* There's a callback set, so we call that instead of writing
+ anything ourselves. This really is the way to go. */
+ result= data->set.fprogress(data->set.progress_client,
+ (double)data->progress.size_dl,
+ (double)data->progress.downloaded,
+ (double)data->progress.size_ul,
+ (double)data->progress.uploaded);
+ if(result)
+ failf(data, "Callback aborted");
+ return result;
+ }
 
   return 0;
 }

-- 
Bryan Henderson                                   San Jose, California

Received on 2007-03-17