Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * _ _ ____ _ |
| 3 | * Project ___| | | | _ \| | |
| 4 | * / __| | | | |_) | | |
| 5 | * | (__| |_| | _ <| |___ |
| 6 | * \___|\___/|_| \_\_____| |
| 7 | * |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 8 | * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 12 | * are also available at https://curl.haxx.se/docs/copyright.html. |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 23 | #include "curl_setup.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 24 | |
| 25 | #include "urldata.h" |
| 26 | #include "sendf.h" |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 27 | #include "multiif.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 28 | #include "progress.h" |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 29 | #include "curl_printf.h" |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 30 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 31 | /* check rate limits within this many recent milliseconds, at minimum. */ |
| 32 | #define MIN_RATE_LIMIT_PERIOD 3000 |
| 33 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 34 | /* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero |
| 35 | byte) */ |
| 36 | static void time2str(char *r, curl_off_t seconds) |
| 37 | { |
| 38 | curl_off_t d, h, m, s; |
| 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 | m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60); |
| 46 | s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60)); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 47 | snprintf(r, 9, "%2" CURL_FORMAT_CURL_OFF_T ":%02" CURL_FORMAT_CURL_OFF_T |
| 48 | ":%02" CURL_FORMAT_CURL_OFF_T, h, m, s); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 | 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)) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 56 | snprintf(r, 9, "%3" CURL_FORMAT_CURL_OFF_T |
| 57 | "d %02" CURL_FORMAT_CURL_OFF_T "h", d, h); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 58 | else |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 59 | snprintf(r, 9, "%7" CURL_FORMAT_CURL_OFF_T "d", d); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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... */ |
| 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)) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 75 | snprintf(max5, 6, "%5" CURL_FORMAT_CURL_OFF_T, bytes); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 76 | |
| 77 | else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 78 | snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "k", bytes/ONE_KILOBYTE); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 82 | snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0" |
| 83 | CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 90 | snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 91 | |
| 92 | else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE) |
| 93 | /* 10000 MB - 100 GB, we show it as XX.XG */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 94 | snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0" |
| 95 | CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 100 | snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 101 | |
| 102 | else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE) |
| 103 | /* up to 10000TB, display without decimal: XXXXT */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 104 | snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "T", bytes/ONE_TERABYTE); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 105 | |
| 106 | else |
| 107 | /* up to 10000PB, display without decimal: XXXXP */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 108 | snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "P", bytes/ONE_PETABYTE); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 116 | snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 137 | int Curl_pgrsDone(struct connectdata *conn) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 138 | { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 139 | int rc; |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 140 | struct Curl_easy *data = conn->data; |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 141 | data->progress.lastshow = 0; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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"); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 151 | |
| 152 | data->progress.speeder_c = 0; /* reset the progress meter display */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 153 | return 0; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 156 | /* reset the known transfer sizes */ |
| 157 | void Curl_pgrsResetTransferSizes(struct Curl_easy *data) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 158 | { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 159 | Curl_pgrsSetDownloadSize(data, -1); |
| 160 | Curl_pgrsSetUploadSize(data, -1); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 163 | /* |
| 164 | * @unittest: 1399 |
| 165 | */ |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 166 | void Curl_pgrsTime(struct Curl_easy *data, timerid timer) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 167 | { |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 168 | struct curltime now = Curl_now(); |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 169 | time_t *delta = NULL; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 170 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 171 | switch(timer) { |
| 172 | default: |
| 173 | case TIMER_NONE: |
| 174 | /* mistake filter */ |
| 175 | break; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 176 | case TIMER_STARTOP: |
| 177 | /* This is set at the start of a transfer */ |
| 178 | data->progress.t_startop = now; |
| 179 | break; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 180 | case TIMER_STARTSINGLE: |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 181 | /* This is set at the start of each single fetch */ |
| 182 | data->progress.t_startsingle = now; |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 183 | data->progress.is_t_startransfer_set = false; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 184 | break; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 185 | case TIMER_STARTACCEPT: |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 186 | data->progress.t_acceptdata = now; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 187 | break; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 188 | case TIMER_NAMELOOKUP: |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 189 | delta = &data->progress.t_nslookup; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 190 | break; |
| 191 | case TIMER_CONNECT: |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 192 | delta = &data->progress.t_connect; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 193 | break; |
| 194 | case TIMER_APPCONNECT: |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 195 | delta = &data->progress.t_appconnect; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 196 | break; |
| 197 | case TIMER_PRETRANSFER: |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 198 | delta = &data->progress.t_pretransfer; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 199 | break; |
| 200 | case TIMER_STARTTRANSFER: |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 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 | */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 208 | if(data->progress.is_t_startransfer_set) { |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 209 | return; |
| 210 | } |
| 211 | else { |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 212 | data->progress.is_t_startransfer_set = true; |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 213 | break; |
| 214 | } |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 215 | case TIMER_POSTRANSFER: |
| 216 | /* this is the normal end-of-transfer thing */ |
| 217 | break; |
| 218 | case TIMER_REDIRECT: |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 219 | data->progress.t_redirect = Curl_timediff_us(now, data->progress.start); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 220 | break; |
| 221 | } |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 222 | if(delta) { |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 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; |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 227 | } |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 230 | void Curl_pgrsStartNow(struct Curl_easy *data) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 231 | { |
| 232 | data->progress.speeder_c = 0; /* reset the progress meter display */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 233 | data->progress.start = Curl_now(); |
| 234 | data->progress.is_t_startransfer_set = false; |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 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; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 239 | /* clear all bits except HIDE and HEADERS_OUT */ |
| 240 | data->progress.flags &= PGRS_HIDE|PGRS_HEADERS_OUT; |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 241 | Curl_ratelimit(data, data->progress.start); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 242 | } |
| 243 | |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 244 | /* |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 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. |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 247 | * |
| 248 | * The way it works is by having a "starting point" (time & amount of data |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 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). |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 253 | * |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 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. |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 257 | * |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 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. |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 261 | */ |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 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) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 267 | { |
| 268 | curl_off_t size = cursize - startsize; |
| 269 | time_t minimum; |
| 270 | time_t actual; |
| 271 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 272 | if(!limit || !size) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 273 | return 0; |
| 274 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 275 | /* |
| 276 | * 'minimum' is the number of milliseconds 'size' should take to download to |
| 277 | * stay below 'limit'. |
| 278 | */ |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 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 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 289 | /* |
| 290 | * 'actual' is the time in milliseconds it took to actually download the |
| 291 | * last 'size' bytes. |
| 292 | */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 293 | actual = Curl_timediff(now, start); |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 294 | if(actual < minimum) { |
| 295 | /* if it downloaded the data faster than the limit, make it wait the |
| 296 | difference */ |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 297 | return (minimum - actual); |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 298 | } |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 299 | |
| 300 | return 0; |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 303 | /* |
| 304 | * Set the number of downloaded bytes so far. |
| 305 | */ |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 306 | void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 307 | { |
| 308 | data->progress.downloaded = size; |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 309 | } |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 310 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 311 | /* |
| 312 | * Update the timestamp and sizestamp to use for rate limit calculations. |
| 313 | */ |
| 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 | } |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 330 | } |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 333 | /* |
| 334 | * Set the number of uploaded bytes so far. |
| 335 | */ |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 336 | void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 337 | { |
| 338 | data->progress.uploaded = size; |
| 339 | } |
| 340 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 341 | void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 342 | { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 343 | if(size >= 0) { |
| 344 | data->progress.size_dl = size; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 345 | data->progress.flags |= PGRS_DL_SIZE_KNOWN; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 346 | } |
| 347 | else { |
| 348 | data->progress.size_dl = 0; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 349 | data->progress.flags &= ~PGRS_DL_SIZE_KNOWN; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 350 | } |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 353 | void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size) |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 354 | { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 355 | if(size >= 0) { |
| 356 | data->progress.size_ul = size; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 357 | data->progress.flags |= PGRS_UL_SIZE_KNOWN; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 358 | } |
| 359 | else { |
| 360 | data->progress.size_ul = 0; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 361 | data->progress.flags &= ~PGRS_UL_SIZE_KNOWN; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 362 | } |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 363 | } |
| 364 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 365 | /* |
| 366 | * Curl_pgrsUpdate() returns 0 for success or the value returned by the |
| 367 | * progress callback! |
| 368 | */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 369 | int Curl_pgrsUpdate(struct connectdata *conn) |
| 370 | { |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 371 | struct curltime now; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 372 | int result; |
| 373 | char max5[6][10]; |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 374 | curl_off_t dlpercen = 0; |
| 375 | curl_off_t ulpercen = 0; |
| 376 | curl_off_t total_percen = 0; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 377 | curl_off_t total_transfer; |
| 378 | curl_off_t total_expected_transfer; |
| 379 | curl_off_t timespent; |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 380 | curl_off_t timespent_ms; /* milliseconds */ |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 381 | struct Curl_easy *data = conn->data; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 382 | int nowindex = data->progress.speeder_c% CURR_TIME; |
| 383 | int checkindex; |
| 384 | int countindex; /* amount of seconds stored in the speeder array */ |
| 385 | char time_left[10]; |
| 386 | char time_total[10]; |
| 387 | char time_spent[10]; |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 388 | curl_off_t ulestimate = 0; |
| 389 | curl_off_t dlestimate = 0; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 390 | curl_off_t total_estimate; |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 391 | bool shownow = FALSE; |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 392 | curl_off_t dl = data->progress.downloaded; |
| 393 | curl_off_t ul = data->progress.uploaded; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 394 | |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 395 | now = Curl_now(); /* what time is it */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 396 | |
| 397 | /* The time spent so far (from the start) */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 398 | data->progress.timespent = Curl_timediff_us(now, data->progress.start); |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 399 | timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */ |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 400 | timespent_ms = (curl_off_t)data->progress.timespent/1000; /* ms */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 401 | |
| 402 | /* The average download speed this far */ |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 403 | if(dl < CURL_OFF_T_MAX/1000) |
| 404 | data->progress.dlspeed = (dl * 1000 / (timespent_ms>0?timespent_ms:1)); |
| 405 | else |
| 406 | data->progress.dlspeed = (dl / (timespent>0?timespent:1)); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 407 | |
| 408 | /* The average upload speed this far */ |
Elliott Hughes | 0128fe4 | 2018-02-27 14:57:55 -0800 | [diff] [blame] | 409 | if(ul < CURL_OFF_T_MAX/1000) |
| 410 | data->progress.ulspeed = (ul * 1000 / (timespent_ms>0?timespent_ms:1)); |
| 411 | else |
| 412 | data->progress.ulspeed = (ul / (timespent>0?timespent:1)); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 413 | |
| 414 | /* Calculations done at most once a second, unless end is reached */ |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 415 | if(data->progress.lastshow != now.tv_sec) { |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 416 | shownow = TRUE; |
| 417 | |
| 418 | data->progress.lastshow = now.tv_sec; |
| 419 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 420 | /* Let's do the "current speed" thing, with the dl + ul speeds |
| 421 | combined. Store the speed at entry 'nowindex'. */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 422 | data->progress.speeder[ nowindex ] = |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 423 | data->progress.downloaded + data->progress.uploaded; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 424 | |
| 425 | /* remember the exact time for this moment */ |
| 426 | data->progress.speeder_time [ nowindex ] = now; |
| 427 | |
| 428 | /* advance our speeder_c counter, which is increased every time we get |
| 429 | here and we expect it to never wrap as 2^32 is a lot of seconds! */ |
| 430 | data->progress.speeder_c++; |
| 431 | |
| 432 | /* figure out how many index entries of data we have stored in our speeder |
| 433 | array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of |
| 434 | transfer. Imagine, after one second we have filled in two entries, |
| 435 | after two seconds we've filled in three entries etc. */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 436 | countindex = ((data->progress.speeder_c >= CURR_TIME)? |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 437 | CURR_TIME:data->progress.speeder_c) - 1; |
| 438 | |
| 439 | /* first of all, we don't do this if there's no counted seconds yet */ |
| 440 | if(countindex) { |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 441 | timediff_t span_ms; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 442 | |
| 443 | /* Get the index position to compare with the 'nowindex' position. |
| 444 | Get the oldest entry possible. While we have less than CURR_TIME |
| 445 | entries, the first entry will remain the oldest. */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 446 | checkindex = (data->progress.speeder_c >= CURR_TIME)? |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 447 | data->progress.speeder_c%CURR_TIME:0; |
| 448 | |
| 449 | /* Figure out the exact time for the time span */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 450 | span_ms = Curl_timediff(now, |
| 451 | data->progress.speeder_time[checkindex]); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 452 | if(0 == span_ms) |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 453 | span_ms = 1; /* at least one millisecond MUST have passed */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 454 | |
| 455 | /* Calculate the average speed the last 'span_ms' milliseconds */ |
| 456 | { |
| 457 | curl_off_t amount = data->progress.speeder[nowindex]- |
| 458 | data->progress.speeder[checkindex]; |
| 459 | |
| 460 | if(amount > CURL_OFF_T_C(4294967) /* 0xffffffff/1000 */) |
| 461 | /* the 'amount' value is bigger than would fit in 32 bits if |
| 462 | multiplied with 1000, so we use the double math for this */ |
| 463 | data->progress.current_speed = (curl_off_t) |
| 464 | ((double)amount/((double)span_ms/1000.0)); |
| 465 | else |
| 466 | /* the 'amount' value is small enough to fit within 32 bits even |
| 467 | when multiplied with 1000 */ |
| 468 | data->progress.current_speed = amount*CURL_OFF_T_C(1000)/span_ms; |
| 469 | } |
| 470 | } |
| 471 | else |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 472 | /* the first second we use the average */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 473 | data->progress.current_speed = |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 474 | data->progress.ulspeed + data->progress.dlspeed; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 475 | |
| 476 | } /* Calculations end */ |
| 477 | |
| 478 | if(!(data->progress.flags & PGRS_HIDE)) { |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 479 | /* progress meter has not been shut off */ |
| 480 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 481 | if(data->set.fxferinfo) { |
| 482 | /* There's a callback set, call that */ |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 483 | Curl_set_in_callback(data, true); |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 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); |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 489 | Curl_set_in_callback(data, false); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 490 | if(result) |
| 491 | failf(data, "Callback aborted"); |
| 492 | return result; |
| 493 | } |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 494 | if(data->set.fprogress) { |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 495 | /* The older deprecated callback is set, call that */ |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 496 | Curl_set_in_callback(data, true); |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 497 | result = data->set.fprogress(data->set.progress_client, |
| 498 | (double)data->progress.size_dl, |
| 499 | (double)data->progress.downloaded, |
| 500 | (double)data->progress.size_ul, |
| 501 | (double)data->progress.uploaded); |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 502 | Curl_set_in_callback(data, false); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 503 | if(result) |
| 504 | failf(data, "Callback aborted"); |
| 505 | return result; |
| 506 | } |
| 507 | |
| 508 | if(!shownow) |
| 509 | /* only show the internal progress meter once per second */ |
| 510 | return 0; |
| 511 | |
| 512 | /* If there's no external callback set, use internal code to show |
| 513 | progress */ |
| 514 | |
| 515 | if(!(data->progress.flags & PGRS_HEADERS_OUT)) { |
| 516 | if(data->state.resume_from) { |
| 517 | fprintf(data->set.err, |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 518 | "** Resuming transfer from byte position %" |
| 519 | CURL_FORMAT_CURL_OFF_T "\n", data->state.resume_from); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 520 | } |
| 521 | fprintf(data->set.err, |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 522 | " %% Total %% Received %% Xferd Average Speed " |
| 523 | "Time Time Time Current\n" |
| 524 | " Dload Upload " |
| 525 | "Total Spent Left Speed\n"); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 526 | data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ |
| 527 | } |
| 528 | |
| 529 | /* Figure out the estimated time of arrival for the upload */ |
| 530 | if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && |
| 531 | (data->progress.ulspeed > CURL_OFF_T_C(0))) { |
| 532 | ulestimate = data->progress.size_ul / data->progress.ulspeed; |
| 533 | |
| 534 | if(data->progress.size_ul > CURL_OFF_T_C(10000)) |
| 535 | ulpercen = data->progress.uploaded / |
| 536 | (data->progress.size_ul/CURL_OFF_T_C(100)); |
| 537 | else if(data->progress.size_ul > CURL_OFF_T_C(0)) |
| 538 | ulpercen = (data->progress.uploaded*100) / |
| 539 | data->progress.size_ul; |
| 540 | } |
| 541 | |
| 542 | /* ... and the download */ |
| 543 | if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && |
| 544 | (data->progress.dlspeed > CURL_OFF_T_C(0))) { |
| 545 | dlestimate = data->progress.size_dl / data->progress.dlspeed; |
| 546 | |
| 547 | if(data->progress.size_dl > CURL_OFF_T_C(10000)) |
| 548 | dlpercen = data->progress.downloaded / |
| 549 | (data->progress.size_dl/CURL_OFF_T_C(100)); |
| 550 | else if(data->progress.size_dl > CURL_OFF_T_C(0)) |
| 551 | dlpercen = (data->progress.downloaded*100) / |
| 552 | data->progress.size_dl; |
| 553 | } |
| 554 | |
| 555 | /* Now figure out which of them is slower and use that one for the |
| 556 | total estimate! */ |
| 557 | total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; |
| 558 | |
| 559 | /* create the three time strings */ |
| 560 | time2str(time_left, total_estimate > 0?(total_estimate - timespent):0); |
| 561 | time2str(time_total, total_estimate); |
| 562 | time2str(time_spent, timespent); |
| 563 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 564 | /* Get the total amount of data expected to get transferred */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 565 | total_expected_transfer = |
| 566 | (data->progress.flags & PGRS_UL_SIZE_KNOWN? |
| 567 | data->progress.size_ul:data->progress.uploaded)+ |
| 568 | (data->progress.flags & PGRS_DL_SIZE_KNOWN? |
| 569 | data->progress.size_dl:data->progress.downloaded); |
| 570 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 571 | /* We have transferred this much so far */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 572 | total_transfer = data->progress.downloaded + data->progress.uploaded; |
| 573 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 574 | /* Get the percentage of data transferred so far */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 575 | if(total_expected_transfer > CURL_OFF_T_C(10000)) |
| 576 | total_percen = total_transfer / |
| 577 | (total_expected_transfer/CURL_OFF_T_C(100)); |
| 578 | else if(total_expected_transfer > CURL_OFF_T_C(0)) |
| 579 | total_percen = (total_transfer*100) / total_expected_transfer; |
| 580 | |
| 581 | fprintf(data->set.err, |
| 582 | "\r" |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 583 | "%3" CURL_FORMAT_CURL_OFF_T " %s " |
| 584 | "%3" CURL_FORMAT_CURL_OFF_T " %s " |
| 585 | "%3" CURL_FORMAT_CURL_OFF_T " %s %s %s %s %s %s %s", |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 586 | total_percen, /* 3 letters */ /* total % */ |
| 587 | max5data(total_expected_transfer, max5[2]), /* total size */ |
| 588 | dlpercen, /* 3 letters */ /* rcvd % */ |
| 589 | max5data(data->progress.downloaded, max5[0]), /* rcvd size */ |
| 590 | ulpercen, /* 3 letters */ /* xfer % */ |
| 591 | max5data(data->progress.uploaded, max5[1]), /* xfer size */ |
| 592 | max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ |
| 593 | max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ |
| 594 | time_total, /* 8 letters */ /* total time */ |
| 595 | time_spent, /* 8 letters */ /* time spent */ |
| 596 | time_left, /* 8 letters */ /* time left */ |
| 597 | max5data(data->progress.current_speed, max5[5]) /* current speed */ |
| 598 | ); |
| 599 | |
| 600 | /* we flush the output stream to make it appear as soon as possible */ |
| 601 | fflush(data->set.err); |
| 602 | |
| 603 | } /* !(data->progress.flags & PGRS_HIDE) */ |
| 604 | |
| 605 | return 0; |
| 606 | } |