Coverage Report

Created: 2026-02-26 06:33

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