]> sjero.net Git - wget/blobdiff - src/retr.c
[svn] Various IPv6 fixes.
[wget] / src / retr.c
index 1f54cf0b0cbeed27b0e89779a66771b200bd08b8..dabb407e971257a69acb48d0351667655145a67a 100644 (file)
@@ -511,11 +511,11 @@ retrieve_url (const char *origurl, char **file, char **newloc,
     {
       if (*dt & RETROKF)
        {
-         register_download (url, local_file);
+         register_download (u->url, local_file);
          if (redirections)
-           register_all_redirections (redirections, url);
+           register_all_redirections (redirections, u->url);
          if (*dt & TEXTHTML)
-           register_html (url, local_file);
+           register_html (u->url, local_file);
        }
     }
 
@@ -653,42 +653,41 @@ sleep_between_retrievals (int count)
 {
   static int first_retrieval = 1;
 
-  if (first_retrieval && opt.random_wait)
-    /* --random-wait uses the RNG, so seed it. */
-    srand (time (NULL));
+  if (first_retrieval)
+    {
+      /* Don't sleep before the very first retrieval. */
+      first_retrieval = 0;
+      return;
+    }
 
-  if (!first_retrieval && (opt.wait || opt.waitretry))
+  if (opt.waitretry && count > 1)
     {
-      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)
+      /* 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)
+    {
+      if (!opt.random_wait || count > 1)
+       /* If random-wait is not specified, or if we are sleeping
+          between retries of the same download, sleep the fixed
+          interval.  */
+       sleep (opt.wait);
+      else
        {
-         /* Otherwise, check if opt.wait is specified.  If so, sleep.  */
-         if (count > 1 || !opt.random_wait)
-           sleep (opt.wait);
-         else
-           {
-             int waitmax = 2 * opt.wait;
-             /* This is equivalent to rand() % waitmax, but uses the
-                high-order bits for better randomness.  */
-             int waitsecs = (double)waitmax * rand () / (RAND_MAX + 1.0);
+         /* Sleep a random amount of time averaging in opt.wait
+            seconds.  The sleeping amount ranges from 0 to
+            opt.wait*2, inclusive.  */
+         int waitsecs = random_number (opt.wait * 2 + 1);
 
-             DEBUGP (("sleep_between_retrievals: norm=%ld,fuzz=%ld,sleep=%d\n",
-                      opt.wait, waitsecs - opt.wait, waitsecs));
+         DEBUGP (("sleep_between_retrievals: norm=%ld,fuzz=%ld,sleep=%d\n",
+                  opt.wait, waitsecs - opt.wait, waitsecs));
 
-             if (waitsecs)
-               sleep (waitsecs);
-           }
+         if (waitsecs)
+           sleep (waitsecs);
        }
     }
-  if (first_retrieval)
-    first_retrieval = 0;
 }