Coverage Report

Created: 2025-12-04 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/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 "transfer.h"
32
#include "curlx/timeval.h"
33
34
/* check rate limits within this many recent milliseconds, at minimum. */
35
#define MIN_RATE_LIMIT_PERIOD 3000
36
37
#ifndef CURL_DISABLE_PROGRESS_METER
38
/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero
39
   byte) */
40
static void time2str(char *r, curl_off_t seconds)
41
0
{
42
0
  curl_off_t h;
43
0
  if(seconds <= 0) {
44
0
    strcpy(r, "--:--:--");
45
0
    return;
46
0
  }
47
0
  h = seconds / 3600;
48
0
  if(h <= 99) {
49
0
    curl_off_t m = (seconds - (h * 3600)) / 60;
50
0
    curl_off_t s = (seconds - (h * 3600)) - (m * 60);
51
0
    curl_msnprintf(r, 9, "%2" FMT_OFF_T ":%02" FMT_OFF_T ":%02" FMT_OFF_T,
52
0
                   h, m, s);
53
0
  }
54
0
  else {
55
    /* this equals to more than 99 hours, switch to a more suitable output
56
       format to fit within the limits. */
57
0
    curl_off_t d = seconds / 86400;
58
0
    h = (seconds - (d * 86400)) / 3600;
59
0
    if(d <= 999)
60
0
      curl_msnprintf(r, 9, "%3" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h);
61
0
    else
62
0
      curl_msnprintf(r, 9, "%7" FMT_OFF_T "d", d);
63
0
  }
64
0
}
65
66
/* The point of this function would be to return a string of the input data,
67
   but never longer than 6 columns (+ one zero byte).
68
   Add suffix k, M, G when suitable... */
69
static char *max6data(curl_off_t bytes, char *max6)
70
0
{
71
  /* a signed 64-bit value is 8192 petabytes maximum, shown as
72
     8.0E (exabytes)*/
73
0
  if(bytes < 100000)
74
0
    curl_msnprintf(max6, 7, "%6" CURL_FORMAT_CURL_OFF_T, bytes);
75
0
  else {
76
0
    const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 };
77
0
    int k = 0;
78
0
    curl_off_t nbytes;
79
0
    do {
80
0
      nbytes = bytes / 1024;
81
0
      if(nbytes < 1000)
82
0
        break;
83
0
      bytes = nbytes;
84
0
      k++;
85
0
      DEBUGASSERT(unit[k]);
86
0
    } while(unit[k]);
87
    /* xxx.yU */
88
0
    curl_msnprintf(max6, 7, "%3" CURL_FORMAT_CURL_OFF_T
89
0
                   ".%" CURL_FORMAT_CURL_OFF_T "%c", nbytes,
90
0
                   (bytes % 1024) / (1024 / 10), unit[k]);
91
0
  }
92
0
  return max6;
93
0
}
94
#endif
95
96
static void pgrs_speedinit(struct Curl_easy *data)
97
0
{
98
0
  memset(&data->state.keeps_speed, 0, sizeof(struct curltime));
99
0
}
100
101
/*
102
 * @unittest: 1606
103
 */
104
UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data,
105
                                  struct curltime *pnow)
106
0
{
107
0
  if(!data->set.low_speed_time || !data->set.low_speed_limit ||
108
0
     Curl_xfer_recv_is_paused(data) || Curl_xfer_send_is_paused(data))
109
    /* A paused transfer is not qualified for speed checks */
110
0
    return CURLE_OK;
111
112
0
  if(data->progress.current_speed >= 0) {
113
0
    if(data->progress.current_speed < data->set.low_speed_limit) {
114
0
      if(!data->state.keeps_speed.tv_sec)
115
        /* under the limit at this moment */
116
0
        data->state.keeps_speed = *pnow;
117
0
      else {
118
        /* how long has it been under the limit */
119
0
        timediff_t howlong = curlx_timediff_ms(*pnow, data->state.keeps_speed);
120
121
0
        if(howlong >= data->set.low_speed_time * 1000) {
122
          /* too long */
123
0
          failf(data,
124
0
                "Operation too slow. "
125
0
                "Less than %ld bytes/sec transferred the last %ld seconds",
126
0
                data->set.low_speed_limit,
127
0
                data->set.low_speed_time);
128
0
          return CURLE_OPERATION_TIMEDOUT;
129
0
        }
130
0
      }
131
0
    }
132
0
    else
133
      /* faster right now */
134
0
      data->state.keeps_speed.tv_sec = 0;
135
0
  }
136
137
  /* since low speed limit is enabled, set the expire timer to make this
138
     connection's speed get checked again in a second */
139
0
  Curl_expire(data, 1000, EXPIRE_SPEEDCHECK);
140
141
0
  return CURLE_OK;
142
0
}
143
144
/*
145
146
   New proposed interface, 9th of February 2000:
147
148
   pgrsStartNow() - sets start time
149
   pgrsSetDownloadSize(x) - known expected download size
150
   pgrsSetUploadSize(x) - known expected upload size
151
   pgrsSetDownloadCounter() - amount of data currently downloaded
152
   pgrsSetUploadCounter() - amount of data currently uploaded
153
   pgrsUpdate() - show progress
154
   pgrsDone() - transfer complete
155
156
*/
157
158
int Curl_pgrsDone(struct Curl_easy *data)
159
0
{
160
0
  int rc;
161
0
  data->progress.lastshow = 0;
162
0
  rc = Curl_pgrsUpdate(data); /* the final (forced) update */
163
0
  if(rc)
164
0
    return rc;
165
166
0
  if(!data->progress.hide && !data->progress.callback)
167
    /* only output if we do not use a progress callback and we are not
168
     * hidden */
169
0
    curl_mfprintf(data->set.err, "\n");
170
171
0
  return 0;
172
0
}
173
174
void Curl_pgrsReset(struct Curl_easy *data)
175
0
{
176
0
  Curl_pgrsSetUploadCounter(data, 0);
177
0
  Curl_pgrsSetDownloadCounter(data, 0);
178
0
  Curl_pgrsSetUploadSize(data, -1);
179
0
  Curl_pgrsSetDownloadSize(data, -1);
180
0
  data->progress.speeder_c = 0; /* reset speed records */
181
0
  pgrs_speedinit(data);
182
0
}
183
184
/* reset the known transfer sizes */
185
void Curl_pgrsResetTransferSizes(struct Curl_easy *data)
186
0
{
187
0
  Curl_pgrsSetDownloadSize(data, -1);
188
0
  Curl_pgrsSetUploadSize(data, -1);
189
0
}
190
191
void Curl_pgrsRecvPause(struct Curl_easy *data, bool enable)
192
0
{
193
0
  if(!enable) {
194
0
    data->progress.speeder_c = 0; /* reset speed records */
195
0
    pgrs_speedinit(data); /* reset low speed measurements */
196
0
  }
197
0
}
198
199
void Curl_pgrsSendPause(struct Curl_easy *data, bool enable)
200
0
{
201
0
  if(!enable) {
202
0
    data->progress.speeder_c = 0; /* reset speed records */
203
0
    pgrs_speedinit(data); /* reset low speed measurements */
204
0
  }
205
0
}
206
207
/*
208
 *
209
 * Curl_pgrsTimeWas(). Store the timestamp time at the given label.
210
 */
211
void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer,
212
                      struct curltime timestamp)
213
0
{
214
0
  timediff_t *delta = NULL;
215
216
0
  switch(timer) {
217
0
  default:
218
0
  case TIMER_NONE:
219
    /* mistake filter */
220
0
    break;
221
0
  case TIMER_STARTOP:
222
    /* This is set at the start of a transfer */
223
0
    data->progress.t_startop = timestamp;
224
0
    data->progress.t_startqueue = timestamp;
225
0
    data->progress.t_postqueue = 0;
226
0
    break;
227
0
  case TIMER_STARTSINGLE:
228
    /* This is set at the start of each single transfer */
229
0
    data->progress.t_startsingle = timestamp;
230
0
    data->progress.is_t_startransfer_set = FALSE;
231
0
    break;
232
0
  case TIMER_POSTQUEUE:
233
    /* Queue time is accumulative from all involved redirects */
234
0
    data->progress.t_postqueue +=
235
0
      curlx_timediff_us(timestamp, data->progress.t_startqueue);
236
0
    break;
237
0
  case TIMER_STARTACCEPT:
238
0
    data->progress.t_acceptdata = timestamp;
239
0
    break;
240
0
  case TIMER_NAMELOOKUP:
241
0
    delta = &data->progress.t_nslookup;
242
0
    break;
243
0
  case TIMER_CONNECT:
244
0
    delta = &data->progress.t_connect;
245
0
    break;
246
0
  case TIMER_APPCONNECT:
247
0
    delta = &data->progress.t_appconnect;
248
0
    break;
249
0
  case TIMER_PRETRANSFER:
250
0
    delta = &data->progress.t_pretransfer;
251
0
    break;
252
0
  case TIMER_STARTTRANSFER:
253
0
    delta = &data->progress.t_starttransfer;
254
    /* prevent updating t_starttransfer unless:
255
     *   1) this is the first time we are setting t_starttransfer
256
     *   2) a redirect has occurred since the last time t_starttransfer was set
257
     * This prevents repeated invocations of the function from incorrectly
258
     * changing the t_starttransfer time.
259
     */
260
0
    if(data->progress.is_t_startransfer_set) {
261
0
      return;
262
0
    }
263
0
    else {
264
0
      data->progress.is_t_startransfer_set = TRUE;
265
0
      break;
266
0
    }
267
0
  case TIMER_POSTRANSFER:
268
0
    delta = &data->progress.t_posttransfer;
269
0
    break;
270
0
  case TIMER_REDIRECT:
271
0
    data->progress.t_redirect = curlx_timediff_us(timestamp,
272
0
                                                 data->progress.start);
273
0
    data->progress.t_startqueue = timestamp;
274
0
    break;
275
0
  }
276
0
  if(delta) {
277
0
    timediff_t us = curlx_timediff_us(timestamp, data->progress.t_startsingle);
278
0
    if(us < 1)
279
0
      us = 1; /* make sure at least one microsecond passed */
280
0
    *delta += us;
281
0
  }
282
0
}
283
284
/*
285
 *
286
 * Curl_pgrsTime(). Store the current time at the given label. This fetches a
287
 * fresh "now" and returns it.
288
 *
289
 * @unittest: 1399
290
 */
291
struct curltime Curl_pgrsTime(struct Curl_easy *data, timerid timer)
292
0
{
293
0
  struct curltime now = curlx_now();
294
295
0
  Curl_pgrsTimeWas(data, timer, now);
296
0
  return now;
297
0
}
298
299
void Curl_pgrsStartNow(struct Curl_easy *data)
300
0
{
301
0
  struct Progress *p = &data->progress;
302
0
  p->speeder_c = 0; /* reset the progress meter display */
303
0
  p->start = curlx_now();
304
0
  p->is_t_startransfer_set = FALSE;
305
0
  p->dl.cur_size = 0;
306
0
  p->ul.cur_size = 0;
307
  /* the sizes are unknown at start */
308
0
  p->dl_size_known = FALSE;
309
0
  p->ul_size_known = FALSE;
310
0
}
311
312
/*
313
 * Set the number of downloaded bytes so far.
314
 */
315
void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
316
0
{
317
0
  data->progress.dl.cur_size = size;
318
0
}
319
320
/*
321
 * Set the number of uploaded bytes so far.
322
 */
323
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size)
324
0
{
325
0
  data->progress.ul.cur_size = size;
326
0
}
327
328
void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size)
329
0
{
330
0
  if(size >= 0) {
331
0
    data->progress.dl.total_size = size;
332
0
    data->progress.dl_size_known = TRUE;
333
0
  }
334
0
  else {
335
0
    data->progress.dl.total_size = 0;
336
0
    data->progress.dl_size_known = FALSE;
337
0
  }
338
0
}
339
340
void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
341
0
{
342
0
  if(size >= 0) {
343
0
    data->progress.ul.total_size = size;
344
0
    data->progress.ul_size_known = TRUE;
345
0
  }
346
0
  else {
347
0
    data->progress.ul.total_size = 0;
348
0
    data->progress.ul_size_known = FALSE;
349
0
  }
350
0
}
351
352
void Curl_pgrsEarlyData(struct Curl_easy *data, curl_off_t sent)
353
0
{
354
0
  data->progress.earlydata_sent = sent;
355
0
}
356
357
/* returns the average speed in bytes / second */
358
static curl_off_t trspeed(curl_off_t size, /* number of bytes */
359
                          curl_off_t us)   /* microseconds */
360
0
{
361
0
  if(us < 1)
362
0
    return size * 1000000;
363
0
  else if(size < CURL_OFF_T_MAX / 1000000)
364
0
    return (size * 1000000) / us;
365
0
  else if(us >= 1000000)
366
0
    return size / (us / 1000000);
367
0
  else
368
0
    return CURL_OFF_T_MAX;
369
0
}
370
371
/* returns TRUE if it is time to show the progress meter */
372
static bool progress_calc(struct Curl_easy *data, struct curltime *pnow)
373
0
{
374
0
  struct Progress * const p = &data->progress;
375
0
  int i_next, i_oldest, i_latest;
376
0
  timediff_t duration_ms;
377
0
  curl_off_t amount;
378
379
  /* The time spent so far (from the start) in microseconds */
380
0
  p->timespent = curlx_timediff_us(*pnow, p->start);
381
0
  p->dl.speed = trspeed(p->dl.cur_size, p->timespent);
382
0
  p->ul.speed = trspeed(p->ul.cur_size, p->timespent);
383
384
0
  if(!p->speeder_c) { /* no previous record exists */
385
0
    p->speed_amount[0] = p->dl.cur_size + p->ul.cur_size;
386
0
    p->speed_time[0] = *pnow;
387
0
    p->speeder_c++;
388
    /* use the overall average at the start */
389
0
    p->current_speed = p->ul.speed + p->dl.speed;
390
0
    p->lastshow = pnow->tv_sec;
391
0
    return TRUE;
392
0
  }
393
  /* We have at least one record now. Where to put the next and
394
   * where is the latest one? */
395
0
  i_next = p->speeder_c % CURL_SPEED_RECORDS;
396
0
  i_latest = (i_next > 0) ? (i_next - 1) : (CURL_SPEED_RECORDS - 1);
397
398
  /* Make a new record only when some time has passed.
399
   * Too frequent calls otherwise ruin the history. */
400
0
  if(curlx_timediff_ms(*pnow, p->speed_time[i_latest]) >= 1000) {
401
0
    p->speeder_c++;
402
0
    i_latest = i_next;
403
0
    p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size;
404
0
    p->speed_time[i_latest] = *pnow;
405
0
  }
406
0
  else if(data->req.done) {
407
    /* When a transfer is done, and we did not have a current speed
408
     * already, update the last record. Otherwise, stay at the speed
409
     * we have. The last chunk of data, when rate limiting, would increase
410
     * reported speed since it no longer measures a full second. */
411
0
    if(!p->current_speed) {
412
0
      p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size;
413
0
      p->speed_time[i_latest] = *pnow;
414
0
    }
415
0
  }
416
0
  else {
417
    /* transfer ongoing, wait for more time to pass. */
418
0
    return FALSE;
419
0
  }
420
421
0
  i_oldest = (p->speeder_c < CURL_SPEED_RECORDS) ? 0 :
422
0
             ((i_latest + 1) % CURL_SPEED_RECORDS);
423
424
  /* How much we transferred between oldest and current records */
425
0
  amount = p->speed_amount[i_latest] - p->speed_amount[i_oldest];
426
  /* How long this took */
427
0
  duration_ms = curlx_timediff_ms(p->speed_time[i_latest],
428
0
                                  p->speed_time[i_oldest]);
429
0
  if(duration_ms <= 0)
430
0
    duration_ms = 1;
431
432
0
  if(amount > (CURL_OFF_T_MAX / 1000)) {
433
    /* the 'amount' value is bigger than would fit in 64 bits if
434
       multiplied with 1000, so we use the double math for this */
435
0
    p->current_speed =
436
0
      (curl_off_t)(((double)amount * 1000.0) / (double)duration_ms);
437
0
  }
438
0
  else {
439
    /* the 'amount' value is small enough to fit within 32 bits even
440
       when multiplied with 1000 */
441
0
    p->current_speed = amount * 1000 / duration_ms;
442
0
  }
443
444
0
  if((p->lastshow == pnow->tv_sec) && !data->req.done)
445
0
    return FALSE;
446
0
  p->lastshow = pnow->tv_sec;
447
0
  return TRUE;
448
0
}
449
450
#ifndef CURL_DISABLE_PROGRESS_METER
451
452
struct pgrs_estimate {
453
  curl_off_t secs;
454
  curl_off_t percent;
455
};
456
457
static curl_off_t pgrs_est_percent(curl_off_t total, curl_off_t cur)
458
0
{
459
0
  if(total > 10000)
460
0
    return cur / (total / 100);
461
0
  else if(total > 0)
462
0
    return (cur * 100) / total;
463
0
  return 0;
464
0
}
465
466
static void pgrs_estimates(struct pgrs_dir *d,
467
                           bool total_known,
468
                           struct pgrs_estimate *est)
469
0
{
470
0
  est->secs = 0;
471
0
  est->percent = 0;
472
0
  if(total_known && (d->speed > 0)) {
473
0
    est->secs = d->total_size / d->speed;
474
0
    est->percent = pgrs_est_percent(d->total_size, d->cur_size);
475
0
  }
476
0
}
477
478
static void progress_meter(struct Curl_easy *data)
479
0
{
480
0
  struct Progress *p = &data->progress;
481
0
  char max6[6][7];
482
0
  struct pgrs_estimate dl_estm;
483
0
  struct pgrs_estimate ul_estm;
484
0
  struct pgrs_estimate total_estm;
485
0
  curl_off_t total_cur_size;
486
0
  curl_off_t total_expected_size;
487
0
  curl_off_t dl_size;
488
0
  char time_left[10];
489
0
  char time_total[10];
490
0
  char time_spent[10];
491
0
  curl_off_t cur_secs = (curl_off_t)p->timespent / 1000000; /* seconds */
492
493
0
  if(!p->headers_out) {
494
0
    if(data->state.resume_from) {
495
0
      curl_mfprintf(data->set.err,
496
0
                    "** Resuming transfer from byte position %" FMT_OFF_T "\n",
497
0
                    data->state.resume_from);
498
0
    }
499
0
    curl_mfprintf(data->set.err,
500
0
                  "  %% Total    %% Received %% Xferd  Average Speed   "
501
0
                  "Time    Time     Time  Current\n"
502
0
                  "                                 Dload  Upload   "
503
0
                  "Total   Spent    Left  Speed\n");
504
0
    p->headers_out = TRUE; /* headers are shown */
505
0
  }
506
507
  /* Figure out the estimated time of arrival for upload and download */
508
0
  pgrs_estimates(&p->ul, (bool)p->ul_size_known, &ul_estm);
509
0
  pgrs_estimates(&p->dl, (bool)p->dl_size_known, &dl_estm);
510
511
  /* Since both happen at the same time, total expected duration is max. */
512
0
  total_estm.secs = CURLMAX(ul_estm.secs, dl_estm.secs);
513
  /* create the three time strings */
514
0
  time2str(time_left, total_estm.secs > 0 ? (total_estm.secs - cur_secs) : 0);
515
0
  time2str(time_total, total_estm.secs);
516
0
  time2str(time_spent, cur_secs);
517
518
  /* Get the total amount of data expected to get transferred */
519
0
  total_expected_size = p->ul_size_known ? p->ul.total_size : p->ul.cur_size;
520
521
0
  dl_size = p->dl_size_known ? p->dl.total_size : p->dl.cur_size;
522
523
  /* integer overflow check */
524
0
  if((CURL_OFF_T_MAX - total_expected_size) < dl_size)
525
0
    total_expected_size = CURL_OFF_T_MAX; /* capped */
526
0
  else
527
0
    total_expected_size += dl_size;
528
529
  /* We have transferred this much so far */
530
0
  total_cur_size = p->dl.cur_size + p->ul.cur_size;
531
532
  /* Get the percentage of data transferred so far */
533
0
  total_estm.percent = pgrs_est_percent(total_expected_size, total_cur_size);
534
535
0
  curl_mfprintf(data->set.err,
536
0
                "\r"
537
0
                "%3" FMT_OFF_T " %s "
538
0
                "%3" FMT_OFF_T " %s "
539
0
                "%3" FMT_OFF_T " %s %s %s  %s %s %s %s",
540
0
                total_estm.percent, /* 3 letters */         /* total % */
541
0
                max6data(total_expected_size, max6[2]),     /* total size */
542
0
                dl_estm.percent, /* 3 letters */            /* rcvd % */
543
0
                max6data(p->dl.cur_size, max6[0]),          /* rcvd size */
544
0
                ul_estm.percent, /* 3 letters */            /* xfer % */
545
0
                max6data(p->ul.cur_size, max6[1]),          /* xfer size */
546
0
                max6data(p->dl.speed, max6[3]),             /* avrg dl speed */
547
0
                max6data(p->ul.speed, max6[4]),             /* avrg ul speed */
548
0
                time_total,    /* 8 letters */              /* total time */
549
0
                time_spent,    /* 8 letters */              /* time spent */
550
0
                time_left,     /* 8 letters */              /* time left */
551
0
                max6data(p->current_speed, max6[5])
552
0
    );
553
554
  /* we flush the output stream to make it appear as soon as possible */
555
0
  fflush(data->set.err);
556
0
}
557
#else
558
 /* progress bar disabled */
559
#define progress_meter(x) Curl_nop_stmt
560
#endif
561
562
/*
563
 * Curl_pgrsUpdate() returns 0 for success or the value returned by the
564
 * progress callback!
565
 */
566
static CURLcode pgrsupdate(struct Curl_easy *data, bool showprogress)
567
0
{
568
0
  if(!data->progress.hide) {
569
0
    if(data->set.fxferinfo) {
570
0
      int result;
571
      /* There is a callback set, call that */
572
0
      Curl_set_in_callback(data, TRUE);
573
0
      result = data->set.fxferinfo(data->set.progress_client,
574
0
                                   data->progress.dl.total_size,
575
0
                                   data->progress.dl.cur_size,
576
0
                                   data->progress.ul.total_size,
577
0
                                   data->progress.ul.cur_size);
578
0
      Curl_set_in_callback(data, FALSE);
579
0
      if(result != CURL_PROGRESSFUNC_CONTINUE) {
580
0
        if(result) {
581
0
          failf(data, "Callback aborted");
582
0
          return CURLE_ABORTED_BY_CALLBACK;
583
0
        }
584
0
        return CURLE_OK;
585
0
      }
586
0
    }
587
0
    else if(data->set.fprogress) {
588
0
      int result;
589
      /* The older deprecated callback is set, call that */
590
0
      Curl_set_in_callback(data, TRUE);
591
0
      result = data->set.fprogress(data->set.progress_client,
592
0
                                   (double)data->progress.dl.total_size,
593
0
                                   (double)data->progress.dl.cur_size,
594
0
                                   (double)data->progress.ul.total_size,
595
0
                                   (double)data->progress.ul.cur_size);
596
0
      Curl_set_in_callback(data, FALSE);
597
0
      if(result != CURL_PROGRESSFUNC_CONTINUE) {
598
0
        if(result) {
599
0
          failf(data, "Callback aborted");
600
0
          return CURLE_ABORTED_BY_CALLBACK;
601
0
        }
602
0
        return CURLE_OK;
603
0
      }
604
0
    }
605
606
0
    if(showprogress)
607
0
      progress_meter(data);
608
0
  }
609
610
0
  return CURLE_OK;
611
0
}
612
613
static CURLcode pgrs_update(struct Curl_easy *data, struct curltime *pnow)
614
0
{
615
0
  bool showprogress = progress_calc(data, pnow);
616
0
  return pgrsupdate(data, showprogress);
617
0
}
618
619
CURLcode Curl_pgrsUpdate(struct Curl_easy *data)
620
0
{
621
0
  struct curltime now = curlx_now(); /* what time is it */
622
0
  return pgrs_update(data, &now);
623
0
}
624
625
CURLcode Curl_pgrsCheck(struct Curl_easy *data)
626
0
{
627
0
  struct curltime now = curlx_now();
628
0
  CURLcode result;
629
630
0
  result = pgrs_update(data, &now);
631
0
  if(!result && !data->req.done)
632
0
    result = pgrs_speedcheck(data, &now);
633
0
  return result;
634
0
}
635
636
/*
637
 * Update all progress, do not do progress meter/callbacks.
638
 */
639
void Curl_pgrsUpdate_nometer(struct Curl_easy *data)
640
0
{
641
0
  struct curltime now = curlx_now(); /* what time is it */
642
0
  (void)progress_calc(data, &now);
643
0
}