From b0e9dfd4e282817ead1a2c1030d8be2941d3e734 Mon Sep 17 00:00:00 2001 From: hniksic Date: Tue, 5 Dec 2000 16:24:40 -0800 Subject: [PATCH] [svn] Fix opt.wait. --- src/ChangeLog | 9 +++++++++ src/ftp.c | 20 +------------------- src/http.c | 20 +------------------- src/retr.c | 31 +++++++++++++++++++++++++++++++ src/retr.h | 2 ++ 5 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1255ab38..d63ea7c3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2000-12-06 Hrvoje Niksic + + * 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 * rbuf.h: Implement only a single version of RBUF_READCHAR, using diff --git a/src/ftp.c b/src/ftp.c index 8ce71fd6..a3fc3d33 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -948,8 +948,6 @@ Error in server response, closing control connection.\n")); static uerr_t ftp_loop_internal (struct urlinfo *u, struct fileinfo *f, ccon *con) { - static int first_retrieval = 1; - int count, orig_lp; long restval, len; char *tms, *tmrate, *locf; @@ -986,23 +984,7 @@ ftp_loop_internal (struct urlinfo *u, struct fileinfo *f, ccon *con) { /* Increment the pass counter. */ ++count; - /* Wait before the retrieval (unless this is the very first - retrieval). - Check if we are retrying or not, wait accordingly - HEH */ - if (!first_retrieval && (opt.wait || (count && opt.waitretry))) - { - if (count) - { - if (countst & ON_YOUR_OWN) { con->cmd = 0; diff --git a/src/http.c b/src/http.c index 0c4ca9a7..e3411874 100644 --- a/src/http.c +++ b/src/http.c @@ -1234,8 +1234,6 @@ Accept: %s\r\n\ uerr_t http_loop (struct urlinfo *u, char **newloc, int *dt) { - static int first_retrieval = 1; - int count; int use_ts, got_head = 0; /* time-stamping info */ char *filename_plus_orig_suffix; @@ -1348,23 +1346,7 @@ File `%s' already there, will not retrieve.\n"), u->local); { /* Increment the pass counter. */ ++count; - /* Wait before the retrieval (unless this is the very first - retrieval). - Check if we are retrying or not, wait accordingly - HEH */ - if (!first_retrieval && (opt.wait || (count && opt.waitretry))) - { - if (count) - { - if (count 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; +} diff --git a/src/retr.h b/src/retr.h index 9866f246..90c4b7b2 100644 --- a/src/retr.h +++ b/src/retr.h @@ -37,4 +37,6 @@ void printwhat PARAMS ((int, int)); void downloaded_increase PARAMS ((unsigned long)); int downloaded_exceeds_quota PARAMS ((void)); +void sleep_between_retrievals PARAMS ((int)); + #endif /* RETR_H */