+ total += sz;
+ if (!quiet) {
+ static unsigned long last;
+ struct timeval tv;
+ unsigned long diff = total - last;
+ /* not really "msecs", but a power-of-two millisec (1/1024th of a sec) */
+ unsigned long msecs;
+
+ gettimeofday(&tv, NULL);
+ msecs = tv.tv_sec - prev_tv.tv_sec;
+ msecs <<= 10;
+ msecs += usec_to_binarymsec(tv.tv_usec - prev_tv.tv_usec);
+
+ if (msecs > 500) {
+ prev_tv = tv;
+ last = total;
+
+ /* Update averages ..*/
+ avg_bytes += diff;
+ avg_time += msecs;
+ avg_bytes -= download[idx].bytes;
+ avg_time -= download[idx].time;
+ download[idx].bytes = diff;
+ download[idx].time = msecs;
+ idx++;
+ if (idx >= NR_AVERAGE)
+ idx = 0;
+
+ fprintf(stderr, "%4lu.%03luMB (%lu kB/s) \r",
+ total >> 20,
+ 1000*((total >> 10) & 1023)>>10,
+ avg_bytes / avg_time );
+ }
+ }