Coverage Report

Created: 2026-01-25 06:10

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