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
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 <config.h>
\f
static struct {
long bytes;
- long dltime;
+ double dltime;
} limit_data;
static 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;
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;
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" };
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;
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;
int redirection_count = 0;
int post_data_suspended = 0;
- char *saved_post_data;
- char *saved_post_file_name;
+ char *saved_post_data = NULL;
+ char *saved_post_file_name = NULL;
/* If dt is NULL, just ignore it. */
if (!dt)