X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Fprogress.c;h=be841590abee1379139f7cd13e69918cbc68876f;hb=4d7c5e087b2bc82c9f503dff003916d1047903ce;hp=f25ca6b606d366864be64f0f7df1ce3ba38ded7e;hpb=3d5863424bd4a4354311c449e9d318057996d16e;p=wget diff --git a/src/progress.c b/src/progress.c index f25ca6b6..be841590 100644 --- a/src/progress.c +++ b/src/progress.c @@ -1,11 +1,11 @@ /* Download progress. - Copyright (C) 2001-2005 Free Software Foundation, Inc. + Copyright (C) 2001-2006 Free Software Foundation, Inc. This file is part of GNU Wget. GNU Wget is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or +the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GNU Wget is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Wget; if not, write to the Free Software Foundation, Inc., -51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +along with Wget. If not, see . In addition, as a special exception, the Free Software Foundation gives permission to link the code of its release of Wget with the @@ -320,8 +319,10 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last) wgint bytes_remaining = dp->total_length - bytes_displayed; /* The quantity downloaded in this download run. */ wgint bytes_sofar = bytes_displayed - dp->initial_length; - int eta = (int) (dltime * bytes_remaining / bytes_sofar + 0.5); - logprintf (LOG_VERBOSE, " %s", eta_to_human_short (eta, true)); + double eta = dltime * bytes_remaining / bytes_sofar; + if (eta < INT_MAX - 1) + logprintf (LOG_VERBOSE, " %s", + eta_to_human_short ((int) (eta + 0.5), true)); } } else @@ -483,6 +484,14 @@ static volatile sig_atomic_t received_sigwinch; download speeds are scratched. */ #define STALL_START_TIME 5 +/* Time between screen refreshes will not be shorter than this, so + that Wget doesn't swamp the TTY with output. */ +#define REFRESH_INTERVAL 0.2 + +/* Don't refresh the ETA too often to avoid jerkiness in predictions. + This allows ETA to change approximately once per second. */ +#define ETA_REFRESH_INTERVAL 0.99 + struct bar_progress { wgint initial_length; /* how many bytes have been downloaded previously. */ @@ -616,7 +625,7 @@ bar_update (void *progress, wgint howmuch, double dltime) received_sigwinch = 0; } - if (dltime - bp->last_screen_update < 0.2 && !force_screen_update) + if (dltime - bp->last_screen_update < REFRESH_INTERVAL && !force_screen_update) /* Don't update more often than five times per second. */ return; @@ -913,7 +922,7 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) any value to the user. */ if (bp->total_length != size && bp->last_eta_value != 0 - && dl_total_time - bp->last_eta_time < 0.9) + && dl_total_time - bp->last_eta_time < ETA_REFRESH_INTERVAL) eta = bp->last_eta_value; else { @@ -924,7 +933,10 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) I found that doing that results in a very jerky and ultimately unreliable ETA. */ wgint bytes_remaining = bp->total_length - size; - eta = (int) (dl_total_time * bytes_remaining / bp->count + 0.5); + double eta_ = dl_total_time * bytes_remaining / bp->count; + if (eta_ >= INT_MAX - 1) + goto skip_eta; + eta = (int) (eta_ + 0.5); bp->last_eta_value = eta; bp->last_eta_time = dl_total_time; } @@ -936,6 +948,7 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done) } else if (bp->total_length > 0) { + skip_eta: APPEND_LITERAL (" "); } } @@ -1051,7 +1064,7 @@ eta_to_human_short (int secs, bool condensed) sprintf (buf, "%ds", secs); else if (secs < 100 * 60) sprintf (buf, "%dm%s%ds", secs / 60, space, secs % 60); - else if (secs < 100 * 3600) + else if (secs < 48 * 3600) sprintf (buf, "%dh%s%dm", secs / 3600, space, (secs / 60) % 60); else if (secs < 100 * 86400) sprintf (buf, "%dd%s%dh", secs / 86400, space, (secs / 3600) % 60);