]> sjero.net Git - wget/commitdiff
[svn] Cosmetic fixes.
authorhniksic <devnull@localhost>
Sat, 20 Sep 2003 21:08:41 +0000 (14:08 -0700)
committerhniksic <devnull@localhost>
Sat, 20 Sep 2003 21:08:41 +0000 (14:08 -0700)
src/ChangeLog
src/retr.c

index 80e9a0c0521286102e5cd46d38eb6f454a1f99ea..7f64e35f7d5df9c77952e5e7142ca993e1455a4a 100644 (file)
@@ -1,3 +1,7 @@
+2003-09-20  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * retr.c (get_contents): Cosmetic fixes.
+
 2003-09-20  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * url.c (uri_merge): Get rid of uri_merge_1.
index 8f1f4394682993bd87e8cd539c0d604968318a0a..24b0782bfb57445300dffcd0d31d99404d5d2155 100644 (file)
@@ -79,9 +79,8 @@ limit_bandwidth_reset (void)
 }
 
 /* Limit the bandwidth by pausing the download for an amount of time.
-   BYTES is the number of bytes received from the network, DELTA is
-   how long it took to receive them, DLTIME the current download time,
-   TIMER the timer, and ADJUSTMENT the previous.  */
+   BYTES is the number of bytes received from the network, and DELTA
+   is how long it took to receive them.  */
 
 static void
 limit_bandwidth (long bytes, double delta)
@@ -196,35 +195,34 @@ get_contents (int fd, FILE *fp, long *len, long restval, long expected,
 #endif /* HAVE_SSL */
        res = iread (fd, dlbuf, amount_to_read);
 
-      if (res > 0)
+      if (res <= 0)
+       break;
+
+      fwrite (dlbuf, 1, res, fp);
+      /* Always flush the contents of the network packet.  This should
+        not hinder performance: fast downloads will be received in
+        16K chunks (which stdio would write out anyway), and slow
+        downloads won't be limited with disk performance.  */
+      fflush (fp);
+      if (ferror (fp))
        {
-         fwrite (dlbuf, 1, res, fp);
-         /* Always flush the contents of the network packet.  This
-            should not be adverse to performance, as the network
-            packets typically won't be too tiny anyway.  */
-         fflush (fp);
-         if (ferror (fp))
-           {
-             res = -2;
-             goto out;
-           }
-
-         /* If bandwidth is not limited, one call to wtimer_elapsed
-            is sufficient.  */
+         res = -2;
+         goto out;
+       }
+
+      /* If bandwidth is not limited, one call to wtimer_elapsed is
+        sufficient.  */
+      dltime = wtimer_elapsed (timer);
+      if (opt.limit_rate)
+       {
+         limit_bandwidth (res, dltime - last_dltime);
          dltime = wtimer_elapsed (timer);
-         if (opt.limit_rate)
-           {
-             limit_bandwidth (res, dltime - last_dltime);
-             dltime = wtimer_elapsed (timer);
-             last_dltime = dltime;
-           }
-
-         if (progress)
-           progress_update (progress, res, dltime);
-         *len += res;
+         last_dltime = dltime;
        }
-      else
-       break;
+
+      if (progress)
+       progress_update (progress, res, dltime);
+      *len += res;
     }
   if (res < -1)
     res = -1;
@@ -284,8 +282,7 @@ calc_rate (long bytes, double msecs, int *units)
   else if (dlrate < 1024.0 * 1024.0 * 1024.0)
     *units = 2, dlrate /= (1024.0 * 1024.0);
   else
-    /* Maybe someone will need this one day.  More realistically, it
-       will get tickled by buggy timers. */
+    /* Maybe someone will need this, one day. */
     *units = 3, dlrate /= (1024.0 * 1024.0 * 1024.0);
 
   return dlrate;