Coverage Report

Created: 2025-12-05 06:38

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
86.5k
{
42
86.5k
  curl_off_t h;
43
86.5k
  if(seconds <= 0) {
44
86.2k
    strcpy(r, "--:--:--");
45
86.2k
    return;
46
86.2k
  }
47
278
  h = seconds / 3600;
48
278
  if(h <= 99) {
49
42
    curl_off_t m = (seconds - (h * 3600)) / 60;
50
42
    curl_off_t s = (seconds - (h * 3600)) - (m * 60);
51
42
    curl_msnprintf(r, 9, "%2" FMT_OFF_T ":%02" FMT_OFF_T ":%02" FMT_OFF_T,
52
42
                   h, m, s);
53
42
  }
54
236
  else {
55
    /* this equals to more than 99 hours, switch to a more suitable output
56
       format to fit within the limits. */
57
236
    curl_off_t d = seconds / 86400;
58
236
    h = (seconds - (d * 86400)) / 3600;
59
236
    if(d <= 999)
60
18
      curl_msnprintf(r, 9, "%3" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h);
61
218
    else
62
218
      curl_msnprintf(r, 9, "%7" FMT_OFF_T "d", d);
63
236
  }
64
278
}
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
173k
{
71
  /* a signed 64-bit value is 8192 petabytes maximum, shown as
72
     8.0E (exabytes)*/
73
173k
  if(bytes < 100000)
74
112k
    curl_msnprintf(max6, 7, "%6" CURL_FORMAT_CURL_OFF_T, bytes);
75
61.0k
  else {
76
61.0k
    const char unit[] = { 'k', 'M', 'G', 'T', 'P', 'E', 0 };
77
61.0k
    int k = 0;
78
61.0k
    curl_off_t nbytes;
79
91.6k
    do {
80
91.6k
      nbytes = bytes / 1024;
81
91.6k
      if(nbytes < 1000)
82
61.0k
        break;
83
30.6k
      bytes = nbytes;
84
30.6k
      k++;
85
30.6k
      DEBUGASSERT(unit[k]);
86
30.6k
    } while(unit[k]);
87
    /* xxx.yU */
88
61.0k
    curl_msnprintf(max6, 7, "%3" CURL_FORMAT_CURL_OFF_T
89
61.0k
                   ".%" CURL_FORMAT_CURL_OFF_T "%c", nbytes,
90
61.0k
                   (bytes % 1024) / (1024 / 10), unit[k]);
91
61.0k
  }
92
173k
  return max6;
93
173k
}
94
#endif
95
96
static void pgrs_speedinit(struct Curl_easy *data)
97
139k
{
98
139k
  memset(&data->state.keeps_speed, 0, sizeof(struct curltime));
99
139k
}
100
101
/*
102
 * @unittest: 1606
103
 */
104
UNITTEST CURLcode pgrs_speedcheck(struct Curl_easy *data,
105
                                  struct curltime *pnow)
106
16.6M
{
107
16.6M
  if(!data->set.low_speed_time || !data->set.low_speed_limit ||
108
529k
     Curl_xfer_recv_is_paused(data) || Curl_xfer_send_is_paused(data))
109
    /* A paused transfer is not qualified for speed checks */
110
16.0M
    return CURLE_OK;
111
112
529k
  if(data->progress.current_speed >= 0) {
113
529k
    if(data->progress.current_speed < data->set.low_speed_limit) {
114
529k
      if(!data->state.keeps_speed.tv_sec)
115
        /* under the limit at this moment */
116
637
        data->state.keeps_speed = *pnow;
117
528k
      else {
118
        /* how long has it been under the limit */
119
528k
        timediff_t howlong = curlx_timediff_ms(*pnow, data->state.keeps_speed);
120
121
528k
        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
528k
      }
131
529k
    }
132
21
    else
133
      /* faster right now */
134
21
      data->state.keeps_speed.tv_sec = 0;
135
529k
  }
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
529k
  Curl_expire(data, 1000, EXPIRE_SPEEDCHECK);
140
141
529k
  return CURLE_OK;
142
529k
}
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
121k
{
160
121k
  int rc;
161
121k
  data->progress.lastshow = 0;
162
121k
  rc = Curl_pgrsUpdate(data); /* the final (forced) update */
163
121k
  if(rc)
164
0
    return rc;
165
166
121k
  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
3.20k
    curl_mfprintf(data->set.err, "\n");
170
171
121k
  return 0;
172
121k
}
173
174
void Curl_pgrsReset(struct Curl_easy *data)
175
139k
{
176
139k
  Curl_pgrsSetUploadCounter(data, 0);
177
139k
  Curl_pgrsSetDownloadCounter(data, 0);
178
139k
  Curl_pgrsSetUploadSize(data, -1);
179
139k
  Curl_pgrsSetDownloadSize(data, -1);
180
139k
  data->progress.speeder_c = 0; /* reset speed records */
181
139k
  pgrs_speedinit(data);
182
139k
}
183
184
/* reset the known transfer sizes */
185
void Curl_pgrsResetTransferSizes(struct Curl_easy *data)
186
148k
{
187
148k
  Curl_pgrsSetDownloadSize(data, -1);
188
148k
  Curl_pgrsSetUploadSize(data, -1);
189
148k
}
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
818k
{
214
818k
  timediff_t *delta = NULL;
215
216
818k
  switch(timer) {
217
0
  default:
218
0
  case TIMER_NONE:
219
    /* mistake filter */
220
0
    break;
221
159k
  case TIMER_STARTOP:
222
    /* This is set at the start of a transfer */
223
159k
    data->progress.t_startop = timestamp;
224
159k
    data->progress.t_startqueue = timestamp;
225
159k
    data->progress.t_postqueue = 0;
226
159k
    break;
227
148k
  case TIMER_STARTSINGLE:
228
    /* This is set at the start of each single transfer */
229
148k
    data->progress.t_startsingle = timestamp;
230
148k
    data->progress.is_t_startransfer_set = FALSE;
231
148k
    break;
232
127k
  case TIMER_POSTQUEUE:
233
    /* Queue time is accumulative from all involved redirects */
234
127k
    data->progress.t_postqueue +=
235
127k
      curlx_timediff_us(timestamp, data->progress.t_startqueue);
236
127k
    break;
237
12.1k
  case TIMER_STARTACCEPT:
238
12.1k
    data->progress.t_acceptdata = timestamp;
239
12.1k
    break;
240
102k
  case TIMER_NAMELOOKUP:
241
102k
    delta = &data->progress.t_nslookup;
242
102k
    break;
243
100k
  case TIMER_CONNECT:
244
100k
    delta = &data->progress.t_connect;
245
100k
    break;
246
0
  case TIMER_APPCONNECT:
247
0
    delta = &data->progress.t_appconnect;
248
0
    break;
249
59.4k
  case TIMER_PRETRANSFER:
250
59.4k
    delta = &data->progress.t_pretransfer;
251
59.4k
    break;
252
34.7k
  case TIMER_STARTTRANSFER:
253
34.7k
    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
34.7k
    if(data->progress.is_t_startransfer_set) {
261
2
      return;
262
2
    }
263
34.7k
    else {
264
34.7k
      data->progress.is_t_startransfer_set = TRUE;
265
34.7k
      break;
266
34.7k
    }
267
54.2k
  case TIMER_POSTRANSFER:
268
54.2k
    delta = &data->progress.t_posttransfer;
269
54.2k
    break;
270
19.3k
  case TIMER_REDIRECT:
271
19.3k
    data->progress.t_redirect = curlx_timediff_us(timestamp,
272
19.3k
                                                 data->progress.start);
273
19.3k
    data->progress.t_startqueue = timestamp;
274
19.3k
    break;
275
818k
  }
276
818k
  if(delta) {
277
351k
    timediff_t us = curlx_timediff_us(timestamp, data->progress.t_startsingle);
278
351k
    if(us < 1)
279
0
      us = 1; /* make sure at least one microsecond passed */
280
351k
    *delta += us;
281
351k
  }
282
818k
}
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
718k
{
293
718k
  struct curltime now = curlx_now();
294
295
718k
  Curl_pgrsTimeWas(data, timer, now);
296
718k
  return now;
297
718k
}
298
299
void Curl_pgrsStartNow(struct Curl_easy *data)
300
128k
{
301
128k
  struct Progress *p = &data->progress;
302
128k
  p->speeder_c = 0; /* reset the progress meter display */
303
128k
  p->start = curlx_now();
304
128k
  p->is_t_startransfer_set = FALSE;
305
128k
  p->dl.cur_size = 0;
306
128k
  p->ul.cur_size = 0;
307
  /* the sizes are unknown at start */
308
128k
  p->dl_size_known = FALSE;
309
128k
  p->ul_size_known = FALSE;
310
128k
}
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
949k
{
317
949k
  data->progress.dl.cur_size = size;
318
949k
}
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
149k
{
325
149k
  data->progress.ul.cur_size = size;
326
149k
}
327
328
void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size)
329
299k
{
330
299k
  if(size >= 0) {
331
10.8k
    data->progress.dl.total_size = size;
332
10.8k
    data->progress.dl_size_known = TRUE;
333
10.8k
  }
334
288k
  else {
335
288k
    data->progress.dl.total_size = 0;
336
288k
    data->progress.dl_size_known = FALSE;
337
288k
  }
338
299k
}
339
340
void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
341
326k
{
342
326k
  if(size >= 0) {
343
37.5k
    data->progress.ul.total_size = size;
344
37.5k
    data->progress.ul_size_known = TRUE;
345
37.5k
  }
346
289k
  else {
347
289k
    data->progress.ul.total_size = 0;
348
289k
    data->progress.ul_size_known = FALSE;
349
289k
  }
350
326k
}
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
142M
{
361
142M
  if(us < 1)
362
142
    return size * 1000000;
363
142M
  else if(size < CURL_OFF_T_MAX / 1000000)
364
142M
    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
142M
}
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
71.1M
{
374
71.1M
  struct Progress * const p = &data->progress;
375
71.1M
  int i_next, i_oldest, i_latest;
376
71.1M
  timediff_t duration_ms;
377
71.1M
  curl_off_t amount;
378
379
  /* The time spent so far (from the start) in microseconds */
380
71.1M
  p->timespent = curlx_timediff_us(*pnow, p->start);
381
71.1M
  p->dl.speed = trspeed(p->dl.cur_size, p->timespent);
382
71.1M
  p->ul.speed = trspeed(p->ul.cur_size, p->timespent);
383
384
71.1M
  if(!p->speeder_c) { /* no previous record exists */
385
163k
    p->speed_amount[0] = p->dl.cur_size + p->ul.cur_size;
386
163k
    p->speed_time[0] = *pnow;
387
163k
    p->speeder_c++;
388
    /* use the overall average at the start */
389
163k
    p->current_speed = p->ul.speed + p->dl.speed;
390
163k
    p->lastshow = pnow->tv_sec;
391
163k
    return TRUE;
392
163k
  }
393
  /* We have at least one record now. Where to put the next and
394
   * where is the latest one? */
395
70.9M
  i_next = p->speeder_c % CURL_SPEED_RECORDS;
396
70.9M
  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
70.9M
  if(curlx_timediff_ms(*pnow, p->speed_time[i_latest]) >= 1000) {
401
6
    p->speeder_c++;
402
6
    i_latest = i_next;
403
6
    p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size;
404
6
    p->speed_time[i_latest] = *pnow;
405
6
  }
406
70.9M
  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
106k
    if(!p->current_speed) {
412
105k
      p->speed_amount[i_latest] = p->dl.cur_size + p->ul.cur_size;
413
105k
      p->speed_time[i_latest] = *pnow;
414
105k
    }
415
106k
  }
416
70.8M
  else {
417
    /* transfer ongoing, wait for more time to pass. */
418
70.8M
    return FALSE;
419
70.8M
  }
420
421
106k
  i_oldest = (p->speeder_c < CURL_SPEED_RECORDS) ? 0 :
422
106k
             ((i_latest + 1) % CURL_SPEED_RECORDS);
423
424
  /* How much we transferred between oldest and current records */
425
106k
  amount = p->speed_amount[i_latest] - p->speed_amount[i_oldest];
426
  /* How long this took */
427
106k
  duration_ms = curlx_timediff_ms(p->speed_time[i_latest],
428
106k
                                  p->speed_time[i_oldest]);
429
106k
  if(duration_ms <= 0)
430
106k
    duration_ms = 1;
431
432
106k
  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
106k
  else {
439
    /* the 'amount' value is small enough to fit within 32 bits even
440
       when multiplied with 1000 */
441
106k
    p->current_speed = amount * 1000 / duration_ms;
442
106k
  }
443
444
106k
  if((p->lastshow == pnow->tv_sec) && !data->req.done)
445
0
    return FALSE;
446
106k
  p->lastshow = pnow->tv_sec;
447
106k
  return TRUE;
448
106k
}
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
49.8k
{
459
49.8k
  if(total > 10000)
460
40.6k
    return cur / (total / 100);
461
9.17k
  else if(total > 0)
462
2.87k
    return (cur * 100) / total;
463
6.30k
  return 0;
464
49.8k
}
465
466
static void pgrs_estimates(struct pgrs_dir *d,
467
                           bool total_known,
468
                           struct pgrs_estimate *est)
469
57.6k
{
470
57.6k
  est->secs = 0;
471
57.6k
  est->percent = 0;
472
57.6k
  if(total_known && (d->speed > 0)) {
473
21.0k
    est->secs = d->total_size / d->speed;
474
21.0k
    est->percent = pgrs_est_percent(d->total_size, d->cur_size);
475
21.0k
  }
476
57.6k
}
477
478
static void progress_meter(struct Curl_easy *data)
479
28.8k
{
480
28.8k
  struct Progress *p = &data->progress;
481
28.8k
  char max6[6][7];
482
28.8k
  struct pgrs_estimate dl_estm;
483
28.8k
  struct pgrs_estimate ul_estm;
484
28.8k
  struct pgrs_estimate total_estm;
485
28.8k
  curl_off_t total_cur_size;
486
28.8k
  curl_off_t total_expected_size;
487
28.8k
  curl_off_t dl_size;
488
28.8k
  char time_left[10];
489
28.8k
  char time_total[10];
490
28.8k
  char time_spent[10];
491
28.8k
  curl_off_t cur_secs = (curl_off_t)p->timespent / 1000000; /* seconds */
492
493
28.8k
  if(!p->headers_out) {
494
1.92k
    if(data->state.resume_from) {
495
234
      curl_mfprintf(data->set.err,
496
234
                    "** Resuming transfer from byte position %" FMT_OFF_T "\n",
497
234
                    data->state.resume_from);
498
234
    }
499
1.92k
    curl_mfprintf(data->set.err,
500
1.92k
                  "  %% Total    %% Received %% Xferd  Average Speed   "
501
1.92k
                  "Time    Time     Time  Current\n"
502
1.92k
                  "                                 Dload  Upload   "
503
1.92k
                  "Total   Spent    Left  Speed\n");
504
1.92k
    p->headers_out = TRUE; /* headers are shown */
505
1.92k
  }
506
507
  /* Figure out the estimated time of arrival for upload and download */
508
28.8k
  pgrs_estimates(&p->ul, (bool)p->ul_size_known, &ul_estm);
509
28.8k
  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
28.8k
  total_estm.secs = CURLMAX(ul_estm.secs, dl_estm.secs);
513
  /* create the three time strings */
514
28.8k
  time2str(time_left, total_estm.secs > 0 ? (total_estm.secs - cur_secs) : 0);
515
28.8k
  time2str(time_total, total_estm.secs);
516
28.8k
  time2str(time_spent, cur_secs);
517
518
  /* Get the total amount of data expected to get transferred */
519
28.8k
  total_expected_size = p->ul_size_known ? p->ul.total_size : p->ul.cur_size;
520
521
28.8k
  dl_size = p->dl_size_known ? p->dl.total_size : p->dl.cur_size;
522
523
  /* integer overflow check */
524
28.8k
  if((CURL_OFF_T_MAX - total_expected_size) < dl_size)
525
3
    total_expected_size = CURL_OFF_T_MAX; /* capped */
526
28.8k
  else
527
28.8k
    total_expected_size += dl_size;
528
529
  /* We have transferred this much so far */
530
28.8k
  total_cur_size = p->dl.cur_size + p->ul.cur_size;
531
532
  /* Get the percentage of data transferred so far */
533
28.8k
  total_estm.percent = pgrs_est_percent(total_expected_size, total_cur_size);
534
535
28.8k
  curl_mfprintf(data->set.err,
536
28.8k
                "\r"
537
28.8k
                "%3" FMT_OFF_T " %s "
538
28.8k
                "%3" FMT_OFF_T " %s "
539
28.8k
                "%3" FMT_OFF_T " %s %s %s  %s %s %s %s",
540
28.8k
                total_estm.percent, /* 3 letters */         /* total % */
541
28.8k
                max6data(total_expected_size, max6[2]),     /* total size */
542
28.8k
                dl_estm.percent, /* 3 letters */            /* rcvd % */
543
28.8k
                max6data(p->dl.cur_size, max6[0]),          /* rcvd size */
544
28.8k
                ul_estm.percent, /* 3 letters */            /* xfer % */
545
28.8k
                max6data(p->ul.cur_size, max6[1]),          /* xfer size */
546
28.8k
                max6data(p->dl.speed, max6[3]),             /* avrg dl speed */
547
28.8k
                max6data(p->ul.speed, max6[4]),             /* avrg ul speed */
548
28.8k
                time_total,    /* 8 letters */              /* total time */
549
28.8k
                time_spent,    /* 8 letters */              /* time spent */
550
28.8k
                time_left,     /* 8 letters */              /* time left */
551
28.8k
                max6data(p->current_speed, max6[5])
552
28.8k
    );
553
554
  /* we flush the output stream to make it appear as soon as possible */
555
28.8k
  fflush(data->set.err);
556
28.8k
}
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
71.1M
{
568
71.1M
  if(!data->progress.hide) {
569
12.0M
    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
12.0M
    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
12.0M
    if(showprogress)
607
28.8k
      progress_meter(data);
608
12.0M
  }
609
610
71.1M
  return CURLE_OK;
611
71.1M
}
612
613
static CURLcode pgrs_update(struct Curl_easy *data, struct curltime *pnow)
614
71.1M
{
615
71.1M
  bool showprogress = progress_calc(data, pnow);
616
71.1M
  return pgrsupdate(data, showprogress);
617
71.1M
}
618
619
CURLcode Curl_pgrsUpdate(struct Curl_easy *data)
620
54.5M
{
621
54.5M
  struct curltime now = curlx_now(); /* what time is it */
622
54.5M
  return pgrs_update(data, &now);
623
54.5M
}
624
625
CURLcode Curl_pgrsCheck(struct Curl_easy *data)
626
16.6M
{
627
16.6M
  struct curltime now = curlx_now();
628
16.6M
  CURLcode result;
629
630
16.6M
  result = pgrs_update(data, &now);
631
16.6M
  if(!result && !data->req.done)
632
16.6M
    result = pgrs_speedcheck(data, &now);
633
16.6M
  return result;
634
16.6M
}
635
636
/*
637
 * Update all progress, do not do progress meter/callbacks.
638
 */
639
void Curl_pgrsUpdate_nometer(struct Curl_easy *data)
640
20.9k
{
641
20.9k
  struct curltime now = curlx_now(); /* what time is it */
642
20.9k
  (void)progress_calc(data, &now);
643
20.9k
}