mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Allow decimal values for --timeout, --wait, and --waitretry.
Message-ID: <m3llsjhx6t.fsf@hniksic.iskon.hr>
This commit is contained in:
parent
e7998ad916
commit
7870937036
@ -1,3 +1,20 @@
|
|||||||
|
2003-09-21 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
|
* connect.c (select_fd): Change MAXTIME's type to double. Handle
|
||||||
|
its decimal part.
|
||||||
|
|
||||||
|
* retr.c (sleep_between_retrievals): In the random-wait case, use
|
||||||
|
random_float() to wait between 0 and 2*opt.wait seconds.
|
||||||
|
|
||||||
|
* utils.c (run_with_timeout): Accept `double' timeouts. Correctly
|
||||||
|
handle timeout values in (0, 1) range.
|
||||||
|
(random_float): New function.
|
||||||
|
|
||||||
|
* options.h (struct options): Change the types of wait, waitretry,
|
||||||
|
and timeout to double.
|
||||||
|
|
||||||
|
* init.c (cmd_time): Accept floating point time.
|
||||||
|
|
||||||
2003-09-20 Hrvoje Niksic <hniksic@xemacs.org>
|
2003-09-20 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
* retr.c (get_contents): Cosmetic fixes.
|
* retr.c (get_contents): Cosmetic fixes.
|
||||||
|
@ -355,7 +355,7 @@ bindport (unsigned short *port, int family)
|
|||||||
Returns 1 if FD is available, 0 for timeout and -1 for error. */
|
Returns 1 if FD is available, 0 for timeout and -1 for error. */
|
||||||
|
|
||||||
int
|
int
|
||||||
select_fd (int fd, int maxtime, int writep)
|
select_fd (int fd, double maxtime, int writep)
|
||||||
{
|
{
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
fd_set *rd = NULL, *wrt = NULL;
|
fd_set *rd = NULL, *wrt = NULL;
|
||||||
@ -366,8 +366,8 @@ select_fd (int fd, int maxtime, int writep)
|
|||||||
FD_SET (fd, &fds);
|
FD_SET (fd, &fds);
|
||||||
*(writep ? &wrt : &rd) = &fds;
|
*(writep ? &wrt : &rd) = &fds;
|
||||||
|
|
||||||
tmout.tv_sec = maxtime;
|
tmout.tv_sec = (long)maxtime;
|
||||||
tmout.tv_usec = 0;
|
tmout.tv_usec = 1000000L * (maxtime - (long)maxtime);
|
||||||
|
|
||||||
do
|
do
|
||||||
result = select (fd + 1, rd, wrt, NULL, &tmout);
|
result = select (fd + 1, rd, wrt, NULL, &tmout);
|
||||||
|
@ -39,7 +39,7 @@ int connect_to_many PARAMS ((struct address_list *, unsigned short, int));
|
|||||||
void set_connection_host_name PARAMS ((const char *));
|
void set_connection_host_name PARAMS ((const char *));
|
||||||
|
|
||||||
int test_socket_open PARAMS ((int));
|
int test_socket_open PARAMS ((int));
|
||||||
int select_fd PARAMS ((int, int, int));
|
int select_fd PARAMS ((int, double, int));
|
||||||
uerr_t bindport PARAMS ((unsigned short *, int));
|
uerr_t bindport PARAMS ((unsigned short *, int));
|
||||||
uerr_t acceptport PARAMS ((int *));
|
uerr_t acceptport PARAMS ((int *));
|
||||||
void closeport PARAMS ((int));
|
void closeport PARAMS ((int));
|
||||||
|
@ -494,7 +494,7 @@ gethostbyname_with_timeout_callback (void *arg)
|
|||||||
other than timeout, errno is reset. */
|
other than timeout, errno is reset. */
|
||||||
|
|
||||||
static struct hostent *
|
static struct hostent *
|
||||||
gethostbyname_with_timeout (const char *host_name, int timeout)
|
gethostbyname_with_timeout (const char *host_name, double timeout)
|
||||||
{
|
{
|
||||||
struct ghbnwt_context ctx;
|
struct ghbnwt_context ctx;
|
||||||
ctx.host_name = host_name;
|
ctx.host_name = host_name;
|
||||||
@ -533,7 +533,7 @@ getaddrinfo_with_timeout_callback (void *arg)
|
|||||||
static int
|
static int
|
||||||
getaddrinfo_with_timeout (const char *node, const char *service,
|
getaddrinfo_with_timeout (const char *node, const char *service,
|
||||||
const struct addrinfo *hints, struct addrinfo **res,
|
const struct addrinfo *hints, struct addrinfo **res,
|
||||||
int timeout)
|
double timeout)
|
||||||
{
|
{
|
||||||
struct gaiwt_context ctx;
|
struct gaiwt_context ctx;
|
||||||
ctx.node = node;
|
ctx.node = node;
|
||||||
@ -670,7 +670,8 @@ lookup_host (const char *host, int silent)
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
struct hostent *hptr = gethostbyname_with_timeout (host, opt.timeout);
|
struct hostent *hptr;
|
||||||
|
hptr = gethostbyname_with_timeout (host, opt.timeout);
|
||||||
if (!hptr)
|
if (!hptr)
|
||||||
{
|
{
|
||||||
if (!silent)
|
if (!silent)
|
||||||
|
90
src/init.c
90
src/init.c
@ -856,51 +856,89 @@ cmd_bytes (const char *com, const char *val, void *closure)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store the value of VAL to *OUT, allowing suffixes for minutes and
|
/* Store the value of VAL to *OUT. The value is a time period, by
|
||||||
hours. */
|
default expressed in seconds. */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cmd_time (const char *com, const char *val, void *closure)
|
cmd_time (const char *com, const char *val, void *closure)
|
||||||
{
|
{
|
||||||
long result = 0;
|
double result, mult, divider;
|
||||||
const char *p = val;
|
int seen_dot, seen_digit;
|
||||||
|
|
||||||
/* Search for digits and construct result. */
|
const char *p;
|
||||||
for (; *p && ISDIGIT (*p); p++)
|
const char *end = val + strlen (val);
|
||||||
result = (10 * result) + (*p - '0');
|
|
||||||
/* If no digits were found, or more than one character is following
|
/* Skip trailing whitespace. */
|
||||||
them, bail out. */
|
while (end > val && ISSPACE (end[-1]))
|
||||||
if (p == val || (*p != '\0' && *(p + 1) != '\0'))
|
--end;
|
||||||
|
|
||||||
|
if (val == end)
|
||||||
{
|
{
|
||||||
printf (_("%s: Invalid specification `%s'\n"), com, val);
|
err:
|
||||||
|
fprintf (stderr, _("%s: Invalid time specification `%s'\n"), com, val);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Search for a suffix. */
|
|
||||||
switch (TOLOWER (*p))
|
switch (TOLOWER (end[-1]))
|
||||||
{
|
{
|
||||||
case '\0':
|
case 's':
|
||||||
/* None */
|
--end, mult = 1; /* seconds */
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
/* Minutes */
|
--end, mult = 60; /* minutes */
|
||||||
result *= 60;
|
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
/* Seconds */
|
--end, mult = 3600; /* hours */
|
||||||
result *= 3600;
|
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
/* Days (overflow on 16bit machines) */
|
--end, mult = 86400; /* days */
|
||||||
result *= 86400L;
|
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
/* Weeks :-) */
|
--end, mult = 604800; /* weeks */
|
||||||
result *= 604800L;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf (_("%s: Invalid specification `%s'\n"), com, val);
|
/* Not a recognized suffix: treat it as part of number, and
|
||||||
return 0;
|
assume seconds. */
|
||||||
|
mult = 1;
|
||||||
}
|
}
|
||||||
*(long *)closure = result;
|
|
||||||
|
/* Skip leading and trailing whitespace. */
|
||||||
|
while (val < end && ISSPACE (*val))
|
||||||
|
++val;
|
||||||
|
while (val > end && ISSPACE (end[-1]))
|
||||||
|
--end;
|
||||||
|
if (val == end)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Poor man's strtod: */
|
||||||
|
result = 0;
|
||||||
|
seen_dot = seen_digit = 0;
|
||||||
|
divider = 1;
|
||||||
|
|
||||||
|
p = val;
|
||||||
|
while (p < end)
|
||||||
|
{
|
||||||
|
char ch = *p++;
|
||||||
|
if (ISDIGIT (ch))
|
||||||
|
{
|
||||||
|
if (!seen_dot)
|
||||||
|
result = (10 * result) + (ch - '0');
|
||||||
|
else
|
||||||
|
result += (ch - '0') / (divider *= 10);
|
||||||
|
seen_digit = 1;
|
||||||
|
}
|
||||||
|
else if (ch == '.')
|
||||||
|
{
|
||||||
|
if (!seen_dot)
|
||||||
|
seen_dot = 1;
|
||||||
|
else
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!seen_digit)
|
||||||
|
goto err;
|
||||||
|
result *= mult;
|
||||||
|
*(double *)closure = result;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ sleep (unsigned seconds)
|
|||||||
/* Emulation of Unix usleep(). This has a granularity of
|
/* Emulation of Unix usleep(). This has a granularity of
|
||||||
milliseconds, but that's ok because:
|
milliseconds, but that's ok because:
|
||||||
|
|
||||||
a) Wget is only using it with milliseconds;
|
a) Wget is only using it with milliseconds [not anymore, but b)
|
||||||
|
still applies];
|
||||||
|
|
||||||
b) You can't rely on usleep's granularity anyway. If a caller
|
b) You can't rely on usleep's granularity anyway. If a caller
|
||||||
expects usleep to respect every microsecond, he's in for a
|
expects usleep to respect every microsecond, he's in for a
|
||||||
|
@ -133,5 +133,6 @@ void ws_changetitle (char*, int);
|
|||||||
char *ws_mypath (void);
|
char *ws_mypath (void);
|
||||||
void ws_help (const char *);
|
void ws_help (const char *);
|
||||||
void windows_main_junk (int *, char **, char **);
|
void windows_main_junk (int *, char **, char **);
|
||||||
|
int usleep (unsigned long);
|
||||||
|
|
||||||
#endif /* MSWINDOWS_H */
|
#endif /* MSWINDOWS_H */
|
||||||
|
@ -108,12 +108,11 @@ struct options
|
|||||||
char *proxy_user; /*oli*/
|
char *proxy_user; /*oli*/
|
||||||
char *proxy_passwd;
|
char *proxy_passwd;
|
||||||
#ifdef HAVE_SELECT
|
#ifdef HAVE_SELECT
|
||||||
long timeout; /* The value of read timeout in
|
double timeout; /* The read/connect/DNS timeout. */
|
||||||
seconds. */
|
|
||||||
#endif
|
#endif
|
||||||
int random_wait; /* vary from 0 .. wait secs by random()? */
|
int random_wait; /* vary from 0 .. wait secs by random()? */
|
||||||
long wait; /* The wait period between retrievals. */
|
double wait; /* The wait period between retrievals. */
|
||||||
long waitretry; /* The wait period between retries. - HEH */
|
double waitretry; /* The wait period between retries. - HEH */
|
||||||
int use_robots; /* Do we heed robots.txt? */
|
int use_robots; /* Do we heed robots.txt? */
|
||||||
|
|
||||||
long limit_rate; /* Limit the download rate to this
|
long limit_rate; /* Limit the download rate to this
|
||||||
|
17
src/retr.c
17
src/retr.c
@ -80,7 +80,7 @@ limit_bandwidth_reset (void)
|
|||||||
|
|
||||||
/* Limit the bandwidth by pausing the download for an amount of time.
|
/* Limit the bandwidth by pausing the download for an amount of time.
|
||||||
BYTES is the number of bytes received from the network, and DELTA
|
BYTES is the number of bytes received from the network, and DELTA
|
||||||
is how long it took to receive them. */
|
is the number of milliseconds it took to receive them. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
limit_bandwidth (long bytes, double delta)
|
limit_bandwidth (long bytes, double delta)
|
||||||
@ -648,7 +648,7 @@ sleep_between_retrievals (int count)
|
|||||||
if (count <= opt.waitretry)
|
if (count <= opt.waitretry)
|
||||||
sleep (count - 1);
|
sleep (count - 1);
|
||||||
else
|
else
|
||||||
sleep (opt.waitretry);
|
usleep (1000000L * opt.waitretry);
|
||||||
}
|
}
|
||||||
else if (opt.wait)
|
else if (opt.wait)
|
||||||
{
|
{
|
||||||
@ -656,19 +656,16 @@ sleep_between_retrievals (int count)
|
|||||||
/* If random-wait is not specified, or if we are sleeping
|
/* If random-wait is not specified, or if we are sleeping
|
||||||
between retries of the same download, sleep the fixed
|
between retries of the same download, sleep the fixed
|
||||||
interval. */
|
interval. */
|
||||||
sleep (opt.wait);
|
usleep (1000000L * opt.wait);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Sleep a random amount of time averaging in opt.wait
|
/* Sleep a random amount of time averaging in opt.wait
|
||||||
seconds. The sleeping amount ranges from 0 to
|
seconds. The sleeping amount ranges from 0 to
|
||||||
opt.wait*2, inclusive. */
|
opt.wait*2, inclusive. */
|
||||||
int waitsecs = random_number (opt.wait * 2 + 1);
|
double waitsecs = 2 * opt.wait * random_float ();
|
||||||
|
DEBUGP (("sleep_between_retrievals: avg=%f,sleep=%f\n",
|
||||||
DEBUGP (("sleep_between_retrievals: norm=%ld,fuzz=%ld,sleep=%d\n",
|
opt.wait, waitsecs));
|
||||||
opt.wait, waitsecs - opt.wait, waitsecs));
|
usleep (1000000L * waitsecs);
|
||||||
|
|
||||||
if (waitsecs)
|
|
||||||
sleep (waitsecs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,8 @@ do { \
|
|||||||
# define VERY_LONG_TYPE unsigned long long
|
# define VERY_LONG_TYPE unsigned long long
|
||||||
#endif /* use long long */
|
#endif /* use long long */
|
||||||
|
|
||||||
/* Defined in cmpt.c: */
|
/* These are defined in cmpt.c if missing, therefore it's generally
|
||||||
|
safe to declare their parameters. */
|
||||||
#ifndef HAVE_STRERROR
|
#ifndef HAVE_STRERROR
|
||||||
char *strerror ();
|
char *strerror ();
|
||||||
#endif
|
#endif
|
||||||
@ -174,7 +175,7 @@ char *strptime ();
|
|||||||
int vsnprintf ();
|
int vsnprintf ();
|
||||||
#endif
|
#endif
|
||||||
#ifndef HAVE_USLEEP
|
#ifndef HAVE_USLEEP
|
||||||
int usleep ();
|
int usleep PARAMS ((unsigned long));
|
||||||
#endif
|
#endif
|
||||||
#ifndef HAVE_MEMMOVE
|
#ifndef HAVE_MEMMOVE
|
||||||
void *memmove ();
|
void *memmove ();
|
||||||
|
28
src/utils.c
28
src/utils.c
@ -1879,6 +1879,22 @@ random_number (int max)
|
|||||||
return (int)bounded;
|
return (int)bounded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return a random uniformly distributed floating point number in the
|
||||||
|
[0, 1) range. The precision of returned numbers is 9 digits.
|
||||||
|
|
||||||
|
Modify this to use erand48() where available! */
|
||||||
|
|
||||||
|
double
|
||||||
|
random_float (void)
|
||||||
|
{
|
||||||
|
/* We can't rely on any specific value of RAND_MAX, but I'm pretty
|
||||||
|
sure it's greater than 1000. */
|
||||||
|
int rnd1 = random_number (1000);
|
||||||
|
int rnd2 = random_number (1000);
|
||||||
|
int rnd3 = random_number (1000);
|
||||||
|
return rnd1 / 1000.0 + rnd2 / 1000000.0 + rnd3 / 1000000000.0;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* A debugging function for checking whether an MD5 library works. */
|
/* A debugging function for checking whether an MD5 library works. */
|
||||||
|
|
||||||
@ -1950,7 +1966,7 @@ abort_run_with_timeout (int sig)
|
|||||||
#endif /* USE_SIGNAL_TIMEOUT */
|
#endif /* USE_SIGNAL_TIMEOUT */
|
||||||
|
|
||||||
int
|
int
|
||||||
run_with_timeout (long timeout, void (*fun) (void *), void *arg)
|
run_with_timeout (double timeout, void (*fun) (void *), void *arg)
|
||||||
{
|
{
|
||||||
#ifndef USE_SIGNAL_TIMEOUT
|
#ifndef USE_SIGNAL_TIMEOUT
|
||||||
fun (arg);
|
fun (arg);
|
||||||
@ -1964,6 +1980,13 @@ run_with_timeout (long timeout, void (*fun) (void *), void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Calling alarm() rounds TIMEOUT. If it is smaller than 1, round
|
||||||
|
it to 1, not to 0, because alarm(0) means "never deliver the
|
||||||
|
alarm", i.e. "wait forever", which is not what someone who
|
||||||
|
specifies a 0.5s timeout would expect. */
|
||||||
|
if (timeout < 1)
|
||||||
|
timeout = 1;
|
||||||
|
|
||||||
signal (SIGALRM, abort_run_with_timeout);
|
signal (SIGALRM, abort_run_with_timeout);
|
||||||
if (SETJMP (run_with_timeout_env) != 0)
|
if (SETJMP (run_with_timeout_env) != 0)
|
||||||
{
|
{
|
||||||
@ -1971,7 +1994,7 @@ run_with_timeout (long timeout, void (*fun) (void *), void *arg)
|
|||||||
signal (SIGALRM, SIG_DFL);
|
signal (SIGALRM, SIG_DFL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
alarm (timeout);
|
alarm ((int) timeout);
|
||||||
fun (arg);
|
fun (arg);
|
||||||
|
|
||||||
/* Preserve errno in case alarm() or signal() modifies it. */
|
/* Preserve errno in case alarm() or signal() modifies it. */
|
||||||
@ -1983,4 +2006,3 @@ run_with_timeout (long timeout, void (*fun) (void *), void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,8 @@ char *html_quote_string PARAMS ((const char *));
|
|||||||
|
|
||||||
int determine_screen_width PARAMS ((void));
|
int determine_screen_width PARAMS ((void));
|
||||||
int random_number PARAMS ((int));
|
int random_number PARAMS ((int));
|
||||||
|
double random_float PARAMS ((void));
|
||||||
|
|
||||||
int run_with_timeout PARAMS ((long, void (*) (void *), void *));
|
int run_with_timeout PARAMS ((double, void (*) (void *), void *));
|
||||||
|
|
||||||
#endif /* UTILS_H */
|
#endif /* UTILS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user