Coverage Report

Created: 2025-10-10 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PROJ/curl/lib/progress.c
Line
Count
Source
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9
 *
10
 * This software is licensed as described in the file COPYING, which
11
 * you should have received as part of this distribution. The terms
12
 * are also available at https://curl.se/docs/copyright.html.
13
 *
14
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15
 * copies of the Software, and permit persons to whom the Software is
16
 * furnished to do so, under the terms of the COPYING file.
17
 *
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
 * KIND, either express or implied.
20
 *
21
 * SPDX-License-Identifier: curl
22
 *
23
 ***************************************************************************/
24
25
#include "curl_setup.h"
26
27
#include "urldata.h"
28
#include "sendf.h"
29
#include "multiif.h"
30
#include "progress.h"
31
#include "curlx/timeval.h"
32
33
/* check rate limits within this many recent milliseconds, at minimum. */
34
0
#define MIN_RATE_LIMIT_PERIOD 3000
35
36
#ifndef CURL_DISABLE_PROGRESS_METER
37
/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero
38
   byte) */
39
static void time2str(char *r, curl_off_t seconds)
40
0
{
41
0
  curl_off_t h;
42
0
  if(seconds <= 0) {
43
0
    strcpy(r, "--:--:--");
44
0
    return;
45
0
  }
46
0
  h = seconds / 3600;
47
0
  if(h <= 99) {
48
0
    curl_off_t m = (seconds - (h * 3600)) / 60;
49
0
    curl_off_t s = (seconds - (h * 3600)) - (m * 60);
50
0
    curl_msnprintf(r, 9, "%2" FMT_OFF_T ":%02" FMT_OFF_T ":%02" FMT_OFF_T,
51
0
                   h, m, s);
52
0
  }
53
0
  else {
54
    /* this equals to more than 99 hours, switch to a more suitable output
55
       format to fit within the limits. */
56
0
    curl_off_t d = seconds / 86400;
57
0
    h = (seconds - (d * 86400)) / 3600;
58
0
    if(d <= 999)
59
0
      curl_msnprintf(r, 9, "%3" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h);
60
0
    else
61
0
      curl_msnprintf(r, 9, "%7" FMT_OFF_T "d", d);
62
0
  }
63
0
}
64
65
/* The point of this function would be to return a string of the input data,
66
   but never longer than 6 columns (+ one zero byte).
67
   Add suffix k, M, G when suitable... */
68
static char *max6data(curl_off_t bytes, char *max6)
69
0
{
70
  /* a signed 64-bit value is 8192 petabytes maximum */
71
0
  const char unit[] = { 'k', 'M', 'G', 'T', 'P', 0 };
72
0
  int k = 0;
73
0
  if(bytes < 1000000) {
74
0
    curl_msnprintf(max6, 7, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
75
0
    return max6;
76
0
  }
77
78
0
  do {
79
0
    curl_off_t nbytes = bytes / 1024;
80
0
    if(nbytes < 1000) {
81
      /* xxx.yU */
82
0
      curl_msnprintf(max6, 7, "%3" CURL_FORMAT_CURL_OFF_T
83
0
                     ".%" CURL_FORMAT_CURL_OFF_T "%c", nbytes,
84
0
                     (bytes%1024) / (1024/10), unit[k]);
85
0
      break;
86
0
    }
87
0
    else if(nbytes < 100000) {
88
      /* xxxxxU */
89
0
      curl_msnprintf(max6, 7, "%5" CURL_FORMAT_CURL_OFF_T "%c",
90
0
                     nbytes, unit[k]);
91
0
      break;
92
0
    }
93
0
    bytes = nbytes;
94
0
    k++;
95
0
    DEBUGASSERT(unit[k]);
96
0
  } while(unit[k]);
97
0
  return max6;
98
0
}
99
#endif
100
101
/*
102
103
   New proposed interface, 9th of February 2000:
104
105
   pgrsStartNow() - sets start time
106
   pgrsSetDownloadSize(x) - known expected download size
107
   pgrsSetUploadSize(x) - known expected upload size
108
   pgrsSetDownloadCounter() - amount of data currently downloaded
109
   pgrsSetUploadCounter() - amount of data currently uploaded
110
   pgrsUpdate() - show progress
111
   pgrsDone() - transfer complete
112
113
*/
114
115
int Curl_pgrsDone(struct Curl_easy *data)
116
0
{
117
0
  int rc;
118
0
  data->progress.lastshow = 0;
119
0
  rc = Curl_pgrsUpdate(data); /* the final (forced) update */
120
0
  if(rc)
121
0
    return rc;
122
123
0
  if(!data->progress.hide && !data->progress.callback)
124
    /* only output if we do not use a progress callback and we are not
125
     * hidden */
126
0
    curl_mfprintf(data->set.err, "\n");
127
128
0
  data->progress.speeder_c = 0; /* reset the progress meter display */
129
0
  return 0;
130
0
}
131
132
/* reset the known transfer sizes */
133
void Curl_pgrsResetTransferSizes(struct Curl_easy *data)
134
0
{
135
0
  Curl_pgrsSetDownloadSize(data, -1);
136
0
  Curl_pgrsSetUploadSize(data, -1);
137
0
}
138
139
/*
140
 *
141
 * Curl_pgrsTimeWas(). Store the timestamp time at the given label.
142
 */
143
void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer,
144
                      struct curltime timestamp)
145
0
{
146
0
  timediff_t *delta = NULL;
147
148
0
  switch(timer) {
149
0
  default:
150
0
  case TIMER_NONE:
151
    /* mistake filter */
152
0
    break;
153
0
  case TIMER_STARTOP:
154
    /* This is set at the start of a transfer */
155
0
    data->progress.t_startop = timestamp;
156
0
    data->progress.t_startqueue = timestamp;
157
0
    data->progress.t_postqueue = 0;
158
0
    break;
159
0
  case TIMER_STARTSINGLE:
160
    /* This is set at the start of each single transfer */
161
0
    data->progress.t_startsingle = timestamp;
162
0
    data->progress.is_t_startransfer_set = FALSE;
163
0
    break;
164
0
  case TIMER_POSTQUEUE:
165
    /* Queue time is accumulative from all involved redirects */
166
0
    data->progress.t_postqueue +=
167
0
      curlx_timediff_us(timestamp, data->progress.t_startqueue);
168
0
    break;
169
0
  case TIMER_STARTACCEPT:
170
0
    data->progress.t_acceptdata = timestamp;
171
0
    break;
172
0
  case TIMER_NAMELOOKUP:
173
0
    delta = &data->progress.t_nslookup;
174
0
    break;
175
0
  case TIMER_CONNECT:
176
0
    delta = &data->progress.t_connect;
177
0
    break;
178
0
  case TIMER_APPCONNECT:
179
0
    delta = &data->progress.t_appconnect;
180
0
    break;
181
0
  case TIMER_PRETRANSFER:
182
0
    delta = &data->progress.t_pretransfer;
183
0
    break;
184
0
  case TIMER_STARTTRANSFER:
185
0
    delta = &data->progress.t_starttransfer;
186
    /* prevent updating t_starttransfer unless:
187
     *   1) this is the first time we are setting t_starttransfer
188
     *   2) a redirect has occurred since the last time t_starttransfer was set
189
     * This prevents repeated invocations of the function from incorrectly
190
     * changing the t_starttransfer time.
191
     */
192
0
    if(data->progress.is_t_startransfer_set) {
193
0
      return;
194
0
    }
195
0
    else {
196
0
      data->progress.is_t_startransfer_set = TRUE;
197
0
      break;
198
0
    }
199
0
  case TIMER_POSTRANSFER:
200
0
    delta = &data->progress.t_posttransfer;
201
0
    break;
202
0
  case TIMER_REDIRECT:
203
0
    data->progress.t_redirect = curlx_timediff_us(timestamp,
204
0
                                                 data->progress.start);
205
0
    data->progress.t_startqueue = timestamp;
206
0
    break;
207
0
  }
208
0
  if(delta) {
209
0
    timediff_t us = curlx_timediff_us(timestamp, data->progress.t_startsingle);
210
0
    if(us < 1)
211
0
      us = 1; /* make sure at least one microsecond passed */
212
0
    *delta += us;
213
0
  }
214
0
}
215
216
/*
217
 *
218
 * Curl_pgrsTime(). Store the current time at the given label. This fetches a
219
 * fresh "now" and returns it.
220
 *
221
 * @unittest: 1399
222
 */
223
struct curltime Curl_pgrsTime(struct Curl_easy *data, timerid timer)
224
0
{
225
0
  struct curltime now = curlx_now();
226
227
0
  Curl_pgrsTimeWas(data, timer, now);
228
0
  return now;
229
0
}
230
231
void Curl_pgrsStartNow(struct Curl_easy *data)
232
0
{
233
0
  struct Progress *p = &data->progress;
234
0
  p->speeder_c = 0; /* reset the progress meter display */
235
0
  p->start = curlx_now();
236
0
  p->is_t_startransfer_set = FALSE;
237
0
  p->ul.limit.start = p->start;
238
0
  p->dl.limit.start = p->start;
239
0
  p->ul.limit.start_size = 0;
240
0
  p->dl.limit.start_size = 0;
241
0
  p->dl.cur_size = 0;
242
0
  p->ul.cur_size = 0;
243
  /* the sizes are unknown at start */
244
0
  p->dl_size_known = FALSE;
245
0
  p->ul_size_known = FALSE;
246
0
  Curl_ratelimit(data, p->start);
247
0
}
248
249
/*
250
 * This is used to handle speed limits, calculating how many milliseconds to
251
 * wait until we are back under the speed limit, if needed.
252
 *
253
 * The way it works is by having a "starting point" (time & amount of data
254
 * transferred by then) used in the speed computation, to be used instead of
255
 * the start of the transfer. This starting point is regularly moved as
256
 * transfer goes on, to keep getting accurate values (instead of average over
257
 * the entire transfer).
258
 *
259
 * This function takes the current amount of data transferred, the amount at
260
 * the starting point, the limit (in bytes/s), the time of the starting point
261
 * and the current time.
262
 *
263
 * Returns 0 if no waiting is needed or when no waiting is needed but the
264
 * starting point should be reset (to current); or the number of milliseconds
265
 * to wait to get back under the speed limit.
266
 */
267
timediff_t Curl_pgrsLimitWaitTime(struct pgrs_dir *d,
268
                                  curl_off_t bytes_per_sec,
269
                                  struct curltime now)
270
0
{
271
0
  curl_off_t bytes = d->cur_size - d->limit.start_size;
272
0
  timediff_t should_ms;
273
0
  timediff_t took_ms;
274
275
  /* no limit or we did not get to any bytes yet */
276
0
  if(!bytes_per_sec || !bytes)
277
0
    return 0;
278
279
  /* The time it took us to have `bytes` */
280
0
  took_ms = curlx_timediff_ceil(now, d->limit.start);
281
282
  /* The time it *should* have taken us to have `bytes`
283
   * when obeying the bytes_per_sec speed_limit. */
284
0
  if(bytes < CURL_OFF_T_MAX/1000) {
285
    /* (1000 * bytes / (bytes / sec)) = 1000 * sec = ms */
286
0
    should_ms = (timediff_t) (1000 * bytes / bytes_per_sec);
287
0
  }
288
0
  else {
289
    /* very large `bytes`, first calc the seconds it should have taken.
290
     * if that is small enough, convert to milliseconds. */
291
0
    should_ms = (timediff_t) (bytes / bytes_per_sec);
292
0
    if(should_ms < TIMEDIFF_T_MAX/1000)
293
0
      should_ms *= 1000;
294
0
    else
295
0
      should_ms = TIMEDIFF_T_MAX;
296
0
  }
297
298
0
  if(took_ms < should_ms) {
299
    /* when gotten to `bytes` too fast, wait the difference */
300
0
    return should_ms - took_ms;
301
0
  }
302
0
  return 0;
303
0
}
304
305
/*
306
 * Set the number of downloaded bytes so far.
307
 */
308
CURLcode Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
309
0
{
310
0
  data->progress.dl.cur_size = size;
311
0
  return CURLE_OK;
312
0
}
313
314
/*
315
 * Update the timestamp and sizestamp to use for rate limit calculations.
316
 */
317
void Curl_ratelimit(struct Curl_easy *data, struct curltime now)
318
0
{
319
  /* do not set a new stamp unless the time since last update is long enough */
320
0
  if(data->set.max_recv_speed) {
321
0
    if(curlx_timediff(now, data->progress.dl.limit.start) >=
322
0
       MIN_RATE_LIMIT_PERIOD) {
323
0
      data->progress.dl.limit.start = now;
324
0
      data->progress.dl.limit.start_size = data->progress.dl.cur_size;
325
0
    }
326
0
  }
327
0
  if(data->set.max_send_speed) {
328
0
    if(curlx_timediff(now, data->progress.ul.limit.start) >=
329
0
       MIN_RATE_LIMIT_PERIOD) {
330
0
      data->progress.ul.limit.start = now;
331
0
      data->progress.ul.limit.start_size = data->progress.ul.cur_size;
332
0
    }
333
0
  }
334
0
}
335
336
/*
337
 * Set the number of uploaded bytes so far.
338
 */
339
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size)
340
0
{
341
0
  data->progress.ul.cur_size = size;
342
0
}
343
344
void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size)
345
0
{
346
0
  if(size >= 0) {
347
0
    data->progress.dl.total_size = size;
348
0
    data->progress.dl_size_known = TRUE;
349
0
  }
350
0
  else {
351
0
    data->progress.dl.total_size = 0;
352
0
    data->progress.dl_size_known = FALSE;
353
0
  }
354
0
}
355
356
void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
357
0
{
358
0
  if(size >= 0) {
359
0
    data->progress.ul.total_size = size;
360
0
    data->progress.ul_size_known = TRUE;
361
0
  }
362
0
  else {
363
0
    data->progress.ul.total_size = 0;
364
0
    data->progress.ul_size_known = FALSE;
365
0
  }
366
0
}
367
368
void Curl_pgrsEarlyData(struct Curl_easy *data, curl_off_t sent)
369
0
{
370
0
    data->progress.earlydata_sent = sent;
371
0
}
372
373
/* returns the average speed in bytes / second */
374
static curl_off_t trspeed(curl_off_t size, /* number of bytes */
375
                          curl_off_t us)   /* microseconds */
376
0
{
377
0
  if(us < 1)
378
0
    return size * 1000000;
379
0
  else if(size < CURL_OFF_T_MAX/1000000)
380
0
    return (size * 1000000) / us;
381
0
  else if(us >= 1000000)
382
0
    return size / (us / 1000000);
383
0
  else
384
0
    return CURL_OFF_T_MAX;
385
0
}
386
387
/* returns TRUE if it is time to show the progress meter */
388
static bool progress_calc(struct Curl_easy *data, struct curltime now)
389
0
{
390
0
  bool timetoshow = FALSE;
391
0
  struct Progress * const p = &data->progress;
392
393
  /* The time spent so far (from the start) in microseconds */
394
0
  p->timespent = curlx_timediff_us(now, p->start);
395
0
  p->dl.speed = trspeed(p->dl.cur_size, p->timespent);
396
0
  p->ul.speed = trspeed(p->ul.cur_size, p->timespent);
397
398
  /* Calculations done at most once a second, unless end is reached */
399
0
  if(p->lastshow != now.tv_sec) {
400
0
    int countindex; /* amount of seconds stored in the speeder array */
401
0
    int nowindex = p->speeder_c% CURR_TIME;
402
0
    p->lastshow = now.tv_sec;
403
0
    timetoshow = TRUE;
404
405
    /* Let's do the "current speed" thing, with the dl + ul speeds
406
       combined. Store the speed at entry 'nowindex'. */
407
0
    p->speeder[ nowindex ] = p->dl.cur_size + p->ul.cur_size;
408
409
    /* remember the exact time for this moment */
410
0
    p->speeder_time [ nowindex ] = now;
411
412
    /* advance our speeder_c counter, which is increased every time we get
413
       here and we expect it to never wrap as 2^32 is a lot of seconds! */
414
0
    p->speeder_c++;
415
416
    /* figure out how many index entries of data we have stored in our speeder
417
       array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of
418
       transfer. Imagine, after one second we have filled in two entries,
419
       after two seconds we have filled in three entries etc. */
420
0
    countindex = ((p->speeder_c >= CURR_TIME) ? CURR_TIME : p->speeder_c) - 1;
421
422
    /* first of all, we do not do this if there is no counted seconds yet */
423
0
    if(countindex) {
424
0
      int checkindex;
425
0
      timediff_t span_ms;
426
0
      curl_off_t amount;
427
428
      /* Get the index position to compare with the 'nowindex' position.
429
         Get the oldest entry possible. While we have less than CURR_TIME
430
         entries, the first entry will remain the oldest. */
431
0
      checkindex = (p->speeder_c >= CURR_TIME) ? p->speeder_c%CURR_TIME : 0;
432
433
      /* Figure out the exact time for the time span */
434
0
      span_ms = curlx_timediff(now, p->speeder_time[checkindex]);
435
0
      if(span_ms == 0)
436
0
        span_ms = 1; /* at least one millisecond MUST have passed */
437
438
      /* Calculate the average speed the last 'span_ms' milliseconds */
439
0
      amount = p->speeder[nowindex]- p->speeder[checkindex];
440
441
0
      if(amount > (0xffffffff/1000))
442
        /* the 'amount' value is bigger than would fit in 32 bits if
443
           multiplied with 1000, so we use the double math for this */
444
0
        p->current_speed = (curl_off_t)
445
0
          ((double)amount/((double)span_ms/1000.0));
446
0
      else
447
        /* the 'amount' value is small enough to fit within 32 bits even
448
           when multiplied with 1000 */
449
0
        p->current_speed = amount * 1000/span_ms;
450
0
    }
451
0
    else
452
      /* the first second we use the average */
453
0
      p->current_speed = p->ul.speed + p->dl.speed;
454
455
0
  } /* Calculations end */
456
0
  return timetoshow;
457
0
}
458
459
#ifndef CURL_DISABLE_PROGRESS_METER
460
461
struct pgrs_estimate {
462
  curl_off_t secs;
463
  curl_off_t percent;
464
};
465
466
static curl_off_t pgrs_est_percent(curl_off_t total, curl_off_t cur)
467
0
{
468
0
  if(total > 10000)
469
0
    return cur / (total / 100);
470
0
  else if(total > 0)
471
0
    return (cur*100) / total;
472
0
  return 0;
473
0
}
474
475
static void pgrs_estimates(struct pgrs_dir *d,
476
                           bool total_known,
477
                           struct pgrs_estimate *est)
478
0
{
479
0
  est->secs = 0;
480
0
  est->percent = 0;
481
0
  if(total_known && (d->speed > 0)) {
482
0
    est->secs = d->total_size / d->speed;
483
0
    est->percent = pgrs_est_percent(d->total_size, d->cur_size);
484
0
  }
485
0
}
486
487
static void progress_meter(struct Curl_easy *data)
488
0
{
489
0
  struct Progress *p = &data->progress;
490
0
  char max6[6][7];
491
0
  struct pgrs_estimate dl_estm;
492
0
  struct pgrs_estimate ul_estm;
493
0
  struct pgrs_estimate total_estm;
494
0
  curl_off_t total_cur_size;
495
0
  curl_off_t total_expected_size;
496
0
  curl_off_t dl_size;
497
0
  char time_left[10];
498
0
  char time_total[10];
499
0
  char time_spent[10];
500
0
  curl_off_t cur_secs = (curl_off_t)p->timespent/1000000; /* seconds */
501
502
0
  if(!p->headers_out) {
503
0
    if(data->state.resume_from) {
504
0
      curl_mfprintf(data->set.err,
505
0
                    "** Resuming transfer from byte position %" FMT_OFF_T "\n",
506
0
                    data->state.resume_from);
507
0
    }
508
0
    curl_mfprintf(data->set.err,
509
0
                  "  %% Total    %% Received %% Xferd  Average Speed   "
510
0
                  "Time    Time     Time  Current\n"
511
0
                  "                                 Dload  Upload   "
512
0
                  "Total   Spent    Left  Speed\n");
513
0
    p->headers_out = TRUE; /* headers are shown */
514
0
  }
515
516
  /* Figure out the estimated time of arrival for upload and download */
517
0
  pgrs_estimates(&p->ul, (bool)p->ul_size_known, &ul_estm);
518
0
  pgrs_estimates(&p->dl, (bool)p->dl_size_known, &dl_estm);
519
520
  /* Since both happen at the same time, total expected duration is max. */
521
0
  total_estm.secs = CURLMAX(ul_estm.secs, dl_estm.secs);
522
  /* create the three time strings */
523
0
  time2str(time_left, total_estm.secs > 0 ? (total_estm.secs - cur_secs) : 0);
524
0
  time2str(time_total, total_estm.secs);
525
0
  time2str(time_spent, cur_secs);
526
527
  /* Get the total amount of data expected to get transferred */
528
0
  total_expected_size =
529
0
    p->ul_size_known ? p->ul.total_size : p->ul.cur_size;
530
531
0
  dl_size =
532
0
    p->dl_size_known ? p->dl.total_size : p->dl.cur_size;
533
534
  /* integer overflow check */
535
0
  if((CURL_OFF_T_MAX - total_expected_size) < dl_size)
536
0
    total_expected_size = CURL_OFF_T_MAX; /* capped */
537
0
  else
538
0
    total_expected_size += dl_size;
539
540
  /* We have transferred this much so far */
541
0
  total_cur_size = p->dl.cur_size + p->ul.cur_size;
542
543
  /* Get the percentage of data transferred so far */
544
0
  total_estm.percent = pgrs_est_percent(total_expected_size, total_cur_size);
545
546
0
  curl_mfprintf(data->set.err,
547
0
                "\r"
548
0
                "%3" FMT_OFF_T " %s "
549
0
                "%3" FMT_OFF_T " %s "
550
0
                "%3" FMT_OFF_T " %s %s %s  %s %s %s %s",
551
0
                total_estm.percent, /* 3 letters */         /* total % */
552
0
                max6data(total_expected_size, max6[2]),     /* total size */
553
0
                dl_estm.percent, /* 3 letters */            /* rcvd % */
554
0
                max6data(p->dl.cur_size, max6[0]),          /* rcvd size */
555
0
                ul_estm.percent, /* 3 letters */            /* xfer % */
556
0
                max6data(p->ul.cur_size, max6[1]),          /* xfer size */
557
0
                max6data(p->dl.speed, max6[3]),             /* avrg dl speed */
558
0
                max6data(p->ul.speed, max6[4]),             /* avrg ul speed */
559
0
                time_total,    /* 8 letters */              /* total time */
560
0
                time_spent,    /* 8 letters */              /* time spent */
561
0
                time_left,     /* 8 letters */              /* time left */
562
0
                max6data(p->current_speed, max6[5])
563
0
    );
564
565
  /* we flush the output stream to make it appear as soon as possible */
566
0
  fflush(data->set.err);
567
0
}
568
#else
569
 /* progress bar disabled */
570
#define progress_meter(x) Curl_nop_stmt
571
#endif
572
573
574
/*
575
 * Curl_pgrsUpdate() returns 0 for success or the value returned by the
576
 * progress callback!
577
 */
578
static int pgrsupdate(struct Curl_easy *data, bool showprogress)
579
0
{
580
0
  if(!data->progress.hide) {
581
0
    if(data->set.fxferinfo) {
582
0
      int result;
583
      /* There is a callback set, call that */
584
0
      Curl_set_in_callback(data, TRUE);
585
0
      result = data->set.fxferinfo(data->set.progress_client,
586
0
                                   data->progress.dl.total_size,
587
0
                                   data->progress.dl.cur_size,
588
0
                                   data->progress.ul.total_size,
589
0
                                   data->progress.ul.cur_size);
590
0
      Curl_set_in_callback(data, FALSE);
591
0
      if(result != CURL_PROGRESSFUNC_CONTINUE) {
592
0
        if(result)
593
0
          failf(data, "Callback aborted");
594
0
        return result;
595
0
      }
596
0
    }
597
0
    else if(data->set.fprogress) {
598
0
      int result;
599
      /* The older deprecated callback is set, call that */
600
0
      Curl_set_in_callback(data, TRUE);
601
0
      result = data->set.fprogress(data->set.progress_client,
602
0
                                   (double)data->progress.dl.total_size,
603
0
                                   (double)data->progress.dl.cur_size,
604
0
                                   (double)data->progress.ul.total_size,
605
0
                                   (double)data->progress.ul.cur_size);
606
0
      Curl_set_in_callback(data, FALSE);
607
0
      if(result != CURL_PROGRESSFUNC_CONTINUE) {
608
0
        if(result)
609
0
          failf(data, "Callback aborted");
610
0
        return result;
611
0
      }
612
0
    }
613
614
0
    if(showprogress)
615
0
      progress_meter(data);
616
0
  }
617
618
0
  return 0;
619
0
}
620
621
int Curl_pgrsUpdate(struct Curl_easy *data)
622
0
{
623
0
  struct curltime now = curlx_now(); /* what time is it */
624
0
  bool showprogress = progress_calc(data, now);
625
0
  return pgrsupdate(data, showprogress);
626
0
}
627
628
/*
629
 * Update all progress, do not do progress meter/callbacks.
630
 */
631
void Curl_pgrsUpdate_nometer(struct Curl_easy *data)
632
0
{
633
0
  struct curltime now = curlx_now(); /* what time is it */
634
0
  (void)progress_calc(data, now);
635
0
}