progress.c 21 KB

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