1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Fix opt.wait.

This commit is contained in:
hniksic 2000-12-05 16:24:40 -08:00
parent 03d11ff1bb
commit b0e9dfd4e2
5 changed files with 44 additions and 38 deletions

View File

@ -1,3 +1,12 @@
2000-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
* ftp.c (ftp_loop_internal): Ditto.
* http.c (http_loop): Use it.
* retr.c (sleep_between_retrievals): New function that handles the
logic of opt.wait and opt.waitretry.
2000-12-06 Hrvoje Niksic <hniksic@arsdigita.com> 2000-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
* rbuf.h: Implement only a single version of RBUF_READCHAR, using * rbuf.h: Implement only a single version of RBUF_READCHAR, using

View File

@ -948,8 +948,6 @@ Error in server response, closing control connection.\n"));
static uerr_t static uerr_t
ftp_loop_internal (struct urlinfo *u, struct fileinfo *f, ccon *con) ftp_loop_internal (struct urlinfo *u, struct fileinfo *f, ccon *con)
{ {
static int first_retrieval = 1;
int count, orig_lp; int count, orig_lp;
long restval, len; long restval, len;
char *tms, *tmrate, *locf; char *tms, *tmrate, *locf;
@ -986,23 +984,7 @@ ftp_loop_internal (struct urlinfo *u, struct fileinfo *f, ccon *con)
{ {
/* Increment the pass counter. */ /* Increment the pass counter. */
++count; ++count;
/* Wait before the retrieval (unless this is the very first sleep_between_retrievals (count);
retrieval).
Check if we are retrying or not, wait accordingly - HEH */
if (!first_retrieval && (opt.wait || (count && opt.waitretry)))
{
if (count)
{
if (count<opt.waitretry)
sleep(count);
else
sleep(opt.waitretry);
}
else
sleep (opt.wait);
}
if (first_retrieval)
first_retrieval = 0;
if (con->st & ON_YOUR_OWN) if (con->st & ON_YOUR_OWN)
{ {
con->cmd = 0; con->cmd = 0;

View File

@ -1234,8 +1234,6 @@ Accept: %s\r\n\
uerr_t uerr_t
http_loop (struct urlinfo *u, char **newloc, int *dt) http_loop (struct urlinfo *u, char **newloc, int *dt)
{ {
static int first_retrieval = 1;
int count; int count;
int use_ts, got_head = 0; /* time-stamping info */ int use_ts, got_head = 0; /* time-stamping info */
char *filename_plus_orig_suffix; char *filename_plus_orig_suffix;
@ -1348,23 +1346,7 @@ File `%s' already there, will not retrieve.\n"), u->local);
{ {
/* Increment the pass counter. */ /* Increment the pass counter. */
++count; ++count;
/* Wait before the retrieval (unless this is the very first sleep_between_retrievals (count);
retrieval).
Check if we are retrying or not, wait accordingly - HEH */
if (!first_retrieval && (opt.wait || (count && opt.waitretry)))
{
if (count)
{
if (count<opt.waitretry)
sleep(count);
else
sleep(opt.waitretry);
}
else
sleep (opt.wait);
}
if (first_retrieval)
first_retrieval = 0;
/* Get the current time string. */ /* Get the current time string. */
tms = time_str (NULL); tms = time_str (NULL);
/* Print fetch message, if opt.verbose. */ /* Print fetch message, if opt.verbose. */

View File

@ -634,3 +634,34 @@ downloaded_exceeds_quota (void)
return opt.downloaded > opt.quota; return opt.downloaded > opt.quota;
} }
/* If opt.wait or opt.waitretry are specified, and if certain
conditions are met, sleep the appropriate number of seconds. See
the documentation of --wait and --waitretry for more information.
COUNT is the count of current retrieval, beginning with 1. */
void
sleep_between_retrievals (int count)
{
static int first_retrieval = 1;
if (!first_retrieval && (opt.wait || opt.waitretry))
{
if (opt.waitretry && count > 1)
{
/* If opt.waitretry is specified and this is a retry, wait
for COUNT-1 number of seconds, or for opt.waitretry
seconds. */
if (count <= opt.waitretry)
sleep (count - 1);
else
sleep (opt.waitretry);
}
else if (opt.wait)
/* Otherwise, check if opt.wait is specified. If so, sleep. */
sleep (opt.wait);
}
if (first_retrieval)
first_retrieval = 0;
}

View File

@ -37,4 +37,6 @@ void printwhat PARAMS ((int, int));
void downloaded_increase PARAMS ((unsigned long)); void downloaded_increase PARAMS ((unsigned long));
int downloaded_exceeds_quota PARAMS ((void)); int downloaded_exceeds_quota PARAMS ((void));
void sleep_between_retrievals PARAMS ((int));
#endif /* RETR_H */ #endif /* RETR_H */