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 "timeval.h"
32 #include "curl_printf.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) */
time2str(char * r,curl_off_t seconds)40 static void time2str(char *r, curl_off_t seconds)
41 {
42 curl_off_t h;
43 if(seconds <= 0) {
44 strcpy(r, "--:--:--");
45 return;
46 }
47 h = seconds / CURL_OFF_T_C(3600);
48 if(h <= CURL_OFF_T_C(99)) {
49 curl_off_t m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
50 curl_off_t s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
51 msnprintf(r, 9, "%2" FMT_OFF_T ":%02" FMT_OFF_T ":%02" FMT_OFF_T, h, m, s);
52 }
53 else {
54 /* this equals to more than 99 hours, switch to a more suitable output
55 format to fit within the limits. */
56 curl_off_t d = seconds / CURL_OFF_T_C(86400);
57 h = (seconds - (d*CURL_OFF_T_C(86400))) / CURL_OFF_T_C(3600);
58 if(d <= CURL_OFF_T_C(999))
59 msnprintf(r, 9, "%3" FMT_OFF_T "d %02" FMT_OFF_T "h", d, h);
60 else
61 msnprintf(r, 9, "%7" FMT_OFF_T "d", d);
62 }
63 }
64
65 /* The point of this function would be to return a string of the input data,
66 but never longer than 5 columns (+ one zero byte).
67 Add suffix k, M, G when suitable... */
max5data(curl_off_t bytes,char * max5)68 static char *max5data(curl_off_t bytes, char *max5)
69 {
70 #define ONE_KILOBYTE CURL_OFF_T_C(1024)
71 #define ONE_MEGABYTE (CURL_OFF_T_C(1024) * ONE_KILOBYTE)
72 #define ONE_GIGABYTE (CURL_OFF_T_C(1024) * ONE_MEGABYTE)
73 #define ONE_TERABYTE (CURL_OFF_T_C(1024) * ONE_GIGABYTE)
74 #define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE)
75
76 if(bytes < CURL_OFF_T_C(100000))
77 msnprintf(max5, 6, "%5" FMT_OFF_T, bytes);
78
79 else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE)
80 msnprintf(max5, 6, "%4" FMT_OFF_T "k", bytes/ONE_KILOBYTE);
81
82 else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE)
83 /* 'XX.XM' is good as long as we are less than 100 megs */
84 msnprintf(max5, 6, "%2" FMT_OFF_T ".%0"
85 FMT_OFF_T "M", bytes/ONE_MEGABYTE,
86 (bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) );
87
88 else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE)
89 /* 'XXXXM' is good until we are at 10000MB or above */
90 msnprintf(max5, 6, "%4" FMT_OFF_T "M", bytes/ONE_MEGABYTE);
91
92 else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE)
93 /* 10000 MB - 100 GB, we show it as XX.XG */
94 msnprintf(max5, 6, "%2" FMT_OFF_T ".%0"
95 FMT_OFF_T "G", bytes/ONE_GIGABYTE,
96 (bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) );
97
98 else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE)
99 /* up to 10000GB, display without decimal: XXXXG */
100 msnprintf(max5, 6, "%4" FMT_OFF_T "G", bytes/ONE_GIGABYTE);
101
102 else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE)
103 /* up to 10000TB, display without decimal: XXXXT */
104 msnprintf(max5, 6, "%4" FMT_OFF_T "T", bytes/ONE_TERABYTE);
105
106 else
107 /* up to 10000PB, display without decimal: XXXXP */
108 msnprintf(max5, 6, "%4" FMT_OFF_T "P", bytes/ONE_PETABYTE);
109
110 /* 16384 petabytes (16 exabytes) is the maximum a 64-bit unsigned number can
111 hold, but our data type is signed so 8192PB will be the maximum. */
112
113 return max5;
114 }
115 #endif
116
117 /*
118
119 New proposed interface, 9th of February 2000:
120
121 pgrsStartNow() - sets start time
122 pgrsSetDownloadSize(x) - known expected download size
123 pgrsSetUploadSize(x) - known expected upload size
124 pgrsSetDownloadCounter() - amount of data currently downloaded
125 pgrsSetUploadCounter() - amount of data currently uploaded
126 pgrsUpdate() - show progress
127 pgrsDone() - transfer complete
128
129 */
130
Curl_pgrsDone(struct Curl_easy * data)131 int Curl_pgrsDone(struct Curl_easy *data)
132 {
133 int rc;
134 data->progress.lastshow = 0;
135 rc = Curl_pgrsUpdate(data); /* the final (forced) update */
136 if(rc)
137 return rc;
138
139 if(!(data->progress.flags & PGRS_HIDE) &&
140 !data->progress.callback)
141 /* only output if we do not use a progress callback and we are not
142 * hidden */
143 fprintf(data->set.err, "\n");
144
145 data->progress.speeder_c = 0; /* reset the progress meter display */
146 return 0;
147 }
148
149 /* reset the known transfer sizes */
Curl_pgrsResetTransferSizes(struct Curl_easy * data)150 void Curl_pgrsResetTransferSizes(struct Curl_easy *data)
151 {
152 Curl_pgrsSetDownloadSize(data, -1);
153 Curl_pgrsSetUploadSize(data, -1);
154 }
155
156 /*
157 *
158 * Curl_pgrsTimeWas(). Store the timestamp time at the given label.
159 */
Curl_pgrsTimeWas(struct Curl_easy * data,timerid timer,struct curltime timestamp)160 void Curl_pgrsTimeWas(struct Curl_easy *data, timerid timer,
161 struct curltime timestamp)
162 {
163 timediff_t *delta = NULL;
164
165 switch(timer) {
166 default:
167 case TIMER_NONE:
168 /* mistake filter */
169 break;
170 case TIMER_STARTOP:
171 /* This is set at the start of a transfer */
172 data->progress.t_startop = timestamp;
173 break;
174 case TIMER_STARTSINGLE:
175 /* This is set at the start of each single transfer */
176 data->progress.t_startsingle = timestamp;
177 data->progress.is_t_startransfer_set = false;
178 break;
179 case TIMER_POSTQUEUE:
180 /* Set when the transfer starts (after potentially having been brought
181 back from the waiting queue). It needs to count from t_startop and not
182 t_startsingle since the latter is reset when a connection is brought
183 back from the pending queue. */
184 data->progress.t_postqueue =
185 Curl_timediff_us(timestamp, data->progress.t_startop);
186 break;
187 case TIMER_STARTACCEPT:
188 data->progress.t_acceptdata = timestamp;
189 break;
190 case TIMER_NAMELOOKUP:
191 delta = &data->progress.t_nslookup;
192 break;
193 case TIMER_CONNECT:
194 delta = &data->progress.t_connect;
195 break;
196 case TIMER_APPCONNECT:
197 delta = &data->progress.t_appconnect;
198 break;
199 case TIMER_PRETRANSFER:
200 delta = &data->progress.t_pretransfer;
201 break;
202 case TIMER_STARTTRANSFER:
203 delta = &data->progress.t_starttransfer;
204 /* prevent updating t_starttransfer unless:
205 * 1) this is the first time we are setting t_starttransfer
206 * 2) a redirect has occurred since the last time t_starttransfer was set
207 * This prevents repeated invocations of the function from incorrectly
208 * changing the t_starttransfer time.
209 */
210 if(data->progress.is_t_startransfer_set) {
211 return;
212 }
213 else {
214 data->progress.is_t_startransfer_set = true;
215 break;
216 }
217 case TIMER_POSTRANSFER:
218 delta = &data->progress.t_posttransfer;
219 break;
220 case TIMER_REDIRECT:
221 data->progress.t_redirect = Curl_timediff_us(timestamp,
222 data->progress.start);
223 break;
224 }
225 if(delta) {
226 timediff_t us = Curl_timediff_us(timestamp, data->progress.t_startsingle);
227 if(us < 1)
228 us = 1; /* make sure at least one microsecond passed */
229 *delta += us;
230 }
231 }
232
233 /*
234 *
235 * Curl_pgrsTime(). Store the current time at the given label. This fetches a
236 * fresh "now" and returns it.
237 *
238 * @unittest: 1399
239 */
Curl_pgrsTime(struct Curl_easy * data,timerid timer)240 struct curltime Curl_pgrsTime(struct Curl_easy *data, timerid timer)
241 {
242 struct curltime now = Curl_now();
243
244 Curl_pgrsTimeWas(data, timer, now);
245 return now;
246 }
247
Curl_pgrsStartNow(struct Curl_easy * data)248 void Curl_pgrsStartNow(struct Curl_easy *data)
249 {
250 data->progress.speeder_c = 0; /* reset the progress meter display */
251 data->progress.start = Curl_now();
252 data->progress.is_t_startransfer_set = false;
253 data->progress.ul.limit.start = data->progress.start;
254 data->progress.dl.limit.start = data->progress.start;
255 data->progress.ul.limit.start_size = 0;
256 data->progress.dl.limit.start_size = 0;
257 data->progress.dl.cur_size = 0;
258 data->progress.ul.cur_size = 0;
259 /* clear all bits except HIDE and HEADERS_OUT */
260 data->progress.flags &= PGRS_HIDE|PGRS_HEADERS_OUT;
261 Curl_ratelimit(data, data->progress.start);
262 }
263
264 /*
265 * This is used to handle speed limits, calculating how many milliseconds to
266 * wait until we are back under the speed limit, if needed.
267 *
268 * The way it works is by having a "starting point" (time & amount of data
269 * transferred by then) used in the speed computation, to be used instead of
270 * the start of the transfer. This starting point is regularly moved as
271 * transfer goes on, to keep getting accurate values (instead of average over
272 * the entire transfer).
273 *
274 * This function takes the current amount of data transferred, the amount at
275 * the starting point, the limit (in bytes/s), the time of the starting point
276 * and the current time.
277 *
278 * Returns 0 if no waiting is needed or when no waiting is needed but the
279 * starting point should be reset (to current); or the number of milliseconds
280 * to wait to get back under the speed limit.
281 */
Curl_pgrsLimitWaitTime(struct pgrs_dir * d,curl_off_t speed_limit,struct curltime now)282 timediff_t Curl_pgrsLimitWaitTime(struct pgrs_dir *d,
283 curl_off_t speed_limit,
284 struct curltime now)
285 {
286 curl_off_t size = d->cur_size - d->limit.start_size;
287 timediff_t minimum;
288 timediff_t actual;
289
290 if(!speed_limit || !size)
291 return 0;
292
293 /*
294 * 'minimum' is the number of milliseconds 'size' should take to download to
295 * stay below 'limit'.
296 */
297 if(size < CURL_OFF_T_MAX/1000)
298 minimum = (timediff_t) (CURL_OFF_T_C(1000) * size / speed_limit);
299 else {
300 minimum = (timediff_t) (size / speed_limit);
301 if(minimum < TIMEDIFF_T_MAX/1000)
302 minimum *= 1000;
303 else
304 minimum = TIMEDIFF_T_MAX;
305 }
306
307 /*
308 * 'actual' is the time in milliseconds it took to actually download the
309 * last 'size' bytes.
310 */
311 actual = Curl_timediff_ceil(now, d->limit.start);
312 if(actual < minimum) {
313 /* if it downloaded the data faster than the limit, make it wait the
314 difference */
315 return (minimum - actual);
316 }
317
318 return 0;
319 }
320
321 /*
322 * Set the number of downloaded bytes so far.
323 */
Curl_pgrsSetDownloadCounter(struct Curl_easy * data,curl_off_t size)324 CURLcode Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
325 {
326 data->progress.dl.cur_size = size;
327 return CURLE_OK;
328 }
329
330 /*
331 * Update the timestamp and sizestamp to use for rate limit calculations.
332 */
Curl_ratelimit(struct Curl_easy * data,struct curltime now)333 void Curl_ratelimit(struct Curl_easy *data, struct curltime now)
334 {
335 /* do not set a new stamp unless the time since last update is long enough */
336 if(data->set.max_recv_speed) {
337 if(Curl_timediff(now, data->progress.dl.limit.start) >=
338 MIN_RATE_LIMIT_PERIOD) {
339 data->progress.dl.limit.start = now;
340 data->progress.dl.limit.start_size = data->progress.dl.cur_size;
341 }
342 }
343 if(data->set.max_send_speed) {
344 if(Curl_timediff(now, data->progress.ul.limit.start) >=
345 MIN_RATE_LIMIT_PERIOD) {
346 data->progress.ul.limit.start = now;
347 data->progress.ul.limit.start_size = data->progress.ul.cur_size;
348 }
349 }
350 }
351
352 /*
353 * Set the number of uploaded bytes so far.
354 */
Curl_pgrsSetUploadCounter(struct Curl_easy * data,curl_off_t size)355 void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size)
356 {
357 data->progress.ul.cur_size = size;
358 }
359
Curl_pgrsSetDownloadSize(struct Curl_easy * data,curl_off_t size)360 void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size)
361 {
362 if(size >= 0) {
363 data->progress.dl.total_size = size;
364 data->progress.flags |= PGRS_DL_SIZE_KNOWN;
365 }
366 else {
367 data->progress.dl.total_size = 0;
368 data->progress.flags &= ~PGRS_DL_SIZE_KNOWN;
369 }
370 }
371
Curl_pgrsSetUploadSize(struct Curl_easy * data,curl_off_t size)372 void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
373 {
374 if(size >= 0) {
375 data->progress.ul.total_size = size;
376 data->progress.flags |= PGRS_UL_SIZE_KNOWN;
377 }
378 else {
379 data->progress.ul.total_size = 0;
380 data->progress.flags &= ~PGRS_UL_SIZE_KNOWN;
381 }
382 }
383
384 /* returns the average speed in bytes / second */
trspeed(curl_off_t size,curl_off_t us)385 static curl_off_t trspeed(curl_off_t size, /* number of bytes */
386 curl_off_t us) /* microseconds */
387 {
388 if(us < 1)
389 return size * 1000000;
390 else if(size < CURL_OFF_T_MAX/1000000)
391 return (size * 1000000) / us;
392 else if(us >= 1000000)
393 return size / (us / 1000000);
394 else
395 return CURL_OFF_T_MAX;
396 }
397
398 /* returns TRUE if it is time to show the progress meter */
progress_calc(struct Curl_easy * data,struct curltime now)399 static bool progress_calc(struct Curl_easy *data, struct curltime now)
400 {
401 bool timetoshow = FALSE;
402 struct Progress * const p = &data->progress;
403
404 /* The time spent so far (from the start) in microseconds */
405 p->timespent = Curl_timediff_us(now, p->start);
406 p->dl.speed = trspeed(p->dl.cur_size, p->timespent);
407 p->ul.speed = trspeed(p->ul.cur_size, p->timespent);
408
409 /* Calculations done at most once a second, unless end is reached */
410 if(p->lastshow != now.tv_sec) {
411 int countindex; /* amount of seconds stored in the speeder array */
412 int nowindex = p->speeder_c% CURR_TIME;
413 p->lastshow = now.tv_sec;
414 timetoshow = TRUE;
415
416 /* Let's do the "current speed" thing, with the dl + ul speeds
417 combined. Store the speed at entry 'nowindex'. */
418 p->speeder[ nowindex ] = p->dl.cur_size + p->ul.cur_size;
419
420 /* remember the exact time for this moment */
421 p->speeder_time [ nowindex ] = now;
422
423 /* advance our speeder_c counter, which is increased every time we get
424 here and we expect it to never wrap as 2^32 is a lot of seconds! */
425 p->speeder_c++;
426
427 /* figure out how many index entries of data we have stored in our speeder
428 array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of
429 transfer. Imagine, after one second we have filled in two entries,
430 after two seconds we have filled in three entries etc. */
431 countindex = ((p->speeder_c >= CURR_TIME) ? CURR_TIME : p->speeder_c) - 1;
432
433 /* first of all, we do not do this if there is no counted seconds yet */
434 if(countindex) {
435 int checkindex;
436 timediff_t span_ms;
437 curl_off_t amount;
438
439 /* Get the index position to compare with the 'nowindex' position.
440 Get the oldest entry possible. While we have less than CURR_TIME
441 entries, the first entry will remain the oldest. */
442 checkindex = (p->speeder_c >= CURR_TIME) ? p->speeder_c%CURR_TIME : 0;
443
444 /* Figure out the exact time for the time span */
445 span_ms = Curl_timediff(now, p->speeder_time[checkindex]);
446 if(0 == span_ms)
447 span_ms = 1; /* at least one millisecond MUST have passed */
448
449 /* Calculate the average speed the last 'span_ms' milliseconds */
450 amount = p->speeder[nowindex]- p->speeder[checkindex];
451
452 if(amount > CURL_OFF_T_C(4294967) /* 0xffffffff/1000 */)
453 /* the 'amount' value is bigger than would fit in 32 bits if
454 multiplied with 1000, so we use the double math for this */
455 p->current_speed = (curl_off_t)
456 ((double)amount/((double)span_ms/1000.0));
457 else
458 /* the 'amount' value is small enough to fit within 32 bits even
459 when multiplied with 1000 */
460 p->current_speed = amount*CURL_OFF_T_C(1000)/span_ms;
461 }
462 else
463 /* the first second we use the average */
464 p->current_speed = p->ul.speed + p->dl.speed;
465
466 } /* Calculations end */
467 return timetoshow;
468 }
469
470 #ifndef CURL_DISABLE_PROGRESS_METER
471
472 struct pgrs_estimate {
473 curl_off_t secs;
474 curl_off_t percent;
475 };
476
pgrs_est_percent(curl_off_t total,curl_off_t cur)477 static curl_off_t pgrs_est_percent(curl_off_t total, curl_off_t cur)
478 {
479 if(total > CURL_OFF_T_C(10000))
480 return cur / (total/CURL_OFF_T_C(100));
481 else if(total > CURL_OFF_T_C(0))
482 return (cur*100) / total;
483 return 0;
484 }
485
pgrs_estimates(struct pgrs_dir * d,bool total_known,struct pgrs_estimate * est)486 static void pgrs_estimates(struct pgrs_dir *d,
487 bool total_known,
488 struct pgrs_estimate *est)
489 {
490 est->secs = 0;
491 est->percent = 0;
492 if(total_known && (d->speed > CURL_OFF_T_C(0))) {
493 est->secs = d->total_size / d->speed;
494 est->percent = pgrs_est_percent(d->total_size, d->cur_size);
495 }
496 }
497
progress_meter(struct Curl_easy * data)498 static void progress_meter(struct Curl_easy *data)
499 {
500 struct Progress *p = &data->progress;
501 char max5[6][10];
502 struct pgrs_estimate dl_estm;
503 struct pgrs_estimate ul_estm;
504 struct pgrs_estimate total_estm;
505 curl_off_t total_cur_size;
506 curl_off_t total_expected_size;
507 char time_left[10];
508 char time_total[10];
509 char time_spent[10];
510 curl_off_t cur_secs = (curl_off_t)p->timespent/1000000; /* seconds */
511
512 if(!(p->flags & PGRS_HEADERS_OUT)) {
513 if(data->state.resume_from) {
514 fprintf(data->set.err,
515 "** Resuming transfer from byte position %" FMT_OFF_T "\n",
516 data->state.resume_from);
517 }
518 fprintf(data->set.err,
519 " %% Total %% Received %% Xferd Average Speed "
520 "Time Time Time Current\n"
521 " Dload Upload "
522 "Total Spent Left Speed\n");
523 p->flags |= PGRS_HEADERS_OUT; /* headers are shown */
524 }
525
526 /* Figure out the estimated time of arrival for upload and download */
527 pgrs_estimates(&p->ul, (p->flags & PGRS_UL_SIZE_KNOWN), &ul_estm);
528 pgrs_estimates(&p->dl, (p->flags & PGRS_DL_SIZE_KNOWN), &dl_estm);
529
530 /* Since both happen at the same time, total expected duration is max. */
531 total_estm.secs = CURLMAX(ul_estm.secs, dl_estm.secs);
532 /* create the three time strings */
533 time2str(time_left, total_estm.secs > 0 ? (total_estm.secs - cur_secs) : 0);
534 time2str(time_total, total_estm.secs);
535 time2str(time_spent, cur_secs);
536
537 /* Get the total amount of data expected to get transferred */
538 total_expected_size =
539 ((p->flags & PGRS_UL_SIZE_KNOWN) ? p->ul.total_size : p->ul.cur_size) +
540 ((p->flags & PGRS_DL_SIZE_KNOWN) ? p->dl.total_size : p->dl.cur_size);
541
542 /* We have transferred this much so far */
543 total_cur_size = p->dl.cur_size + p->ul.cur_size;
544
545 /* Get the percentage of data transferred so far */
546 total_estm.percent = pgrs_est_percent(total_expected_size, total_cur_size);
547
548 fprintf(data->set.err,
549 "\r"
550 "%3" FMT_OFF_T " %s "
551 "%3" FMT_OFF_T " %s "
552 "%3" FMT_OFF_T " %s %s %s %s %s %s %s",
553 total_estm.percent, /* 3 letters */ /* total % */
554 max5data(total_expected_size, max5[2]), /* total size */
555 dl_estm.percent, /* 3 letters */ /* rcvd % */
556 max5data(p->dl.cur_size, max5[0]), /* rcvd size */
557 ul_estm.percent, /* 3 letters */ /* xfer % */
558 max5data(p->ul.cur_size, max5[1]), /* xfer size */
559 max5data(p->dl.speed, max5[3]), /* avrg dl speed */
560 max5data(p->ul.speed, max5[4]), /* avrg ul speed */
561 time_total, /* 8 letters */ /* total time */
562 time_spent, /* 8 letters */ /* time spent */
563 time_left, /* 8 letters */ /* time left */
564 max5data(p->current_speed, max5[5])
565 );
566
567 /* we flush the output stream to make it appear as soon as possible */
568 fflush(data->set.err);
569 }
570 #else
571 /* progress bar disabled */
572 #define progress_meter(x) Curl_nop_stmt
573 #endif
574
575
576 /*
577 * Curl_pgrsUpdate() returns 0 for success or the value returned by the
578 * progress callback!
579 */
pgrsupdate(struct Curl_easy * data,bool showprogress)580 static int pgrsupdate(struct Curl_easy *data, bool showprogress)
581 {
582 if(!(data->progress.flags & PGRS_HIDE)) {
583 if(data->set.fxferinfo) {
584 int result;
585 /* There is a callback set, call that */
586 Curl_set_in_callback(data, true);
587 result = data->set.fxferinfo(data->set.progress_client,
588 data->progress.dl.total_size,
589 data->progress.dl.cur_size,
590 data->progress.ul.total_size,
591 data->progress.ul.cur_size);
592 Curl_set_in_callback(data, false);
593 if(result != CURL_PROGRESSFUNC_CONTINUE) {
594 if(result)
595 failf(data, "Callback aborted");
596 return result;
597 }
598 }
599 else if(data->set.fprogress) {
600 int result;
601 /* The older deprecated callback is set, call that */
602 Curl_set_in_callback(data, true);
603 result = data->set.fprogress(data->set.progress_client,
604 (double)data->progress.dl.total_size,
605 (double)data->progress.dl.cur_size,
606 (double)data->progress.ul.total_size,
607 (double)data->progress.ul.cur_size);
608 Curl_set_in_callback(data, false);
609 if(result != CURL_PROGRESSFUNC_CONTINUE) {
610 if(result)
611 failf(data, "Callback aborted");
612 return result;
613 }
614 }
615
616 if(showprogress)
617 progress_meter(data);
618 }
619
620 return 0;
621 }
622
Curl_pgrsUpdate(struct Curl_easy * data)623 int Curl_pgrsUpdate(struct Curl_easy *data)
624 {
625 struct curltime now = Curl_now(); /* what time is it */
626 bool showprogress = progress_calc(data, now);
627 return pgrsupdate(data, showprogress);
628 }
629
630 /*
631 * Update all progress, do not do progress meter/callbacks.
632 */
Curl_pgrsUpdate_nometer(struct Curl_easy * data)633 void Curl_pgrsUpdate_nometer(struct Curl_easy *data)
634 {
635 struct curltime now = Curl_now(); /* what time is it */
636 (void)progress_calc(data, now);
637 }
638