+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>
* rbuf.h: Implement only a single version of RBUF_READCHAR, using
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;
{
/* 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.waitretry)
- sleep(count);
- else
- sleep(opt.waitretry);
- }
- else
- sleep (opt.wait);
- }
- if (first_retrieval)
- first_retrieval = 0;
+ sleep_between_retrievals (count);
if (con->st & ON_YOUR_OWN)
{
con->cmd = 0;
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;
{
/* 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.waitretry)
- sleep(count);
- else
- sleep(opt.waitretry);
- }
- else
- sleep (opt.wait);
- }
- if (first_retrieval)
- first_retrieval = 0;
+ sleep_between_retrievals (count);
/* Get the current time string. */
tms = time_str (NULL);
/* Print fetch message, if opt.verbose. */
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;
+}
void downloaded_increase PARAMS ((unsigned long));
int downloaded_exceeds_quota PARAMS ((void));
+void sleep_between_retrievals PARAMS ((int));
+
#endif /* RETR_H */