Coverage Report

Created: 2025-11-09 06:25

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 "curlx/timeval.h"
32
33
/* check rate limits within this many recent milliseconds, at minimum. */
34
7.22k
#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
20.2k
{
41
20.2k
  curl_off_t h;
42
20.2k
  if(seconds <= 0) {
43
18.3k
    strcpy(r, "--:--:--");
44
18.3k
    return;
45
18.3k
  }
46
1.92k
  h = seconds / 3600;
47
1.92k
  if(h <= 99) {
48
612
    curl_off_t m = (seconds - (h * 3600)) / 60;
49
612
    curl_off_t s = (seconds - (h * 3600)) - (m * 60);
50
612
    curl_msnprintf(r, 9, "%2" FMT_OFF_T ":%02" FMT_OFF_T ":%02" FMT_OFF_T,
51
612
                   h, m, s);
52
612
  }
53
1.31k
  else {
54
    /* this equals to more than 99 hours, switch to a more suitable output
55
       format to fit within the limits. */
56
1.31k
    curl_off_t d = seconds / 86400;
57
1.31k
    h = (seconds - (d * 86400)) / 3600;
58
1.31k
    if(d <= 999)
59
222
      curl_msnprintf(r, 9, "%3" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h);
60
1.09k
    else
61
1.09k
      curl_msnprintf(r, 9, "%7" FMT_OFF_T "d", d);
62
1.31k
  }
63
1.92k
}
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
40.4k
{
70
  /* a signed 64-bit value is 8192 petabytes maximum */
71
40.4k
  const char unit[] = { 'k', 'M', 'G', 'T', 'P', 0 };
72
40.4k
  int k = 0;
73
40.4k
  if(bytes < 1000000) {
74
38.4k
    curl_msnprintf(max6, 7, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
75
38.4k
    return max6;
76
38.4k
  }
77
78
5.26k
  do {
79
5.26k
    curl_off_t nbytes = bytes / 1024;
80
5.26k
    if(nbytes < 1000) {
81
      /* xxx.yU */
82
302
      curl_msnprintf(max6, 7, "%3" CURL_FORMAT_CURL_OFF_T
83
302
                     ".%" CURL_FORMAT_CURL_OFF_T "%c", nbytes,
84
302
                     (bytes%1024) / (1024/10), unit[k]);
85
302
      break;
86
302
    }
87
4.96k
    else if(nbytes < 100000) {
88
      /* xxxxxU */
89
1.73k
      curl_msnprintf(max6, 7, "%5" CURL_FORMAT_CURL_OFF_T "%c",
90
1.73k
                     nbytes, unit[k]);
91
1.73k
      break;
92
1.73k
    }
93
3.23k
    bytes = nbytes;
94
3.23k
    k++;
95
3.23k
    DEBUGASSERT(unit[k]);
96
3.23k
  } while(unit[k]);
97
2.03k
  return max6;
98
2.03k
}
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
120k
{
117
120k
  int rc;
118
120k
  data->progress.lastshow = 0;
119
120k
  rc = Curl_pgrsUpdate(data); /* the final (forced) update */
120
120k
  if(rc)
121
0
    return rc;
122
123
120k
  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
3.95k
    curl_mfprintf(data->set.err, "\n");
127
128
120k
  data->progress.speeder_c = 0; /* reset the progress meter display */
129
120k
  return 0;
130
120k
}
131
132
/* reset the known transfer sizes */
133
void Curl_pgrsResetTransferSizes(struct Curl_easy *data)
134
147k
{
135
147k
  Curl_pgrsSetDownloadSize(data, -1);
136
147k
  Curl_pgrsSetUploadSize(data, -1);
137
147k
}
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
805k
{
146
805k
  timediff_t *delta = NULL;
147
148
805k
  switch(timer) {
149
0
  default:
150
0
  case TIMER_NONE:
151
    /* mistake filter */
152
0
    break;
153
162k
  case TIMER_STARTOP:
154
    /* This is set at the start of a transfer */
155
162k
    data->progress.t_startop = timestamp;
156
162k
    data->progress.t_startqueue = timestamp;
157
162k
    data->progress.t_postqueue = 0;
158
162k
    break;
159
147k
  case TIMER_STARTSINGLE:
160
    /* This is set at the start of each single transfer */
161
147k
    data->progress.t_startsingle = timestamp;
162
147k
    data->progress.is_t_startransfer_set = FALSE;
163
147k
    break;
164
124k
  case TIMER_POSTQUEUE:
165
    /* Queue time is accumulative from all involved redirects */
166
124k
    data->progress.t_postqueue +=
167
124k
      curlx_timediff_us(timestamp, data->progress.t_startqueue);
168
124k
    break;
169
10.6k
  case TIMER_STARTACCEPT:
170
10.6k
    data->progress.t_acceptdata = timestamp;
171
10.6k
    break;
172
104k
  case TIMER_NAMELOOKUP:
173
104k
    delta = &data->progress.t_nslookup;
174
104k
    break;
175
101k
  case TIMER_CONNECT:
176
101k
    delta = &data->progress.t_connect;
177
101k
    break;
178
0
  case TIMER_APPCONNECT:
179
0
    delta = &data->progress.t_appconnect;
180
0
    break;
181
57.1k
  case TIMER_PRETRANSFER:
182
57.1k
    delta = &data->progress.t_pretransfer;
183
57.1k
    break;
184
38.0k
  case TIMER_STARTTRANSFER:
185
38.0k
    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
38.0k
    if(data->progress.is_t_startransfer_set) {
193
1
      return;
194
1
    }
195
38.0k
    else {
196
38.0k
      data->progress.is_t_startransfer_set = TRUE;
197
38.0k
      break;
198
38.0k
    }
199
43.3k
  case TIMER_POSTRANSFER:
200
43.3k
    delta = &data->progress.t_posttransfer;
201
43.3k
    break;
202
17.0k
  case TIMER_REDIRECT:
203
17.0k
    data->progress.t_redirect = curlx_timediff_us(timestamp,
204
17.0k
                                                 data->progress.start);
205
17.0k
    data->progress.t_startqueue = timestamp;
206
17.0k
    break;
207
805k
  }
208
805k
  if(delta) {
209
343k
    timediff_t us = curlx_timediff_us(timestamp, data->progress.t_startsingle);
210
343k
    if(us < 1)
211
0
      us = 1; /* make sure at least one microsecond passed */
212
343k
    *delta += us;
213
343k
  }
214
805k
}
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
704k
{
225
704k
  struct curltime now = curlx_now();
226
227
704k
  Curl_pgrsTimeWas(data, timer, now);
228
704k
  return now;
229
704k
}
230
231
void Curl_pgrsStartNow(struct Curl_easy *data)
232
130k
{
233
130k
  struct Progress *p = &data->progress;
234
130k
  p->speeder_c = 0; /* reset the progress meter display */
235
130k
  p->start = curlx_now();
236
130k
  p->is_t_startransfer_set = FALSE;
237
130k
  p->ul.limit.start = p->start;
238
130k
  p->dl.limit.start = p->start;
239
130k
  p->ul.limit.start_size = 0;
240
130k
  p->dl.limit.start_size = 0;
241
130k
  p->dl.cur_size = 0;
242
130k
  p->ul.cur_size = 0;
243
  /* the sizes are unknown at start */
244
130k
  p->dl_size_known = FALSE;
245
130k
  p->ul_size_known = FALSE;
246
130k
  Curl_ratelimit(data, p->start);
247
130k
}
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
2.76M
{
271
2.76M
  curl_off_t bytes = d->cur_size - d->limit.start_size;
272
2.76M
  timediff_t should_ms;
273
2.76M
  timediff_t took_ms;
274
275
  /* no limit or we did not get to any bytes yet */
276
2.76M
  if(!bytes_per_sec || !bytes)
277
2.74M
    return 0;
278
279
  /* The time it took us to have `bytes` */
280
15.0k
  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
15.0k
  if(bytes < CURL_OFF_T_MAX/1000) {
285
    /* (1000 * bytes / (bytes / sec)) = 1000 * sec = ms */
286
15.0k
    should_ms = (timediff_t) (1000 * bytes / bytes_per_sec);
287
15.0k
  }
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
15.0k
  if(took_ms < should_ms) {
299
    /* when gotten to `bytes` too fast, wait the difference */
300
2.02k
    return should_ms - took_ms;
301
2.02k
  }
302
13.0k
  return 0;
303
15.0k
}
304
305
/*
306
 * Set the number of downloaded bytes so far.
307
 */
308
void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
309
1.26M
{
310
1.26M
  data->progress.dl.cur_size = size;
311
1.26M
}
312
313
/*
314
 * Update the timestamp and sizestamp to use for rate limit calculations.
315
 */
316
void Curl_ratelimit(struct Curl_easy *data, struct curltime now)
317
131k
{
318
  /* do not set a new stamp unless the time since last update is long enough */
319
131k
  if(data->set.max_recv_speed) {
320
4.82k
    if(curlx_timediff(now, data->progress.dl.limit.start) >=
321
4.82k
       MIN_RATE_LIMIT_PERIOD) {
322
0
      data->progress.dl.limit.start = now;
323
0
      data->progress.dl.limit.start_size = data->progress.dl.cur_size;
324
0
    }
325
4.82k
  }
326
131k
  if(data->set.max_send_speed) {
327
2.39k
    if(curlx_timediff(now, data->progress.ul.limit.start) >=
328
2.39k
       MIN_RATE_LIMIT_PERIOD) {
329
0
      data->progress.ul.limit.start = now;
330
0
      data->progress.ul.limit.start_size = data->progress.ul.cur_size;
331
0
    }
332
2.39k
  }
333
131k
}
334
335
/*
336
 * Set the number of uploaded bytes so far.
337
 */
338
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size)
339
147k
{
340
147k
  data->progress.ul.cur_size = size;
341
147k
}
342
343
void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size)
344
163k
{
345
163k
  if(size >= 0) {
346
10.0k
    data->progress.dl.total_size = size;
347
10.0k
    data->progress.dl_size_known = TRUE;
348
10.0k
  }
349
153k
  else {
350
153k
    data->progress.dl.total_size = 0;
351
153k
    data->progress.dl_size_known = FALSE;
352
153k
  }
353
163k
}
354
355
void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
356
188k
{
357
188k
  if(size >= 0) {
358
35.0k
    data->progress.ul.total_size = size;
359
35.0k
    data->progress.ul_size_known = TRUE;
360
35.0k
  }
361
153k
  else {
362
153k
    data->progress.ul.total_size = 0;
363
153k
    data->progress.ul_size_known = FALSE;
364
153k
  }
365
188k
}
366
367
void Curl_pgrsEarlyData(struct Curl_easy *data, curl_off_t sent)
368
0
{
369
0
    data->progress.earlydata_sent = sent;
370
0
}
371
372
/* returns the average speed in bytes / second */
373
static curl_off_t trspeed(curl_off_t size, /* number of bytes */
374
                          curl_off_t us)   /* microseconds */
375
146M
{
376
146M
  if(us < 1)
377
212
    return size * 1000000;
378
146M
  else if(size < CURL_OFF_T_MAX/1000000)
379
146M
    return (size * 1000000) / us;
380
0
  else if(us >= 1000000)
381
0
    return size / (us / 1000000);
382
0
  else
383
0
    return CURL_OFF_T_MAX;
384
146M
}
385
386
/* returns TRUE if it is time to show the progress meter */
387
static bool progress_calc(struct Curl_easy *data, struct curltime now)
388
73.2M
{
389
73.2M
  bool timetoshow = FALSE;
390
73.2M
  struct Progress * const p = &data->progress;
391
392
  /* The time spent so far (from the start) in microseconds */
393
73.2M
  p->timespent = curlx_timediff_us(now, p->start);
394
73.2M
  p->dl.speed = trspeed(p->dl.cur_size, p->timespent);
395
73.2M
  p->ul.speed = trspeed(p->ul.cur_size, p->timespent);
396
397
  /* Calculations done at most once a second, unless end is reached */
398
73.2M
  if(p->lastshow != now.tv_sec) {
399
253k
    int countindex; /* amount of seconds stored in the speeder array */
400
253k
    int nowindex = p->speeder_c% CURR_TIME;
401
253k
    p->lastshow = now.tv_sec;
402
253k
    timetoshow = TRUE;
403
404
    /* Let's do the "current speed" thing, with the dl + ul speeds
405
       combined. Store the speed at entry 'nowindex'. */
406
253k
    p->speeder[ nowindex ] = p->dl.cur_size + p->ul.cur_size;
407
408
    /* remember the exact time for this moment */
409
253k
    p->speeder_time [ nowindex ] = now;
410
411
    /* advance our speeder_c counter, which is increased every time we get
412
       here and we expect it to never wrap as 2^32 is a lot of seconds! */
413
253k
    p->speeder_c++;
414
415
    /* figure out how many index entries of data we have stored in our speeder
416
       array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of
417
       transfer. Imagine, after one second we have filled in two entries,
418
       after two seconds we have filled in three entries etc. */
419
253k
    countindex = ((p->speeder_c >= CURR_TIME) ? CURR_TIME : p->speeder_c) - 1;
420
421
    /* first of all, we do not do this if there is no counted seconds yet */
422
253k
    if(countindex) {
423
103k
      int checkindex;
424
103k
      timediff_t span_ms;
425
103k
      curl_off_t amount;
426
427
      /* Get the index position to compare with the 'nowindex' position.
428
         Get the oldest entry possible. While we have less than CURR_TIME
429
         entries, the first entry will remain the oldest. */
430
103k
      checkindex = (p->speeder_c >= CURR_TIME) ? p->speeder_c%CURR_TIME : 0;
431
432
      /* Figure out the exact time for the time span */
433
103k
      span_ms = curlx_timediff(now, p->speeder_time[checkindex]);
434
103k
      if(span_ms == 0)
435
72.9k
        span_ms = 1; /* at least one millisecond MUST have passed */
436
437
      /* Calculate the average speed the last 'span_ms' milliseconds */
438
103k
      amount = p->speeder[nowindex]- p->speeder[checkindex];
439
440
103k
      if(amount > (0xffffffff/1000))
441
        /* the 'amount' value is bigger than would fit in 32 bits if
442
           multiplied with 1000, so we use the double math for this */
443
0
        p->current_speed = (curl_off_t)
444
0
          ((double)amount/((double)span_ms/1000.0));
445
103k
      else
446
        /* the 'amount' value is small enough to fit within 32 bits even
447
           when multiplied with 1000 */
448
103k
        p->current_speed = amount * 1000/span_ms;
449
103k
    }
450
149k
    else
451
      /* the first second we use the average */
452
149k
      p->current_speed = p->ul.speed + p->dl.speed;
453
454
253k
  } /* Calculations end */
455
73.2M
  return timetoshow;
456
73.2M
}
457
458
#ifndef CURL_DISABLE_PROGRESS_METER
459
460
struct pgrs_estimate {
461
  curl_off_t secs;
462
  curl_off_t percent;
463
};
464
465
static curl_off_t pgrs_est_percent(curl_off_t total, curl_off_t cur)
466
8.17k
{
467
8.17k
  if(total > 10000)
468
2.75k
    return cur / (total / 100);
469
5.42k
  else if(total > 0)
470
844
    return (cur*100) / total;
471
4.58k
  return 0;
472
8.17k
}
473
474
static void pgrs_estimates(struct pgrs_dir *d,
475
                           bool total_known,
476
                           struct pgrs_estimate *est)
477
13.4k
{
478
13.4k
  est->secs = 0;
479
13.4k
  est->percent = 0;
480
13.4k
  if(total_known && (d->speed > 0)) {
481
1.42k
    est->secs = d->total_size / d->speed;
482
1.42k
    est->percent = pgrs_est_percent(d->total_size, d->cur_size);
483
1.42k
  }
484
13.4k
}
485
486
static void progress_meter(struct Curl_easy *data)
487
6.74k
{
488
6.74k
  struct Progress *p = &data->progress;
489
6.74k
  char max6[6][7];
490
6.74k
  struct pgrs_estimate dl_estm;
491
6.74k
  struct pgrs_estimate ul_estm;
492
6.74k
  struct pgrs_estimate total_estm;
493
6.74k
  curl_off_t total_cur_size;
494
6.74k
  curl_off_t total_expected_size;
495
6.74k
  curl_off_t dl_size;
496
6.74k
  char time_left[10];
497
6.74k
  char time_total[10];
498
6.74k
  char time_spent[10];
499
6.74k
  curl_off_t cur_secs = (curl_off_t)p->timespent/1000000; /* seconds */
500
501
6.74k
  if(!p->headers_out) {
502
2.75k
    if(data->state.resume_from) {
503
159
      curl_mfprintf(data->set.err,
504
159
                    "** Resuming transfer from byte position %" FMT_OFF_T "\n",
505
159
                    data->state.resume_from);
506
159
    }
507
2.75k
    curl_mfprintf(data->set.err,
508
2.75k
                  "  %% Total    %% Received %% Xferd  Average Speed   "
509
2.75k
                  "Time    Time     Time  Current\n"
510
2.75k
                  "                                 Dload  Upload   "
511
2.75k
                  "Total   Spent    Left  Speed\n");
512
2.75k
    p->headers_out = TRUE; /* headers are shown */
513
2.75k
  }
514
515
  /* Figure out the estimated time of arrival for upload and download */
516
6.74k
  pgrs_estimates(&p->ul, (bool)p->ul_size_known, &ul_estm);
517
6.74k
  pgrs_estimates(&p->dl, (bool)p->dl_size_known, &dl_estm);
518
519
  /* Since both happen at the same time, total expected duration is max. */
520
6.74k
  total_estm.secs = CURLMAX(ul_estm.secs, dl_estm.secs);
521
  /* create the three time strings */
522
6.74k
  time2str(time_left, total_estm.secs > 0 ? (total_estm.secs - cur_secs) : 0);
523
6.74k
  time2str(time_total, total_estm.secs);
524
6.74k
  time2str(time_spent, cur_secs);
525
526
  /* Get the total amount of data expected to get transferred */
527
6.74k
  total_expected_size =
528
6.74k
    p->ul_size_known ? p->ul.total_size : p->ul.cur_size;
529
530
6.74k
  dl_size =
531
6.74k
    p->dl_size_known ? p->dl.total_size : p->dl.cur_size;
532
533
  /* integer overflow check */
534
6.74k
  if((CURL_OFF_T_MAX - total_expected_size) < dl_size)
535
4
    total_expected_size = CURL_OFF_T_MAX; /* capped */
536
6.74k
  else
537
6.74k
    total_expected_size += dl_size;
538
539
  /* We have transferred this much so far */
540
6.74k
  total_cur_size = p->dl.cur_size + p->ul.cur_size;
541
542
  /* Get the percentage of data transferred so far */
543
6.74k
  total_estm.percent = pgrs_est_percent(total_expected_size, total_cur_size);
544
545
6.74k
  curl_mfprintf(data->set.err,
546
6.74k
                "\r"
547
6.74k
                "%3" FMT_OFF_T " %s "
548
6.74k
                "%3" FMT_OFF_T " %s "
549
6.74k
                "%3" FMT_OFF_T " %s %s %s  %s %s %s %s",
550
6.74k
                total_estm.percent, /* 3 letters */         /* total % */
551
6.74k
                max6data(total_expected_size, max6[2]),     /* total size */
552
6.74k
                dl_estm.percent, /* 3 letters */            /* rcvd % */
553
6.74k
                max6data(p->dl.cur_size, max6[0]),          /* rcvd size */
554
6.74k
                ul_estm.percent, /* 3 letters */            /* xfer % */
555
6.74k
                max6data(p->ul.cur_size, max6[1]),          /* xfer size */
556
6.74k
                max6data(p->dl.speed, max6[3]),             /* avrg dl speed */
557
6.74k
                max6data(p->ul.speed, max6[4]),             /* avrg ul speed */
558
6.74k
                time_total,    /* 8 letters */              /* total time */
559
6.74k
                time_spent,    /* 8 letters */              /* time spent */
560
6.74k
                time_left,     /* 8 letters */              /* time left */
561
6.74k
                max6data(p->current_speed, max6[5])
562
6.74k
    );
563
564
  /* we flush the output stream to make it appear as soon as possible */
565
6.74k
  fflush(data->set.err);
566
6.74k
}
567
#else
568
 /* progress bar disabled */
569
#define progress_meter(x) Curl_nop_stmt
570
#endif
571
572
573
/*
574
 * Curl_pgrsUpdate() returns 0 for success or the value returned by the
575
 * progress callback!
576
 */
577
static int pgrsupdate(struct Curl_easy *data, bool showprogress)
578
73.1M
{
579
73.1M
  if(!data->progress.hide) {
580
14.8M
    if(data->set.fxferinfo) {
581
0
      int result;
582
      /* There is a callback set, call that */
583
0
      Curl_set_in_callback(data, TRUE);
584
0
      result = data->set.fxferinfo(data->set.progress_client,
585
0
                                   data->progress.dl.total_size,
586
0
                                   data->progress.dl.cur_size,
587
0
                                   data->progress.ul.total_size,
588
0
                                   data->progress.ul.cur_size);
589
0
      Curl_set_in_callback(data, FALSE);
590
0
      if(result != CURL_PROGRESSFUNC_CONTINUE) {
591
0
        if(result)
592
0
          failf(data, "Callback aborted");
593
0
        return result;
594
0
      }
595
0
    }
596
14.8M
    else if(data->set.fprogress) {
597
0
      int result;
598
      /* The older deprecated callback is set, call that */
599
0
      Curl_set_in_callback(data, TRUE);
600
0
      result = data->set.fprogress(data->set.progress_client,
601
0
                                   (double)data->progress.dl.total_size,
602
0
                                   (double)data->progress.dl.cur_size,
603
0
                                   (double)data->progress.ul.total_size,
604
0
                                   (double)data->progress.ul.cur_size);
605
0
      Curl_set_in_callback(data, FALSE);
606
0
      if(result != CURL_PROGRESSFUNC_CONTINUE) {
607
0
        if(result)
608
0
          failf(data, "Callback aborted");
609
0
        return result;
610
0
      }
611
0
    }
612
613
14.8M
    if(showprogress)
614
6.74k
      progress_meter(data);
615
14.8M
  }
616
617
73.1M
  return 0;
618
73.1M
}
619
620
int Curl_pgrsUpdate(struct Curl_easy *data)
621
73.1M
{
622
73.1M
  struct curltime now = curlx_now(); /* what time is it */
623
73.1M
  bool showprogress = progress_calc(data, now);
624
73.1M
  return pgrsupdate(data, showprogress);
625
73.1M
}
626
627
/*
628
 * Update all progress, do not do progress meter/callbacks.
629
 */
630
void Curl_pgrsUpdate_nometer(struct Curl_easy *data)
631
21.1k
{
632
21.1k
  struct curltime now = curlx_now(); /* what time is it */
633
21.1k
  (void)progress_calc(data, now);
634
21.1k
}