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