From e7998ad916f5a0a0f5db79a9fe1ce555c4709c90 Mon Sep 17 00:00:00 2001 From: hniksic Date: Sat, 20 Sep 2003 14:08:41 -0700 Subject: [PATCH] [svn] Cosmetic fixes. --- src/ChangeLog | 4 ++++ src/retr.c | 63 ++++++++++++++++++++++++--------------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 80e9a0c0..7f64e35f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2003-09-20 Hrvoje Niksic + + * retr.c (get_contents): Cosmetic fixes. + 2003-09-20 Hrvoje Niksic * url.c (uri_merge): Get rid of uri_merge_1. diff --git a/src/retr.c b/src/retr.c index 8f1f4394..24b0782b 100644 --- a/src/retr.c +++ b/src/retr.c @@ -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) - { - 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. */ - 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; - } - else + 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)) + { + 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); + last_dltime = dltime; + } + + 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;