]> sjero.net Git - wget/commitdiff
[svn] Fix opt.wait.
authorhniksic <devnull@localhost>
Wed, 6 Dec 2000 00:24:40 +0000 (16:24 -0800)
committerhniksic <devnull@localhost>
Wed, 6 Dec 2000 00:24:40 +0000 (16:24 -0800)
src/ChangeLog
src/ftp.c
src/http.c
src/retr.c
src/retr.h

index 1255ab38d2a58ada52aac10cb8ca24170024ff62..d63ea7c33ecb9fab01807b38ad45b471beb664b7 100644 (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>
 
        * rbuf.h: Implement only a single version of RBUF_READCHAR, using
index 8ce71fd66b89bdf340d882ce118afc4abbba6d68..a3fc3d333eaa115429027d14c07ce29e5ddfcded 100644 (file)
--- 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 (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;
index 0c4ca9a7e2d12714e09cb87ab032dbf3e233ddd7..e3411874370e4d4bebb2ff5a89edfd3996996c87 100644 (file)
@@ -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.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.  */
index ffc2ecac33753492a907df55a68bced49c13f226..a334cea506e2f415c1a5ec26025cb1158778c746 100644 (file)
@@ -634,3 +634,34 @@ downloaded_exceeds_quota (void)
 
   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;
+}
index 9866f2465157fe1778fe84113a174d1878b59981..90c4b7b2f462afcb26bf071cc97f028527e61769 100644 (file)
@@ -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 */