X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Fretr.c;h=e619f1cbb74b9ef5b1d50131d8d4ad957c5a6684;hb=9228f0bf53d3b42459daeb28372196a007de3014;hp=aeef3da3e4b9cf267244542d4cba4932438d788e;hpb=9f2cc079246d21f98bb7b73f1bdce9be6606c8c0;p=wget diff --git a/src/retr.c b/src/retr.c index aeef3da3..e619f1cb 100644 --- a/src/retr.c +++ b/src/retr.c @@ -5,8 +5,8 @@ This file is part of GNU Wget. GNU Wget is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. GNU Wget is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -15,7 +15,17 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Wget; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +In addition, as a special exception, the Free Software Foundation +gives permission to link the code of its release of Wget with the +OpenSSL project's "OpenSSL" library (or with modified versions of it +that use the same license as the "OpenSSL" library), and distribute +the linked executables. You must obey the GNU General Public License +in all respects for all of the code used other than "OpenSSL". If you +modify this file, you may extend this exception to your version of the +file, but you are not obligated to do so. If you do not wish to do +so, delete this exception statement from your version. */ #include @@ -58,7 +68,7 @@ int global_download_count; static struct { long bytes; - long dltime; + double dltime; } limit_data; static void @@ -74,26 +84,26 @@ limit_bandwidth_reset (void) TIMER the timer, and ADJUSTMENT the previous. */ static void -limit_bandwidth (long bytes, long delta) +limit_bandwidth (long bytes, double delta) { - long expected; + double expected; limit_data.bytes += bytes; limit_data.dltime += delta; - expected = (long)(1000.0 * limit_data.bytes / opt.limit_rate); + expected = 1000.0 * limit_data.bytes / opt.limit_rate; if (expected > limit_data.dltime) { - long slp = expected - limit_data.dltime; + double slp = expected - limit_data.dltime; if (slp < 200) { - DEBUGP (("deferring a %ld ms sleep (%ld/%ld) until later.\n", + DEBUGP (("deferring a %.2f ms sleep (%ld/%.2f).\n", slp, limit_data.bytes, limit_data.dltime)); return; } - DEBUGP (("sleeping %ld ms\n", slp)); - usleep (1000 * slp); + DEBUGP (("sleeping %.2f ms\n", slp)); + usleep ((unsigned long) (1000 * slp)); } limit_data.bytes = 0; @@ -125,13 +135,13 @@ limit_bandwidth (long bytes, long delta) from fd immediately, flush or discard the buffer. */ int get_contents (int fd, FILE *fp, long *len, long restval, long expected, - struct rbuf *rbuf, int use_expected, long *elapsed) + struct rbuf *rbuf, int use_expected, double *elapsed) { int res = 0; - static char c[8192]; + static char c[16384]; void *progress = NULL; struct wget_timer *timer = wtimer_allocate (); - long dltime = 0, last_dltime = 0; + double dltime = 0, last_dltime = 0; *len = restval; @@ -226,7 +236,7 @@ get_contents (int fd, FILE *fp, long *len, long restval, long expected, appropriate for the speed. If PAD is non-zero, strings will be padded to the width of 7 characters (xxxx.xx). */ char * -retr_rate (long bytes, long msecs, int pad) +retr_rate (long bytes, double msecs, int pad) { static char res[20]; static char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" }; @@ -246,7 +256,7 @@ retr_rate (long bytes, long msecs, int pad) UNITS is zero for B/s, one for KB/s, two for MB/s, and three for GB/s. */ double -calc_rate (long bytes, long msecs, int *units) +calc_rate (long bytes, double msecs, int *units) { double dlrate; @@ -254,9 +264,9 @@ calc_rate (long bytes, long msecs, int *units) assert (bytes >= 0); if (msecs == 0) - /* If elapsed time is 0, it means we're under the granularity of - the timer. This often happens on systems that use time() for - the timer. */ + /* If elapsed time is exactly zero, it means we're under the + granularity of the timer. This often happens on systems that + use time() for the timer. */ msecs = wtimer_granularity (); dlrate = (double)1000 * bytes / msecs;