From ae1912cb0d494b48d514d937826c9fe83ec96c4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Dec 1999 14:20:26 +0000 Subject: Initial revision --- lib/progress.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 lib/progress.c (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c new file mode 100644 index 000000000..6a083370b --- /dev/null +++ b/lib/progress.c @@ -0,0 +1,221 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Curl. + * + * The Initial Developer of the Original Code is Daniel Stenberg. + * + * Portions created by the Initial Developer are Copyright (C) 1998. + * All Rights Reserved. + * + * ------------------------------------------------------------ + * Main author: + * - Daniel Stenberg + * + * http://curl.haxx.nu + * + * $Source$ + * $Revision$ + * $Date$ + * $Author$ + * $State$ + * $Locker$ + * + * ------------------------------------------------------------ + ****************************************************************************/ + +#include +#include "setup.h" + +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +#if defined(__MINGW32__) +#include +#endif +#include +#endif + +#include +#include "urldata.h" + +#include "progress.h" + +/* --- start of progress routines --- */ +int progressmax=-1; + +static int prev = 0; +static int width = 0; + +void ProgressInit(struct UrlData *data, int max) +{ + if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) + return; + + prev = 0; + +/* TODO: get terminal width through ansi escapes or something similar. + try to update width when xterm is resized... - 19990617 larsa */ + if (curl_GetEnv("COLUMNS") != NULL) + width = atoi(curl_GetEnv("COLUMNS")); + else + width = 80; + + progressmax = max; + if(-1 == max) + return; + if(progressmax <= LEAST_SIZE_PROGRESS) { + progressmax = -1; /* disable */ + return; + } + + if ( data->progressmode == CURL_PROGRESS_STATS ) + fprintf(data->err, + " %% Received Total Speed Time left Total Curr.Speed\n"); +} + +void time2str(char *r, int t) +{ + int h = (t/3600); + int m = (t-(h*3600))/60; + int s = (t-(h*3600)-(m*60)); + sprintf(r,"%3d:%02d:%02d",h,m,s); +} + +void ProgressShow(struct UrlData *data, + int point, struct timeval start, struct timeval now, bool force) +{ + switch ( data->progressmode ) { + case CURL_PROGRESS_STATS: + { + static long lastshow; + double percen; + + double spent; + double speed; + +#define CURR_TIME 5 + + static int speeder[ CURR_TIME ]; + static int speeder_c=0; + + int nowindex = speeder_c% CURR_TIME; + int checkindex; + int count; + + if(!force && (point != progressmax) && (lastshow == tvlong(now))) + return; /* never update this more than once a second if the end isn't + reached */ + + spent = tvdiff (now, start); + speed = point/(spent!=0.0?spent:1.0); + if(!speed) + speed=1; + + /* point is where we are right now */ + speeder[ nowindex ] = point; + speeder_c++; /* increase */ + count = ((speeder_c>=CURR_TIME)?CURR_TIME:speeder_c) - 1; + checkindex = (speeder_c>=CURR_TIME)?speeder_c%CURR_TIME:0; + + /* find out the average speed the last CURR_TIME seconds */ + data->current_speed = (speeder[nowindex]-speeder[checkindex])/(count?count:1); + +#if 0 + printf("NOW %d(%d) THEN %d(%d) DIFF %lf COUNT %d\n", + speeder[nowindex], nowindex, + speeder[checkindex], checkindex, + data->current_speed, count); +#endif + + if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) + return; + + if(-1 != progressmax) { + char left[20],estim[20]; + int estimate = progressmax/(int) speed; + + time2str(left,estimate-(int) spent); + time2str(estim,estimate); + + percen=(double)point/progressmax; + percen=percen*100; + + fprintf(data->err, "\r%3d %8d %8d %6.0lf %s %s %6.0lf ", + (int)percen, point, progressmax, + speed, left, estim, data->current_speed); + } + else + fprintf(data->err, + "\r%d bytes received in %.3lf seconds (%.0lf bytes/sec)", + point, spent, speed); + + lastshow = now.tv_sec; + break; + } + case CURL_PROGRESS_BAR: /* 19990617 larsa */ + { + if (point == prev) break; + if (progressmax == -1) { + int prevblock = prev / 1024; + int thisblock = point / 1024; + while ( thisblock > prevblock ) { + fprintf( data->err, "#" ); + prevblock++; + } + prev = point; + } else { + char line[256]; + char outline[256]; + char format[40]; + float frac = (float) point / (float) progressmax; + float percent = frac * 100.0f; + int barwidth = width - 7; + int num = (int) (((float)barwidth) * frac); + int i = 0; + for ( i = 0; i < num; i++ ) { + line[i] = '#'; + } + line[i] = '\0'; + sprintf( format, "%%-%ds %%5.1f%%%%", barwidth ); + sprintf( outline, format, line, percent ); + fprintf( data->err, "\r%s", outline ); + } + prev = point; + break; + } + default: /* 19990617 larsa */ + { + int prevblock = prev / 1024; + int thisblock = point / 1024; + if (prev == point) break; + while ( thisblock > prevblock ) { + fprintf( data->err, "#" ); + prevblock++; + } + prev = point; + break; + } + } +} + +void ProgressEnd(struct UrlData *data) +{ + if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) + return; + fputs("\n", data->err); +} + +/* --- end of progress routines --- */ -- cgit v1.2.1 From 7c8bb5dfff48e47bd102d2b57b1e5eb1f332d903 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 16 Jan 2000 18:52:53 +0000 Subject: =?UTF-8?q?Made=20the=20progress=20bar=20cooler,=20with=20ideas=20?= =?UTF-8?q?from=20Bj=F6rn=20Stenberg=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/progress.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 6a083370b..2e3f6e975 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -83,7 +83,8 @@ void ProgressInit(struct UrlData *data, int max) if ( data->progressmode == CURL_PROGRESS_STATS ) fprintf(data->err, - " %% Received Total Speed Time left Total Curr.Speed\n"); + " %% Received Total Speed Estimated Time Left Curr.Speed\n"); + } void time2str(char *r, int t) @@ -144,18 +145,21 @@ void ProgressShow(struct UrlData *data, return; if(-1 != progressmax) { - char left[20],estim[20]; + char left[20]; + char estim[20]; + char timespent[20]; int estimate = progressmax/(int) speed; time2str(left,estimate-(int) spent); time2str(estim,estimate); + time2str(timespent,spent); percen=(double)point/progressmax; percen=percen*100; - fprintf(data->err, "\r%3d %8d %8d %6.0lf %s %s %6.0lf ", + fprintf(stderr, "\r%3d %10d %10d %6.0lf %s %s %s %6.0lf ", (int)percen, point, progressmax, - speed, left, estim, data->current_speed); + speed, estim, timespent, left, data->current_speed); } else fprintf(data->err, -- cgit v1.2.1 From ede7cf175e78d2be2c31bc469ad69d4e9073c1d1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 31 Jan 2000 22:19:17 +0000 Subject: assume 79 columns instead of 80 in case we don't know, to better work on win32 systems --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 2e3f6e975..dc1073a01 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -71,7 +71,7 @@ void ProgressInit(struct UrlData *data, int max) if (curl_GetEnv("COLUMNS") != NULL) width = atoi(curl_GetEnv("COLUMNS")); else - width = 80; + width = 79; progressmax = max; if(-1 == max) -- cgit v1.2.1 From 7413ee668f42204791c0fe9465a796286b0da460 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 14 Feb 2000 23:15:08 +0000 Subject: all new progress stuff on the way in --- lib/progress.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 251 insertions(+), 10 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index dc1073a01..a54be86d6 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -53,13 +53,261 @@ #include "progress.h" -/* --- start of progress routines --- */ +void time2str(char *r, int t) +{ + int h = (t/3600); + int m = (t-(h*3600))/60; + int s = (t-(h*3600)-(m*60)); + sprintf(r,"%d:%02d:%02d",h,m,s); +} + +/* The point of this function would be to return a string of the input data, + but never longer than 5 columns. Add suffix k, M, G when suitable... */ +char *max5data(double bytes, char *max5) +{ + if(bytes < 100000) { + sprintf(max5, "%5d", (int)bytes); + return max5; + } + if(bytes < (9999*1024)) { + sprintf(max5, "%4dk", (int)bytes/1024); + return max5; + } + sprintf(max5, "%4dM", (int)bytes/(1024*1024)); + return max5; +} + +/* + + New proposed interface, 9th of February 2000: + + pgrsStartNow() - sets start time + pgrsMode(type) - kind of display + pgrsSetDownloadSize(x) - known expected download size + pgrsSetUploadSize(x) - known expected upload size + pgrsSetDownloadCounter() - amount of data currently downloaded + pgrsSetUploadCounter() - amount of data currently uploaded + pgrsUpdate() - show progress + pgrsDone() - transfer complete + +*/ +#if 1 +void pgrsDone(struct UrlData *data) +{ + if(!(data->progress.flags & PGRS_HIDE)) + fprintf(stderr, "\n"); +} +void pgrsMode(struct UrlData *data, int mode) +{ + /* mode should include a hidden mode as well */ + if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) + data->progress.flags |= PGRS_HIDE; /* don't show anything */ + else { + data->progress.mode = mode; /* store type */ + } + +} + +void pgrsStartNow(struct UrlData *data) +{ + data->progress.start = tvnow(); +} + +void pgrsSetDownloadCounter(struct UrlData *data, double size) +{ + data->progress.downloaded = size; +} + +void pgrsSetUploadCounter(struct UrlData *data, double size) +{ + data->progress.uploaded = size; +} + +void pgrsSetDownloadSize(struct UrlData *data, double size) +{ + data->progress.size_dl = size; + data->progress.flags |= PGRS_DL_SIZE_KNOWN; +} + +void pgrsSetUploadSize(struct UrlData *data, double size) +{ + data->progress.size_ul = size; + data->progress.flags |= PGRS_UL_SIZE_KNOWN; +} + +/* EXAMPLE OUTPUT to follow: + + % Total % Received % Xferd Average Speed Time Curr. + Download Upload Total Current Left Speed +100 12345 100 12345 100 12345 12345 12345 2:47:33 2:00:02 2:00:02 12345 + + */ + +void pgrsUpdate(struct UrlData *data) +{ + struct timeval now; + + if(data->progress.flags & PGRS_HIDE) + ; /* We do enter this function even if we don't wanna see anything, since + this is were lots of the calculations are being made that will be used + even when not displayed! */ + else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { + if ( data->progress.mode == CURL_PROGRESS_STATS ) { + fprintf(data->err, + " %% Total %% Received %% Xferd Average Speed Time Curr.\n" + " Download Upload Total Current Left Speed\n"); + } + data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ + } + + now = tvnow(); /* what time is it */ + + switch(data->progress.mode) { + case CURL_PROGRESS_STATS: + { + static long lastshow; + char max5[6][6]; + double dlpercen=0; + double ulpercen=0; + double total_percen=0; + + double total_transfer; + double total_expected_transfer; + + double timespent; + double dlspeed; + double ulspeed; + +#define CURR_TIME 5 + + static double speeder[ CURR_TIME ]; + static int speeder_c=0; + + int nowindex = speeder_c% CURR_TIME; + int checkindex; + int count; + + char time_left[10]; + char time_total[10]; + char time_current[10]; + + double ulestimate=0; + double dlestimate=0; + + double total_estimate; + + if(lastshow == tvlong(now)) + return; /* never update this more than once a second if the end isn't + reached */ + lastshow = now.tv_sec; + + /* The exact time spent so far */ + timespent = tvdiff (now, data->progress.start); + + /* The average download speed this far */ + dlspeed = data->progress.downloaded/(timespent!=0.0?timespent:1.0); + + /* The average upload speed this far */ + ulspeed = data->progress.uploaded/(timespent!=0.0?timespent:1.0); + + /* Let's do the "current speed" thing, which should use the fastest + of the dl/ul speeds */ + + speeder[ nowindex ] = data->progress.downloaded>data->progress.uploaded? + data->progress.downloaded:data->progress.uploaded; + speeder_c++; /* increase */ + count = ((speeder_c>=CURR_TIME)?CURR_TIME:speeder_c) - 1; + checkindex = (speeder_c>=CURR_TIME)?speeder_c%CURR_TIME:0; + + /* find out the average speed the last CURR_TIME seconds */ + data->progress.current_speed = + (speeder[nowindex]-speeder[checkindex])/(count?count:1); + + if(data->progress.flags & PGRS_HIDE) + return; + + /* Figure out the estimated time of arrival for the upload */ + if(data->progress.flags & PGRS_UL_SIZE_KNOWN) { + if(!ulspeed) + ulspeed=1; + ulestimate = data->progress.size_ul / ulspeed; + ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; + } + + /* ... and the download */ + if(data->progress.flags & PGRS_DL_SIZE_KNOWN) { + if(!dlspeed) + dlspeed=1; + dlestimate = data->progress.size_dl / dlspeed; + dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; + } + + /* Now figure out which of them that is slower and use for the for + total estimate! */ + total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; + + /* If we have a total estimate, we can display that and the expected + time left */ + if(total_estimate) { + time2str(time_left, total_estimate-(int) timespent); + time2str(time_total, total_estimate); + } + else { + /* otherwise we blank those times */ + strcpy(time_left, "--:--:--"); + strcpy(time_total, "--:--:--"); + } + /* The time spent so far is always known */ + time2str(time_current, timespent); + + /* Get the total amount of data expected to get transfered */ + total_expected_transfer = + (data->progress.flags & PGRS_UL_SIZE_KNOWN? + data->progress.size_ul:data->progress.uploaded)+ + (data->progress.flags & PGRS_DL_SIZE_KNOWN? + data->progress.size_dl:data->progress.downloaded); + + /* We have transfered this much so far */ + total_transfer = data->progress.downloaded + data->progress.uploaded; + + /* Get the percentage of data transfered so far */ + if(total_expected_transfer) + total_percen=(double)(total_transfer/total_expected_transfer)*100; + + + fprintf(stderr, + "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", + (int)total_percen, /* total % */ + max5data(total_expected_transfer, max5[2]), /* total size */ + (int)dlpercen, /* rcvd % */ + max5data(data->progress.downloaded, max5[0]), /* rcvd size */ + (int)ulpercen, /* xfer % */ + max5data(data->progress.uploaded, max5[1]), /* xfer size */ + + max5data(dlspeed, max5[3]), /* avrg dl speed */ + max5data(ulspeed, max5[4]), /* avrg ul speed */ + time_total, /* total time */ + time_current, /* current time */ + time_left, /* time left */ + max5data(data->progress.current_speed, max5[5]) /* current speed */ + ); + } + + + } +} + + +#endif + +#if 0 +/* --- start of (the former) progress routines --- */ int progressmax=-1; static int prev = 0; static int width = 0; -void ProgressInit(struct UrlData *data, int max) +void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) { if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) return; @@ -87,14 +335,6 @@ void ProgressInit(struct UrlData *data, int max) } -void time2str(char *r, int t) -{ - int h = (t/3600); - int m = (t-(h*3600))/60; - int s = (t-(h*3600)-(m*60)); - sprintf(r,"%3d:%02d:%02d",h,m,s); -} - void ProgressShow(struct UrlData *data, int point, struct timeval start, struct timeval now, bool force) { @@ -223,3 +463,4 @@ void ProgressEnd(struct UrlData *data) } /* --- end of progress routines --- */ +#endif -- cgit v1.2.1 From b4a47dda27f175a8f33c64b935fb2fea4b47cbb3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 16 Feb 2000 00:00:27 +0000 Subject: re-arranged the progress meter columns, made the hour-field two characters wide and made the pgrsUpdate() make a final meter update so that the final values actually are displayed last. --- lib/progress.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index a54be86d6..2e2f26b4f 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -58,7 +58,7 @@ void time2str(char *r, int t) int h = (t/3600); int m = (t-(h*3600))/60; int s = (t-(h*3600)-(m*60)); - sprintf(r,"%d:%02d:%02d",h,m,s); + sprintf(r,"%2d:%02d:%02d",h,m,s); } /* The point of this function would be to return a string of the input data, @@ -94,8 +94,11 @@ char *max5data(double bytes, char *max5) #if 1 void pgrsDone(struct UrlData *data) { - if(!(data->progress.flags & PGRS_HIDE)) + if(!(data->progress.flags & PGRS_HIDE)) { + data->progress.lastshow=0; + pgrsUpdate(data); /* the final (forced) update */ fprintf(stderr, "\n"); + } } void pgrsMode(struct UrlData *data, int mode) { @@ -125,21 +128,25 @@ void pgrsSetUploadCounter(struct UrlData *data, double size) void pgrsSetDownloadSize(struct UrlData *data, double size) { - data->progress.size_dl = size; - data->progress.flags |= PGRS_DL_SIZE_KNOWN; + if(size > 0) { + data->progress.size_dl = size; + data->progress.flags |= PGRS_DL_SIZE_KNOWN; + } } void pgrsSetUploadSize(struct UrlData *data, double size) { - data->progress.size_ul = size; - data->progress.flags |= PGRS_UL_SIZE_KNOWN; + if(size > 0) { + data->progress.size_ul = size; + data->progress.flags |= PGRS_UL_SIZE_KNOWN; + } } /* EXAMPLE OUTPUT to follow: - % Total % Received % Xferd Average Speed Time Curr. - Download Upload Total Current Left Speed -100 12345 100 12345 100 12345 12345 12345 2:47:33 2:00:02 2:00:02 12345 + % Total % Received % Xferd Average Speed Time Curr. + Dload Upload Total Current Left Speed +100 12345 100 12345 100 12345 12345 12345 12:12:12 12:12:12 12:12:12 12345 */ @@ -154,8 +161,8 @@ void pgrsUpdate(struct UrlData *data) else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if ( data->progress.mode == CURL_PROGRESS_STATS ) { fprintf(data->err, - " %% Total %% Received %% Xferd Average Speed Time Curr.\n" - " Download Upload Total Current Left Speed\n"); + " %% Total %% Received %% Xferd Average Speed Time Curr.\n" + " Dload Upload Total Current Left Speed\n"); } data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ } @@ -165,7 +172,6 @@ void pgrsUpdate(struct UrlData *data) switch(data->progress.mode) { case CURL_PROGRESS_STATS: { - static long lastshow; char max5[6][6]; double dlpercen=0; double ulpercen=0; @@ -196,10 +202,10 @@ void pgrsUpdate(struct UrlData *data) double total_estimate; - if(lastshow == tvlong(now)) + if(data->progress.lastshow == tvlong(now)) return; /* never update this more than once a second if the end isn't reached */ - lastshow = now.tv_sec; + data->progress.lastshow = now.tv_sec; /* The exact time spent so far */ timespent = tvdiff (now, data->progress.start); @@ -276,7 +282,7 @@ void pgrsUpdate(struct UrlData *data) fprintf(stderr, - "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", + "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", (int)total_percen, /* total % */ max5data(total_expected_transfer, max5[2]), /* total size */ (int)dlpercen, /* rcvd % */ -- cgit v1.2.1 From 947a644d5ad0088c418b954fb3af4248c267d5dd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 21 Feb 2000 23:50:27 +0000 Subject: moved a few more variables to the progress struct and I had some problems on how to approach the -# progress bar in the new style transfers... --- lib/progress.c | 66 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 19 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 2e2f26b4f..e07667c2b 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -171,6 +171,7 @@ void pgrsUpdate(struct UrlData *data) switch(data->progress.mode) { case CURL_PROGRESS_STATS: + default: { char max5[6][6]; double dlpercen=0; @@ -180,10 +181,6 @@ void pgrsUpdate(struct UrlData *data) double total_transfer; double total_expected_transfer; - double timespent; - double dlspeed; - double ulspeed; - #define CURR_TIME 5 static double speeder[ CURR_TIME ]; @@ -208,13 +205,13 @@ void pgrsUpdate(struct UrlData *data) data->progress.lastshow = now.tv_sec; /* The exact time spent so far */ - timespent = tvdiff (now, data->progress.start); + data->progress.timespent = tvdiff (now, data->progress.start); /* The average download speed this far */ - dlspeed = data->progress.downloaded/(timespent!=0.0?timespent:1.0); + data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); /* The average upload speed this far */ - ulspeed = data->progress.uploaded/(timespent!=0.0?timespent:1.0); + data->progress.ulspeed = data->progress.uploaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); /* Let's do the "current speed" thing, which should use the fastest of the dl/ul speeds */ @@ -234,17 +231,17 @@ void pgrsUpdate(struct UrlData *data) /* Figure out the estimated time of arrival for the upload */ if(data->progress.flags & PGRS_UL_SIZE_KNOWN) { - if(!ulspeed) - ulspeed=1; - ulestimate = data->progress.size_ul / ulspeed; + if(!data->progress.ulspeed) + data->progress.ulspeed=1; + ulestimate = data->progress.size_ul / data->progress.ulspeed; ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; } /* ... and the download */ if(data->progress.flags & PGRS_DL_SIZE_KNOWN) { - if(!dlspeed) - dlspeed=1; - dlestimate = data->progress.size_dl / dlspeed; + if(!data->progress.dlspeed) + data->progress.dlspeed=1; + dlestimate = data->progress.size_dl / data->progress.dlspeed; dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; } @@ -255,7 +252,7 @@ void pgrsUpdate(struct UrlData *data) /* If we have a total estimate, we can display that and the expected time left */ if(total_estimate) { - time2str(time_left, total_estimate-(int) timespent); + time2str(time_left, total_estimate-(int) data->progress.timespent); time2str(time_total, total_estimate); } else { @@ -264,7 +261,7 @@ void pgrsUpdate(struct UrlData *data) strcpy(time_total, "--:--:--"); } /* The time spent so far is always known */ - time2str(time_current, timespent); + time2str(time_current, data->progress.timespent); /* Get the total amount of data expected to get transfered */ total_expected_transfer = @@ -290,16 +287,47 @@ void pgrsUpdate(struct UrlData *data) (int)ulpercen, /* xfer % */ max5data(data->progress.uploaded, max5[1]), /* xfer size */ - max5data(dlspeed, max5[3]), /* avrg dl speed */ - max5data(ulspeed, max5[4]), /* avrg ul speed */ + max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ + max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ time_total, /* total time */ time_current, /* current time */ time_left, /* time left */ max5data(data->progress.current_speed, max5[5]) /* current speed */ ); } - - + break; +#if 0 + case CURL_PROGRESS_BAR: + /* original progress bar code by Lars Aas */ + if (progressmax == -1) { + int prevblock = prev / 1024; + int thisblock = point / 1024; + while ( thisblock > prevblock ) { + fprintf( data->err, "#" ); + prevblock++; + } + prev = point; + } + else { + char line[256]; + char outline[256]; + char format[40]; + float frac = (float) point / (float) progressmax; + float percent = frac * 100.0f; + int barwidth = width - 7; + int num = (int) (((float)barwidth) * frac); + int i = 0; + for ( i = 0; i < num; i++ ) { + line[i] = '#'; + } + line[i] = '\0'; + sprintf( format, "%%-%ds %%5.1f%%%%", barwidth ); + sprintf( outline, format, line, percent ); + fprintf( data->err, "\r%s", outline ); + } + prev = point; + break; +#endif } } -- cgit v1.2.1 From 5fb1d20ed95faca8d076e1ffd82bec7e73f38fa3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 1 Mar 2000 21:59:59 +0000 Subject: added pgrsTime() to store various time stamps for the -w option --- lib/progress.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index e07667c2b..4307be35e 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -111,6 +111,28 @@ void pgrsMode(struct UrlData *data, int mode) } +void pgrsTime(struct UrlData *data, timerid timer) +{ + switch(timer) { + default: + case TIMER_NONE: + /* mistake filter */ + break; + case TIMER_NAMELOOKUP: + data->progress.t_nslookup = tvnow(); + break; + case TIMER_CONNECT: + data->progress.t_connect = tvnow(); + break; + case TIMER_PRETRANSFER: + data->progress.t_pretransfer = tvnow(); + break; + case TIMER_POSTRANSFER: + /* this is the normal end-of-transfer thing */ + break; + } +} + void pgrsStartNow(struct UrlData *data) { data->progress.start = tvnow(); @@ -280,15 +302,15 @@ void pgrsUpdate(struct UrlData *data) fprintf(stderr, "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", - (int)total_percen, /* total % */ - max5data(total_expected_transfer, max5[2]), /* total size */ - (int)dlpercen, /* rcvd % */ + (int)total_percen, /* total % */ + max5data(total_expected_transfer, max5[2]), /* total size */ + (int)dlpercen, /* rcvd % */ max5data(data->progress.downloaded, max5[0]), /* rcvd size */ - (int)ulpercen, /* xfer % */ - max5data(data->progress.uploaded, max5[1]), /* xfer size */ + (int)ulpercen, /* xfer % */ + max5data(data->progress.uploaded, max5[1]), /* xfer size */ - max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ - max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ + max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ + max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ time_total, /* total time */ time_current, /* current time */ time_left, /* time left */ -- cgit v1.2.1 From ff3fd842d8338feb5277a0450991c882dd4d84b2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 19 Mar 2000 19:54:13 +0000 Subject: Marco G. Salvagno's OS/2 fixes --- lib/progress.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 4307be35e..1bd5b470c 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -48,6 +48,13 @@ #include #endif +/* 20000318 mgs + * later we use _scrsize to determine the screen width, this emx library + * function needs stdlib.h to be included */ +#if defined(__EMX__) +#include +#endif + #include #include "urldata.h" @@ -365,6 +372,11 @@ static int width = 0; void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) { +#ifdef __EMX__ + /* 20000318 mgs */ + int scr_size [2]; +#endif + if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) return; @@ -372,10 +384,25 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) /* TODO: get terminal width through ansi escapes or something similar. try to update width when xterm is resized... - 19990617 larsa */ +#ifndef __EMX__ + /* 20000318 mgs + * OS/2 users most likely won't have this env var set, and besides that + * we're using our own way to determine screen width */ if (curl_GetEnv("COLUMNS") != NULL) width = atoi(curl_GetEnv("COLUMNS")); else width = 79; +#else + /* 20000318 mgs + * We use this emx library call to get the screen width, and subtract + * one from what we got in order to avoid a problem with the cursor + * advancing to the next line if we print a string that is as long as + * the screen is wide. */ + + _scrsize(scr_size); + width = scr_size[0] - 1; +#endif + progressmax = max; if(-1 == max) -- cgit v1.2.1 From eb856b04fee26345ea0c2addb19c3d97a847e931 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 8 Apr 2000 19:28:23 +0000 Subject: Improved the looks of the progress meter when the file size is between 9999 KB and 100 MB since it then can display the size as XX.X MB instead of just XX as before. --- lib/progress.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 1bd5b470c..1bb5aec0c 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -72,15 +72,23 @@ void time2str(char *r, int t) but never longer than 5 columns. Add suffix k, M, G when suitable... */ char *max5data(double bytes, char *max5) { +#define ONE_KILOBYTE 1024 +#define ONE_MEGABYTE (1024*1024) + if(bytes < 100000) { sprintf(max5, "%5d", (int)bytes); return max5; } - if(bytes < (9999*1024)) { - sprintf(max5, "%4dk", (int)bytes/1024); + if(bytes < (9999*ONE_KILOBYTE)) { + sprintf(max5, "%4dk", (int)bytes/ONE_KILOBYTE); + return max5; + } + if(bytes < (100*ONE_MEGABYTE)) { + /* 'XX.XM' is good as long as we're less than 100 megs */ + sprintf(max5, "%2.1fM", bytes/ONE_MEGABYTE); return max5; } - sprintf(max5, "%4dM", (int)bytes/(1024*1024)); + sprintf(max5, "%4dM", (int)bytes/ONE_MEGABYTE); return max5; } -- cgit v1.2.1 From 96dde76b99897352aa3d0877a0b621a9e605733e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 May 2000 14:12:12 +0000 Subject: moved here from the newlib branch --- lib/progress.c | 231 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 117 insertions(+), 114 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 1bb5aec0c..35847fab4 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -118,7 +118,7 @@ void pgrsDone(struct UrlData *data) void pgrsMode(struct UrlData *data, int mode) { /* mode should include a hidden mode as well */ - if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) + if(data->bits.hide_progress || data->bits.mute) data->progress.flags |= PGRS_HIDE; /* don't show anything */ else { data->progress.mode = mode; /* store type */ @@ -187,10 +187,36 @@ void pgrsSetUploadSize(struct UrlData *data, double size) */ -void pgrsUpdate(struct UrlData *data) +int pgrsUpdate(struct UrlData *data) { struct timeval now; + char max5[6][6]; + double dlpercen=0; + double ulpercen=0; + double total_percen=0; + + double total_transfer; + double total_expected_transfer; + +#define CURR_TIME 5 + + static double speeder[ CURR_TIME ]; + static int speeder_c=0; + + int nowindex = speeder_c% CURR_TIME; + int checkindex; + int count; + + char time_left[10]; + char time_total[10]; + char time_current[10]; + + double ulestimate=0; + double dlestimate=0; + + double total_estimate; + if(data->progress.flags & PGRS_HIDE) ; /* We do enter this function even if we don't wanna see anything, since this is were lots of the calculations are being made that will be used @@ -206,133 +232,109 @@ void pgrsUpdate(struct UrlData *data) now = tvnow(); /* what time is it */ - switch(data->progress.mode) { - case CURL_PROGRESS_STATS: - default: - { - char max5[6][6]; - double dlpercen=0; - double ulpercen=0; - double total_percen=0; - - double total_transfer; - double total_expected_transfer; - -#define CURR_TIME 5 - - static double speeder[ CURR_TIME ]; - static int speeder_c=0; - - int nowindex = speeder_c% CURR_TIME; - int checkindex; - int count; - - char time_left[10]; - char time_total[10]; - char time_current[10]; - - double ulestimate=0; - double dlestimate=0; - - double total_estimate; - - if(data->progress.lastshow == tvlong(now)) - return; /* never update this more than once a second if the end isn't - reached */ - data->progress.lastshow = now.tv_sec; + if(data->progress.lastshow == tvlong(now)) + return 0; /* never update this more than once a second if the end isn't + reached */ + data->progress.lastshow = now.tv_sec; - /* The exact time spent so far */ - data->progress.timespent = tvdiff (now, data->progress.start); + /* The exact time spent so far */ + data->progress.timespent = tvdiff (now, data->progress.start); - /* The average download speed this far */ - data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); + /* The average download speed this far */ + data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); - /* The average upload speed this far */ - data->progress.ulspeed = data->progress.uploaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); + /* The average upload speed this far */ + data->progress.ulspeed = data->progress.uploaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); - /* Let's do the "current speed" thing, which should use the fastest + /* Let's do the "current speed" thing, which should use the fastest of the dl/ul speeds */ - speeder[ nowindex ] = data->progress.downloaded>data->progress.uploaded? - data->progress.downloaded:data->progress.uploaded; - speeder_c++; /* increase */ - count = ((speeder_c>=CURR_TIME)?CURR_TIME:speeder_c) - 1; - checkindex = (speeder_c>=CURR_TIME)?speeder_c%CURR_TIME:0; + speeder[ nowindex ] = data->progress.downloaded>data->progress.uploaded? + data->progress.downloaded:data->progress.uploaded; + speeder_c++; /* increase */ + count = ((speeder_c>=CURR_TIME)?CURR_TIME:speeder_c) - 1; + checkindex = (speeder_c>=CURR_TIME)?speeder_c%CURR_TIME:0; - /* find out the average speed the last CURR_TIME seconds */ - data->progress.current_speed = - (speeder[nowindex]-speeder[checkindex])/(count?count:1); + /* find out the average speed the last CURR_TIME seconds */ + data->progress.current_speed = + (speeder[nowindex]-speeder[checkindex])/(count?count:1); - if(data->progress.flags & PGRS_HIDE) - return; + if(data->progress.flags & PGRS_HIDE) + return 0; + else if(data->fprogress) { + return data->fprogress(data->progress_client, + data->progress.size_dl, + data->progress.downloaded, + data->progress.size_ul, + data->progress.uploaded); + } /* Figure out the estimated time of arrival for the upload */ - if(data->progress.flags & PGRS_UL_SIZE_KNOWN) { - if(!data->progress.ulspeed) - data->progress.ulspeed=1; - ulestimate = data->progress.size_ul / data->progress.ulspeed; - ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; - } + if(data->progress.flags & PGRS_UL_SIZE_KNOWN) { + if(!data->progress.ulspeed) + data->progress.ulspeed=1; + ulestimate = data->progress.size_ul / data->progress.ulspeed; + ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; + } - /* ... and the download */ - if(data->progress.flags & PGRS_DL_SIZE_KNOWN) { - if(!data->progress.dlspeed) - data->progress.dlspeed=1; - dlestimate = data->progress.size_dl / data->progress.dlspeed; - dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; - } + /* ... and the download */ + if(data->progress.flags & PGRS_DL_SIZE_KNOWN) { + if(!data->progress.dlspeed) + data->progress.dlspeed=1; + dlestimate = data->progress.size_dl / data->progress.dlspeed; + dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; + } - /* Now figure out which of them that is slower and use for the for + /* Now figure out which of them that is slower and use for the for total estimate! */ - total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; + total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; - /* If we have a total estimate, we can display that and the expected + /* If we have a total estimate, we can display that and the expected time left */ - if(total_estimate) { - time2str(time_left, total_estimate-(int) data->progress.timespent); - time2str(time_total, total_estimate); - } - else { - /* otherwise we blank those times */ - strcpy(time_left, "--:--:--"); - strcpy(time_total, "--:--:--"); - } - /* The time spent so far is always known */ - time2str(time_current, data->progress.timespent); - - /* Get the total amount of data expected to get transfered */ - total_expected_transfer = - (data->progress.flags & PGRS_UL_SIZE_KNOWN? - data->progress.size_ul:data->progress.uploaded)+ - (data->progress.flags & PGRS_DL_SIZE_KNOWN? - data->progress.size_dl:data->progress.downloaded); + if(total_estimate) { + time2str(time_left, total_estimate-(int) data->progress.timespent); + time2str(time_total, total_estimate); + } + else { + /* otherwise we blank those times */ + strcpy(time_left, "--:--:--"); + strcpy(time_total, "--:--:--"); + } + /* The time spent so far is always known */ + time2str(time_current, data->progress.timespent); + + /* Get the total amount of data expected to get transfered */ + total_expected_transfer = + (data->progress.flags & PGRS_UL_SIZE_KNOWN? + data->progress.size_ul:data->progress.uploaded)+ + (data->progress.flags & PGRS_DL_SIZE_KNOWN? + data->progress.size_dl:data->progress.downloaded); - /* We have transfered this much so far */ - total_transfer = data->progress.downloaded + data->progress.uploaded; - - /* Get the percentage of data transfered so far */ - if(total_expected_transfer) - total_percen=(double)(total_transfer/total_expected_transfer)*100; - - - fprintf(stderr, - "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", - (int)total_percen, /* total % */ - max5data(total_expected_transfer, max5[2]), /* total size */ - (int)dlpercen, /* rcvd % */ - max5data(data->progress.downloaded, max5[0]), /* rcvd size */ - (int)ulpercen, /* xfer % */ - max5data(data->progress.uploaded, max5[1]), /* xfer size */ - - max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ - max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ - time_total, /* total time */ - time_current, /* current time */ - time_left, /* time left */ - max5data(data->progress.current_speed, max5[5]) /* current speed */ - ); - } - break; + /* We have transfered this much so far */ + total_transfer = data->progress.downloaded + data->progress.uploaded; + + /* Get the percentage of data transfered so far */ + if(total_expected_transfer) + total_percen=(double)(total_transfer/total_expected_transfer)*100; + + fprintf(stderr, + "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", + (int)total_percen, /* total % */ + max5data(total_expected_transfer, max5[2]), /* total size */ + (int)dlpercen, /* rcvd % */ + max5data(data->progress.downloaded, max5[0]), /* rcvd size */ + (int)ulpercen, /* xfer % */ + max5data(data->progress.uploaded, max5[1]), /* xfer size */ + + max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ + max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ + time_total, /* total time */ + time_current, /* current time */ + time_left, /* time left */ + max5data(data->progress.current_speed, max5[5]) /* current speed */ + ); + + #if 0 case CURL_PROGRESS_BAR: /* original progress bar code by Lars Aas */ @@ -365,7 +367,8 @@ void pgrsUpdate(struct UrlData *data) prev = point; break; #endif - } + + return 0; } -- cgit v1.2.1 From 6d522c9c1dae070f73aae1022b09b68f9153959e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 29 May 2000 23:07:22 +0000 Subject: made getenv() more threadsafe for win32 --- lib/progress.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 35847fab4..b2372aa53 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -387,6 +387,7 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) /* 20000318 mgs */ int scr_size [2]; #endif + char *colp; if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) return; @@ -399,8 +400,11 @@ void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) /* 20000318 mgs * OS/2 users most likely won't have this env var set, and besides that * we're using our own way to determine screen width */ - if (curl_GetEnv("COLUMNS") != NULL) - width = atoi(curl_GetEnv("COLUMNS")); + colp = curl_GetEnv("COLUMNS"); + if (colp != NULL) { + width = atoi(colp); + free(colp); + } else width = 79; #else -- cgit v1.2.1 From 435f17195e6111a0689b98026bde95f67d29def0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 16 Jun 2000 13:15:36 +0000 Subject: removed lots of #if 0'ed code removed the "mode" concept moved all #-stuff to the client --- lib/progress.c | 256 +++------------------------------------------------------ 1 file changed, 12 insertions(+), 244 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index b2372aa53..f34f9d087 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -57,6 +57,7 @@ #include #include "urldata.h" +#include "sendf.h" #include "progress.h" @@ -97,7 +98,6 @@ char *max5data(double bytes, char *max5) New proposed interface, 9th of February 2000: pgrsStartNow() - sets start time - pgrsMode(type) - kind of display pgrsSetDownloadSize(x) - known expected download size pgrsSetUploadSize(x) - known expected upload size pgrsSetDownloadCounter() - amount of data currently downloaded @@ -106,7 +106,7 @@ char *max5data(double bytes, char *max5) pgrsDone() - transfer complete */ -#if 1 + void pgrsDone(struct UrlData *data) { if(!(data->progress.flags & PGRS_HIDE)) { @@ -115,16 +115,6 @@ void pgrsDone(struct UrlData *data) fprintf(stderr, "\n"); } } -void pgrsMode(struct UrlData *data, int mode) -{ - /* mode should include a hidden mode as well */ - if(data->bits.hide_progress || data->bits.mute) - data->progress.flags |= PGRS_HIDE; /* don't show anything */ - else { - data->progress.mode = mode; /* store type */ - } - -} void pgrsTime(struct UrlData *data, timerid timer) { @@ -190,6 +180,7 @@ void pgrsSetUploadSize(struct UrlData *data, double size) int pgrsUpdate(struct UrlData *data) { struct timeval now; + int result; char max5[6][6]; double dlpercen=0; @@ -222,7 +213,7 @@ int pgrsUpdate(struct UrlData *data) this is were lots of the calculations are being made that will be used even when not displayed! */ else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { - if ( data->progress.mode == CURL_PROGRESS_STATS ) { + if (!data->progress.callback) { fprintf(data->err, " %% Total %% Received %% Xferd Average Speed Time Curr.\n" " Dload Upload Total Current Left Speed\n"); @@ -262,11 +253,14 @@ int pgrsUpdate(struct UrlData *data) if(data->progress.flags & PGRS_HIDE) return 0; else if(data->fprogress) { - return data->fprogress(data->progress_client, - data->progress.size_dl, - data->progress.downloaded, - data->progress.size_ul, - data->progress.uploaded); + result= data->fprogress(data->progress_client, + data->progress.size_dl, + data->progress.downloaded, + data->progress.size_ul, + data->progress.uploaded); + if(result) + failf(data, "Callback aborted"); + return result; } /* Figure out the estimated time of arrival for the upload */ @@ -334,231 +328,5 @@ int pgrsUpdate(struct UrlData *data) max5data(data->progress.current_speed, max5[5]) /* current speed */ ); - -#if 0 - case CURL_PROGRESS_BAR: - /* original progress bar code by Lars Aas */ - if (progressmax == -1) { - int prevblock = prev / 1024; - int thisblock = point / 1024; - while ( thisblock > prevblock ) { - fprintf( data->err, "#" ); - prevblock++; - } - prev = point; - } - else { - char line[256]; - char outline[256]; - char format[40]; - float frac = (float) point / (float) progressmax; - float percent = frac * 100.0f; - int barwidth = width - 7; - int num = (int) (((float)barwidth) * frac); - int i = 0; - for ( i = 0; i < num; i++ ) { - line[i] = '#'; - } - line[i] = '\0'; - sprintf( format, "%%-%ds %%5.1f%%%%", barwidth ); - sprintf( outline, format, line, percent ); - fprintf( data->err, "\r%s", outline ); - } - prev = point; - break; -#endif - return 0; } - - -#endif - -#if 0 -/* --- start of (the former) progress routines --- */ -int progressmax=-1; - -static int prev = 0; -static int width = 0; - -void ProgressInit(struct UrlData *data, int max/*, int options, int moremax*/) -{ -#ifdef __EMX__ - /* 20000318 mgs */ - int scr_size [2]; -#endif - char *colp; - - if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) - return; - - prev = 0; - -/* TODO: get terminal width through ansi escapes or something similar. - try to update width when xterm is resized... - 19990617 larsa */ -#ifndef __EMX__ - /* 20000318 mgs - * OS/2 users most likely won't have this env var set, and besides that - * we're using our own way to determine screen width */ - colp = curl_GetEnv("COLUMNS"); - if (colp != NULL) { - width = atoi(colp); - free(colp); - } - else - width = 79; -#else - /* 20000318 mgs - * We use this emx library call to get the screen width, and subtract - * one from what we got in order to avoid a problem with the cursor - * advancing to the next line if we print a string that is as long as - * the screen is wide. */ - - _scrsize(scr_size); - width = scr_size[0] - 1; -#endif - - - progressmax = max; - if(-1 == max) - return; - if(progressmax <= LEAST_SIZE_PROGRESS) { - progressmax = -1; /* disable */ - return; - } - - if ( data->progressmode == CURL_PROGRESS_STATS ) - fprintf(data->err, - " %% Received Total Speed Estimated Time Left Curr.Speed\n"); - -} - -void ProgressShow(struct UrlData *data, - int point, struct timeval start, struct timeval now, bool force) -{ - switch ( data->progressmode ) { - case CURL_PROGRESS_STATS: - { - static long lastshow; - double percen; - - double spent; - double speed; - -#define CURR_TIME 5 - - static int speeder[ CURR_TIME ]; - static int speeder_c=0; - - int nowindex = speeder_c% CURR_TIME; - int checkindex; - int count; - - if(!force && (point != progressmax) && (lastshow == tvlong(now))) - return; /* never update this more than once a second if the end isn't - reached */ - - spent = tvdiff (now, start); - speed = point/(spent!=0.0?spent:1.0); - if(!speed) - speed=1; - - /* point is where we are right now */ - speeder[ nowindex ] = point; - speeder_c++; /* increase */ - count = ((speeder_c>=CURR_TIME)?CURR_TIME:speeder_c) - 1; - checkindex = (speeder_c>=CURR_TIME)?speeder_c%CURR_TIME:0; - - /* find out the average speed the last CURR_TIME seconds */ - data->current_speed = (speeder[nowindex]-speeder[checkindex])/(count?count:1); - -#if 0 - printf("NOW %d(%d) THEN %d(%d) DIFF %lf COUNT %d\n", - speeder[nowindex], nowindex, - speeder[checkindex], checkindex, - data->current_speed, count); -#endif - - if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) - return; - - if(-1 != progressmax) { - char left[20]; - char estim[20]; - char timespent[20]; - int estimate = progressmax/(int) speed; - - time2str(left,estimate-(int) spent); - time2str(estim,estimate); - time2str(timespent,spent); - - percen=(double)point/progressmax; - percen=percen*100; - - fprintf(stderr, "\r%3d %10d %10d %6.0lf %s %s %s %6.0lf ", - (int)percen, point, progressmax, - speed, estim, timespent, left, data->current_speed); - } - else - fprintf(data->err, - "\r%d bytes received in %.3lf seconds (%.0lf bytes/sec)", - point, spent, speed); - - lastshow = now.tv_sec; - break; - } - case CURL_PROGRESS_BAR: /* 19990617 larsa */ - { - if (point == prev) break; - if (progressmax == -1) { - int prevblock = prev / 1024; - int thisblock = point / 1024; - while ( thisblock > prevblock ) { - fprintf( data->err, "#" ); - prevblock++; - } - prev = point; - } else { - char line[256]; - char outline[256]; - char format[40]; - float frac = (float) point / (float) progressmax; - float percent = frac * 100.0f; - int barwidth = width - 7; - int num = (int) (((float)barwidth) * frac); - int i = 0; - for ( i = 0; i < num; i++ ) { - line[i] = '#'; - } - line[i] = '\0'; - sprintf( format, "%%-%ds %%5.1f%%%%", barwidth ); - sprintf( outline, format, line, percent ); - fprintf( data->err, "\r%s", outline ); - } - prev = point; - break; - } - default: /* 19990617 larsa */ - { - int prevblock = prev / 1024; - int thisblock = point / 1024; - if (prev == point) break; - while ( thisblock > prevblock ) { - fprintf( data->err, "#" ); - prevblock++; - } - prev = point; - break; - } - } -} - -void ProgressEnd(struct UrlData *data) -{ - if(data->conf&(CONF_NOPROGRESS|CONF_MUTE)) - return; - fputs("\n", data->err); -} - -/* --- end of progress routines --- */ -#endif -- cgit v1.2.1 From 1ef3600a0731fef8f59563a1e49981f1b64b9746 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Jun 2000 15:31:26 +0000 Subject: haxx.nu => haxx.se --- lib/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index f34f9d087..d2c46cab8 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -24,9 +24,9 @@ * * ------------------------------------------------------------ * Main author: - * - Daniel Stenberg + * - Daniel Stenberg * - * http://curl.haxx.nu + * http://curl.haxx.se * * $Source$ * $Revision$ -- cgit v1.2.1 From b6e18f2f665f16910c04cb52bdc7b90270ab7c9b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Aug 2000 14:26:33 +0000 Subject: #include "setup.h" moved first of all includes --- lib/progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index d2c46cab8..75defbad3 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -38,9 +38,10 @@ * ------------------------------------------------------------ ****************************************************************************/ -#include #include "setup.h" +#include + #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) #if defined(__MINGW32__) #include -- cgit v1.2.1 From f353258ff62a91263b2cac9eda45dfae553bc0dc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 25 Sep 2000 21:49:37 +0000 Subject: corrected bad data re-use and buffer problems --- lib/progress.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 75defbad3..8a8a78f0e 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -183,7 +183,7 @@ int pgrsUpdate(struct UrlData *data) struct timeval now; int result; - char max5[6][6]; + char max5[6][10]; double dlpercen=0; double ulpercen=0; double total_percen=0; @@ -191,12 +191,7 @@ int pgrsUpdate(struct UrlData *data) double total_transfer; double total_expected_transfer; -#define CURR_TIME 5 - - static double speeder[ CURR_TIME ]; - static int speeder_c=0; - - int nowindex = speeder_c% CURR_TIME; + int nowindex = data->progress.speeder_c% CURR_TIME; int checkindex; int count; @@ -241,15 +236,19 @@ int pgrsUpdate(struct UrlData *data) /* Let's do the "current speed" thing, which should use the fastest of the dl/ul speeds */ - speeder[ nowindex ] = data->progress.downloaded>data->progress.uploaded? + data->progress.speeder[ nowindex ] = + data->progress.downloaded>data->progress.uploaded? data->progress.downloaded:data->progress.uploaded; - speeder_c++; /* increase */ - count = ((speeder_c>=CURR_TIME)?CURR_TIME:speeder_c) - 1; - checkindex = (speeder_c>=CURR_TIME)?speeder_c%CURR_TIME:0; + data->progress.speeder_c++; /* increase */ + count = ((data->progress.speeder_c>=CURR_TIME)? + CURR_TIME:data->progress.speeder_c) - 1; + checkindex = (data->progress.speeder_c>=CURR_TIME)? + data->progress.speeder_c%CURR_TIME:0; /* find out the average speed the last CURR_TIME seconds */ data->progress.current_speed = - (speeder[nowindex]-speeder[checkindex])/(count?count:1); + (data->progress.speeder[nowindex]- + data->progress.speeder[checkindex])/(count?count:1); if(data->progress.flags & PGRS_HIDE) return 0; @@ -284,6 +283,7 @@ int pgrsUpdate(struct UrlData *data) total estimate! */ total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; + /* If we have a total estimate, we can display that and the expected time left */ if(total_estimate) { @@ -329,5 +329,5 @@ int pgrsUpdate(struct UrlData *data) max5data(data->progress.current_speed, max5[5]) /* current speed */ ); - return 0; + return 0; } -- cgit v1.2.1 From e05922c4285bf72b2246c9909703c7411f98163b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 6 Nov 2000 15:32:16 +0000 Subject: modified pgrsTime() to the new functionality --- lib/progress.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8a8a78f0e..79ba1b59d 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -124,14 +124,24 @@ void pgrsTime(struct UrlData *data, timerid timer) case TIMER_NONE: /* mistake filter */ break; + case TIMER_STARTSINGLE: + /* This is set at the start of a single fetch, there may be several + fetches within an operation, why we add all other times relative + to this one */ + data->progress.t_startsingle = tvnow(); + break; + case TIMER_NAMELOOKUP: - data->progress.t_nslookup = tvnow(); + data->progress.t_nslookup += tvdiff(tvnow(), + data->progress.t_startsingle); break; case TIMER_CONNECT: - data->progress.t_connect = tvnow(); + data->progress.t_connect += tvdiff(tvnow(), + data->progress.t_startsingle); break; case TIMER_PRETRANSFER: - data->progress.t_pretransfer = tvnow(); + data->progress.t_pretransfer += tvdiff(tvnow(), + data->progress.t_startsingle); break; case TIMER_POSTRANSFER: /* this is the normal end-of-transfer thing */ -- cgit v1.2.1 From 77bbbd868b13dab04febcdd9086eac2fa0c8c27f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Nov 2000 07:20:12 +0000 Subject: data->err must be used, not stderr --- lib/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 79ba1b59d..8ad6821fe 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -113,7 +113,7 @@ void pgrsDone(struct UrlData *data) if(!(data->progress.flags & PGRS_HIDE)) { data->progress.lastshow=0; pgrsUpdate(data); /* the final (forced) update */ - fprintf(stderr, "\n"); + fprintf(data->err, "\n"); } } @@ -322,7 +322,7 @@ int pgrsUpdate(struct UrlData *data) if(total_expected_transfer) total_percen=(double)(total_transfer/total_expected_transfer)*100; - fprintf(stderr, + fprintf(data->err, "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", (int)total_percen, /* total % */ max5data(total_expected_transfer, max5[2]), /* total size */ -- cgit v1.2.1 From 24dee483e9e925c2ab79dd582f70c9a55ab9ba4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 3 Jan 2001 09:29:33 +0000 Subject: dual-license fix --- lib/progress.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8ad6821fe..fa902e03d 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,38 +5,21 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ + * Copyright (C) 2000, Daniel Stenberg, , et al. * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. + * In order to be useful for every potential user, curl and libcurl are + * dual-licensed under the MPL and the MIT/X-derivate licenses. * - * The Original Code is Curl. + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the MPL or the MIT/X-derivate + * licenses. You may pick one of these licenses. * - * The Initial Developer of the Original Code is Daniel Stenberg. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. * - * Portions created by the Initial Developer are Copyright (C) 1998. - * All Rights Reserved. - * - * ------------------------------------------------------------ - * Main author: - * - Daniel Stenberg - * - * http://curl.haxx.se - * - * $Source$ - * $Revision$ - * $Date$ - * $Author$ - * $State$ - * $Locker$ - * - * ------------------------------------------------------------ - ****************************************************************************/ + * $Id$ + *****************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 4031104404c6ceed5e57134125dcdb6cac51c564 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Jan 2001 10:11:41 +0000 Subject: Internal symbols that aren't static are now prefixed with 'Curl_' --- lib/progress.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index fa902e03d..098a0e681 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -45,7 +45,7 @@ #include "progress.h" -void time2str(char *r, int t) +static void time2str(char *r, int t) { int h = (t/3600); int m = (t-(h*3600))/60; @@ -55,7 +55,7 @@ void time2str(char *r, int t) /* The point of this function would be to return a string of the input data, but never longer than 5 columns. Add suffix k, M, G when suitable... */ -char *max5data(double bytes, char *max5) +static char *max5data(double bytes, char *max5) { #define ONE_KILOBYTE 1024 #define ONE_MEGABYTE (1024*1024) @@ -91,16 +91,16 @@ char *max5data(double bytes, char *max5) */ -void pgrsDone(struct UrlData *data) +void Curl_pgrsDone(struct UrlData *data) { if(!(data->progress.flags & PGRS_HIDE)) { data->progress.lastshow=0; - pgrsUpdate(data); /* the final (forced) update */ + Curl_pgrsUpdate(data); /* the final (forced) update */ fprintf(data->err, "\n"); } } -void pgrsTime(struct UrlData *data, timerid timer) +void Curl_pgrsTime(struct UrlData *data, timerid timer) { switch(timer) { default: @@ -111,19 +111,19 @@ void pgrsTime(struct UrlData *data, timerid timer) /* This is set at the start of a single fetch, there may be several fetches within an operation, why we add all other times relative to this one */ - data->progress.t_startsingle = tvnow(); + data->progress.t_startsingle = Curl_tvnow(); break; case TIMER_NAMELOOKUP: - data->progress.t_nslookup += tvdiff(tvnow(), + data->progress.t_nslookup += Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle); break; case TIMER_CONNECT: - data->progress.t_connect += tvdiff(tvnow(), + data->progress.t_connect += Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle); break; case TIMER_PRETRANSFER: - data->progress.t_pretransfer += tvdiff(tvnow(), + data->progress.t_pretransfer += Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle); break; case TIMER_POSTRANSFER: @@ -132,22 +132,22 @@ void pgrsTime(struct UrlData *data, timerid timer) } } -void pgrsStartNow(struct UrlData *data) +void Curl_pgrsStartNow(struct UrlData *data) { - data->progress.start = tvnow(); + data->progress.start = Curl_tvnow(); } -void pgrsSetDownloadCounter(struct UrlData *data, double size) +void Curl_pgrsSetDownloadCounter(struct UrlData *data, double size) { data->progress.downloaded = size; } -void pgrsSetUploadCounter(struct UrlData *data, double size) +void Curl_pgrsSetUploadCounter(struct UrlData *data, double size) { data->progress.uploaded = size; } -void pgrsSetDownloadSize(struct UrlData *data, double size) +void Curl_pgrsSetDownloadSize(struct UrlData *data, double size) { if(size > 0) { data->progress.size_dl = size; @@ -155,7 +155,7 @@ void pgrsSetDownloadSize(struct UrlData *data, double size) } } -void pgrsSetUploadSize(struct UrlData *data, double size) +void Curl_pgrsSetUploadSize(struct UrlData *data, double size) { if(size > 0) { data->progress.size_ul = size; @@ -171,7 +171,7 @@ void pgrsSetUploadSize(struct UrlData *data, double size) */ -int pgrsUpdate(struct UrlData *data) +int Curl_pgrsUpdate(struct UrlData *data) { struct timeval now; int result; @@ -210,15 +210,15 @@ int pgrsUpdate(struct UrlData *data) data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ } - now = tvnow(); /* what time is it */ + now = Curl_tvnow(); /* what time is it */ - if(data->progress.lastshow == tvlong(now)) + if(data->progress.lastshow == Curl_tvlong(now)) return 0; /* never update this more than once a second if the end isn't reached */ data->progress.lastshow = now.tv_sec; /* The exact time spent so far */ - data->progress.timespent = tvdiff (now, data->progress.start); + data->progress.timespent = Curl_tvdiff (now, data->progress.start); /* The average download speed this far */ data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); -- cgit v1.2.1 From abcd1e7d5a2aa06990a0de19196f6d417b4f3e99 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Jan 2001 16:21:05 +0000 Subject: =?UTF-8?q?Bj=F6rn=20Stenberg's=20patch=20for=20making=20the=20pro?= =?UTF-8?q?gress=20meter=20betterlooking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/progress.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 098a0e681..ac2cb23aa 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -257,17 +257,13 @@ int Curl_pgrsUpdate(struct UrlData *data) } /* Figure out the estimated time of arrival for the upload */ - if(data->progress.flags & PGRS_UL_SIZE_KNOWN) { - if(!data->progress.ulspeed) - data->progress.ulspeed=1; + if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && data->progress.ulspeed){ ulestimate = data->progress.size_ul / data->progress.ulspeed; ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; } /* ... and the download */ - if(data->progress.flags & PGRS_DL_SIZE_KNOWN) { - if(!data->progress.dlspeed) - data->progress.dlspeed=1; + if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && data->progress.dlspeed) { dlestimate = data->progress.size_dl / data->progress.dlspeed; dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; } -- cgit v1.2.1 From c43a9d9068c759a4af1200b717b0b1d57009cbac Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 25 Jan 2001 12:32:40 +0000 Subject: timespent is now updated in every call to the progress meter update function --- lib/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index ac2cb23aa..122cb6a15 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -212,14 +212,14 @@ int Curl_pgrsUpdate(struct UrlData *data) now = Curl_tvnow(); /* what time is it */ + /* The exact time spent so far */ + data->progress.timespent = Curl_tvdiff (now, data->progress.start); + if(data->progress.lastshow == Curl_tvlong(now)) return 0; /* never update this more than once a second if the end isn't reached */ data->progress.lastshow = now.tv_sec; - /* The exact time spent so far */ - data->progress.timespent = Curl_tvdiff (now, data->progress.start); - /* The average download speed this far */ data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); -- cgit v1.2.1 From c8a546c94162f5b2e7ba8f0ed2dae4f016101abe Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 27 Jan 2001 18:23:59 +0000 Subject: The progess meter title get an extra output when a resumed transfer is taking place --- lib/progress.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 122cb6a15..44b5ca38f 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -203,6 +203,9 @@ int Curl_pgrsUpdate(struct UrlData *data) even when not displayed! */ else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if (!data->progress.callback) { + if(data->resume_from) + fprintf(data->err, "** Resuming transfer from byte position %d\n", + data->resume_from); fprintf(data->err, " %% Total %% Received %% Xferd Average Speed Time Curr.\n" " Dload Upload Total Current Left Speed\n"); -- cgit v1.2.1 From 8274bee963851e4c620e9cba73f8fa6e2069da1d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 17 Apr 2001 15:00:17 +0000 Subject: init the speed index variable between transfers --- lib/progress.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 44b5ca38f..6451da6f4 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -134,6 +134,7 @@ void Curl_pgrsTime(struct UrlData *data, timerid timer) void Curl_pgrsStartNow(struct UrlData *data) { + data->progress.speeder_c = 0; /* reset the progress meter display */ data->progress.start = Curl_tvnow(); } -- cgit v1.2.1 From 3fd65fb7d83a8e3e6acd1a40c48b46088ebd536f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 18 Apr 2001 07:25:11 +0000 Subject: Remade resume stuff to keep data in the connectdata struct instead of the main handle struct to work with persistant connections --- lib/progress.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 6451da6f4..9fbd45c34 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -91,11 +91,12 @@ static char *max5data(double bytes, char *max5) */ -void Curl_pgrsDone(struct UrlData *data) +void Curl_pgrsDone(struct connectdata *conn) { + struct UrlData *data = conn->data; if(!(data->progress.flags & PGRS_HIDE)) { data->progress.lastshow=0; - Curl_pgrsUpdate(data); /* the final (forced) update */ + Curl_pgrsUpdate(conn); /* the final (forced) update */ fprintf(data->err, "\n"); } } @@ -172,7 +173,7 @@ void Curl_pgrsSetUploadSize(struct UrlData *data, double size) */ -int Curl_pgrsUpdate(struct UrlData *data) +int Curl_pgrsUpdate(struct connectdata *conn) { struct timeval now; int result; @@ -185,6 +186,8 @@ int Curl_pgrsUpdate(struct UrlData *data) double total_transfer; double total_expected_transfer; + struct UrlData *data = conn->data; + int nowindex = data->progress.speeder_c% CURR_TIME; int checkindex; int count; @@ -198,15 +201,16 @@ int Curl_pgrsUpdate(struct UrlData *data) double total_estimate; + if(data->progress.flags & PGRS_HIDE) ; /* We do enter this function even if we don't wanna see anything, since this is were lots of the calculations are being made that will be used even when not displayed! */ else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if (!data->progress.callback) { - if(data->resume_from) + if(conn->resume_from) fprintf(data->err, "** Resuming transfer from byte position %d\n", - data->resume_from); + conn->resume_from); fprintf(data->err, " %% Total %% Received %% Xferd Average Speed Time Curr.\n" " Dload Upload Total Current Left Speed\n"); -- cgit v1.2.1 From 2b44fdab2ebf7b7de65fa5e6699bb56167224a47 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 2 Aug 2001 17:05:11 +0000 Subject: don't do final newline output when using progress callback --- lib/progress.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 9fbd45c34..08d9c7890 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -97,7 +97,9 @@ void Curl_pgrsDone(struct connectdata *conn) if(!(data->progress.flags & PGRS_HIDE)) { data->progress.lastshow=0; Curl_pgrsUpdate(conn); /* the final (forced) update */ - fprintf(data->err, "\n"); + if(!data->progress.callback) + /* only output if we don't use progress callback */ + fprintf(data->err, "\n"); } } -- cgit v1.2.1 From 4b6c2408327d283a1453c8540367fd00285e5862 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 10 Aug 2001 06:24:49 +0000 Subject: moved the download/upload speed calculations, to be made on every invoke of the progressupdate, as on very quick transfers they wouldn't always get calculated! --- lib/progress.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 08d9c7890..af756a026 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -225,20 +225,19 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* The exact time spent so far */ data->progress.timespent = Curl_tvdiff (now, data->progress.start); - if(data->progress.lastshow == Curl_tvlong(now)) - return 0; /* never update this more than once a second if the end isn't - reached */ - data->progress.lastshow = now.tv_sec; - /* The average download speed this far */ data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); /* The average upload speed this far */ data->progress.ulspeed = data->progress.uploaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); + if(data->progress.lastshow == Curl_tvlong(now)) + return 0; /* never update this more than once a second if the end isn't + reached */ + data->progress.lastshow = now.tv_sec; + /* Let's do the "current speed" thing, which should use the fastest of the dl/ul speeds */ - data->progress.speeder[ nowindex ] = data->progress.downloaded>data->progress.uploaded? data->progress.downloaded:data->progress.uploaded; -- cgit v1.2.1 From d5fbfa3d0b975c112ff55d4924530ed3c69edd89 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 21 Aug 2001 06:29:56 +0000 Subject: =?UTF-8?q?As=20Andr=E9s=20Garc=EDa=20reported=20we=20need=20to=20?= =?UTF-8?q?fflush()=20the=20data->err=20so=20that=20the=20progress=20meter?= =?UTF-8?q?=20looks=20better=20on=20windows=20(and=20if=20the=20data->err?= =?UTF-8?q?=20is=20redirected=20from=20stderr=20it=20also=20makes=20a=20po?= =?UTF-8?q?int)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/progress.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index af756a026..093c93083 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -327,5 +327,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) max5data(data->progress.current_speed, max5[5]) /* current speed */ ); + /* we flush the output stream to make it appear as soon as possible */ + fflush(data->err); + return 0; } -- cgit v1.2.1 From 0ece1b5c34c049a3226f7dd793cf75e470c46e4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 30 Aug 2001 22:48:34 +0000 Subject: Major rename and redesign of the internal "backbone" structs. Details will be posted in a minute to the libcurl list. --- lib/progress.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 093c93083..45bc407f3 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -93,17 +93,17 @@ static char *max5data(double bytes, char *max5) void Curl_pgrsDone(struct connectdata *conn) { - struct UrlData *data = conn->data; + struct SessionHandle *data = conn->data; if(!(data->progress.flags & PGRS_HIDE)) { data->progress.lastshow=0; Curl_pgrsUpdate(conn); /* the final (forced) update */ if(!data->progress.callback) /* only output if we don't use progress callback */ - fprintf(data->err, "\n"); + fprintf(data->set.err, "\n"); } } -void Curl_pgrsTime(struct UrlData *data, timerid timer) +void Curl_pgrsTime(struct SessionHandle *data, timerid timer) { switch(timer) { default: @@ -135,23 +135,23 @@ void Curl_pgrsTime(struct UrlData *data, timerid timer) } } -void Curl_pgrsStartNow(struct UrlData *data) +void Curl_pgrsStartNow(struct SessionHandle *data) { data->progress.speeder_c = 0; /* reset the progress meter display */ data->progress.start = Curl_tvnow(); } -void Curl_pgrsSetDownloadCounter(struct UrlData *data, double size) +void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, double size) { data->progress.downloaded = size; } -void Curl_pgrsSetUploadCounter(struct UrlData *data, double size) +void Curl_pgrsSetUploadCounter(struct SessionHandle *data, double size) { data->progress.uploaded = size; } -void Curl_pgrsSetDownloadSize(struct UrlData *data, double size) +void Curl_pgrsSetDownloadSize(struct SessionHandle *data, double size) { if(size > 0) { data->progress.size_dl = size; @@ -159,7 +159,7 @@ void Curl_pgrsSetDownloadSize(struct UrlData *data, double size) } } -void Curl_pgrsSetUploadSize(struct UrlData *data, double size) +void Curl_pgrsSetUploadSize(struct SessionHandle *data, double size) { if(size > 0) { data->progress.size_ul = size; @@ -188,7 +188,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) double total_transfer; double total_expected_transfer; - struct UrlData *data = conn->data; + struct SessionHandle *data = conn->data; int nowindex = data->progress.speeder_c% CURR_TIME; int checkindex; @@ -211,9 +211,9 @@ int Curl_pgrsUpdate(struct connectdata *conn) else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if (!data->progress.callback) { if(conn->resume_from) - fprintf(data->err, "** Resuming transfer from byte position %d\n", + fprintf(data->set.err, "** Resuming transfer from byte position %d\n", conn->resume_from); - fprintf(data->err, + fprintf(data->set.err, " %% Total %% Received %% Xferd Average Speed Time Curr.\n" " Dload Upload Total Current Left Speed\n"); } @@ -254,12 +254,12 @@ int Curl_pgrsUpdate(struct connectdata *conn) if(data->progress.flags & PGRS_HIDE) return 0; - else if(data->fprogress) { - result= data->fprogress(data->progress_client, - data->progress.size_dl, - data->progress.downloaded, - data->progress.size_ul, - data->progress.uploaded); + else if(data->set.fprogress) { + result= data->set.fprogress(data->set.progress_client, + data->progress.size_dl, + data->progress.downloaded, + data->progress.size_ul, + data->progress.uploaded); if(result) failf(data, "Callback aborted"); return result; @@ -310,7 +310,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) if(total_expected_transfer) total_percen=(double)(total_transfer/total_expected_transfer)*100; - fprintf(data->err, + fprintf(data->set.err, "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", (int)total_percen, /* total % */ max5data(total_expected_transfer, max5[2]), /* total size */ @@ -328,7 +328,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) ); /* we flush the output stream to make it appear as soon as possible */ - fflush(data->err); + fflush(data->set.err); return 0; } -- cgit v1.2.1 From 6147879837a53d22c9be04e7a4fc315a297ba2b3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Fri, 7 Sep 2001 04:01:32 +0000 Subject: Added formatting sections for emacs and vim --- lib/progress.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 45bc407f3..08611e920 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -332,3 +332,11 @@ int Curl_pgrsUpdate(struct connectdata *conn) return 0; } + +/* + * local variables: + * eval: (load-file "../curl-mode.el") + * end: + * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker + * vim<600: et sw=2 ts=2 sts=2 tw=78 + */ -- cgit v1.2.1 From 8e91d5de8e4e17ce3d4936cc91171d09726e7bb3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Thu, 11 Oct 2001 09:32:19 +0000 Subject: looks nicer and is better compatible with older vim versions --- lib/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 08611e920..3686340b6 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -337,6 +337,6 @@ int Curl_pgrsUpdate(struct connectdata *conn) * local variables: * eval: (load-file "../curl-mode.el") * end: - * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker - * vim<600: et sw=2 ts=2 sts=2 tw=78 + * vim600: fdm=marker + * vim: et sw=2 ts=2 sts=2 tw=78 */ -- cgit v1.2.1 From ef48c737834a68a1731ca09324f50db5dafa6fdb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 12 Oct 2001 12:31:06 +0000 Subject: extensively commented source code, parts refreshened, the "current speed" is now more accurate since it is based on actual spent time without the assumptions from before --- lib/progress.c | 87 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 26 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 3686340b6..571879b8a 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2000, Daniel Stenberg, , et al. + * Copyright (C) 2001, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. @@ -70,7 +70,7 @@ static char *max5data(double bytes, char *max5) } if(bytes < (100*ONE_MEGABYTE)) { /* 'XX.XM' is good as long as we're less than 100 megs */ - sprintf(max5, "%2.1fM", bytes/ONE_MEGABYTE); + sprintf(max5, "%4.1fM", bytes/ONE_MEGABYTE); return max5; } sprintf(max5, "%4dM", (int)bytes/ONE_MEGABYTE); @@ -118,16 +118,16 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) break; case TIMER_NAMELOOKUP: - data->progress.t_nslookup += Curl_tvdiff(Curl_tvnow(), - data->progress.t_startsingle); + data->progress.t_nslookup += + Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; break; case TIMER_CONNECT: - data->progress.t_connect += Curl_tvdiff(Curl_tvnow(), - data->progress.t_startsingle); + data->progress.t_connect += + Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; break; case TIMER_PRETRANSFER: - data->progress.t_pretransfer += Curl_tvdiff(Curl_tvnow(), - data->progress.t_startsingle); + data->progress.t_pretransfer += + Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; break; case TIMER_POSTRANSFER: /* this is the normal end-of-transfer thing */ @@ -192,7 +192,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) int nowindex = data->progress.speeder_c% CURR_TIME; int checkindex; - int count; + + int countindex; /* amount of seconds stored in the speeder array */ char time_left[10]; char time_total[10]; @@ -222,14 +223,18 @@ int Curl_pgrsUpdate(struct connectdata *conn) now = Curl_tvnow(); /* what time is it */ - /* The exact time spent so far */ - data->progress.timespent = Curl_tvdiff (now, data->progress.start); + /* The exact time spent so far (from the start) */ + data->progress.timespent = Curl_tvdiff (now, data->progress.start)/1000; /* The average download speed this far */ - data->progress.dlspeed = data->progress.downloaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); + data->progress.dlspeed = + data->progress.downloaded/(data->progress.timespent? + data->progress.timespent:1); /* The average upload speed this far */ - data->progress.ulspeed = data->progress.uploaded/(data->progress.timespent!=0.0?data->progress.timespent:1.0); + data->progress.ulspeed = + data->progress.uploaded/(data->progress.timespent? + data->progress.timespent:1); if(data->progress.lastshow == Curl_tvlong(now)) return 0; /* never update this more than once a second if the end isn't @@ -237,24 +242,54 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->progress.lastshow = now.tv_sec; /* Let's do the "current speed" thing, which should use the fastest - of the dl/ul speeds */ + of the dl/ul speeds. Store the fasted speed at entry 'nowindex'. */ data->progress.speeder[ nowindex ] = data->progress.downloaded>data->progress.uploaded? data->progress.downloaded:data->progress.uploaded; - data->progress.speeder_c++; /* increase */ - count = ((data->progress.speeder_c>=CURR_TIME)? - CURR_TIME:data->progress.speeder_c) - 1; - checkindex = (data->progress.speeder_c>=CURR_TIME)? - data->progress.speeder_c%CURR_TIME:0; - /* find out the average speed the last CURR_TIME seconds */ - data->progress.current_speed = - (data->progress.speeder[nowindex]- - data->progress.speeder[checkindex])/(count?count:1); + /* remember the exact time for this moment */ + data->progress.speeder_time [ nowindex ] = now; + + /* advance our speeder_c counter, which is increased every time we get + here and we expect it to never wrap as 2^32 is a lot of seconds! */ + data->progress.speeder_c++; + + /* figure out how many index entries of data we have stored in our speeder + array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of + transfer. Imagine, after one second we have filled in two entries, + after two seconds we've filled in three entries etc. */ + countindex = ((data->progress.speeder_c>=CURR_TIME)? + CURR_TIME:data->progress.speeder_c) - 1; + + /* first of all, we don't do this if there's no counted seconds yet */ + if(countindex) { + long span_ms; + + /* Get the index position to compare with the 'nowindex' position. + Get the oldest entry possible. While we have less than CURR_TIME + entries, the first entry will remain the oldest. */ + checkindex = (data->progress.speeder_c>=CURR_TIME)? + data->progress.speeder_c%CURR_TIME:0; + + /* Figure out the exact time for the time span */ + span_ms = Curl_tvdiff(now, + data->progress.speeder_time[checkindex]); + + /* Calculate the average speed the last 'countindex' seconds */ + data->progress.current_speed = + (data->progress.speeder[nowindex]- + data->progress.speeder[checkindex])/((double)span_ms/1000); + } + else + /* the first second we only have one speed information to use */ + data->progress.current_speed = data->progress.speeder[nowindex]; if(data->progress.flags & PGRS_HIDE) return 0; + else if(data->set.fprogress) { + /* There's a callback set, so we call that instead of writing + anything ourselves. This really is the way to go. */ result= data->set.fprogress(data->set.progress_client, data->progress.size_dl, data->progress.downloaded, @@ -265,7 +300,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) return result; } - /* Figure out the estimated time of arrival for the upload */ + /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && data->progress.ulspeed){ ulestimate = data->progress.size_ul / data->progress.ulspeed; ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; @@ -278,12 +313,12 @@ int Curl_pgrsUpdate(struct connectdata *conn) } /* Now figure out which of them that is slower and use for the for - total estimate! */ + total estimate! */ total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; /* If we have a total estimate, we can display that and the expected - time left */ + time left */ if(total_estimate) { time2str(time_left, total_estimate-(int) data->progress.timespent); time2str(time_total, total_estimate); -- cgit v1.2.1 From babb985f1a7155b01f0483a817db3b0c2437c588 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 26 Oct 2001 11:25:03 +0000 Subject: made 'timespent' a double, which makes more accurate calculations for quick downloads --- lib/progress.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 571879b8a..9e53f4b99 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -187,6 +187,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) double total_transfer; double total_expected_transfer; + double timespent; struct SessionHandle *data = conn->data; @@ -224,17 +225,17 @@ int Curl_pgrsUpdate(struct connectdata *conn) now = Curl_tvnow(); /* what time is it */ /* The exact time spent so far (from the start) */ - data->progress.timespent = Curl_tvdiff (now, data->progress.start)/1000; + timespent = (double)Curl_tvdiff (now, data->progress.start)/1000; + + data->progress.timespent = (long)timespent; /* The average download speed this far */ data->progress.dlspeed = - data->progress.downloaded/(data->progress.timespent? - data->progress.timespent:1); + data->progress.downloaded/(timespent>0.01?timespent:1); /* The average upload speed this far */ data->progress.ulspeed = - data->progress.uploaded/(data->progress.timespent? - data->progress.timespent:1); + data->progress.uploaded/(timespent>0.01?timespent:1); if(data->progress.lastshow == Curl_tvlong(now)) return 0; /* never update this more than once a second if the end isn't @@ -281,8 +282,10 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->progress.speeder[checkindex])/((double)span_ms/1000); } else - /* the first second we only have one speed information to use */ - data->progress.current_speed = data->progress.speeder[nowindex]; + /* the first second we use the main average */ + data->progress.current_speed = + (data->progress.ulspeed>data->progress.dlspeed)? + data->progress.ulspeed:data->progress.dlspeed; if(data->progress.flags & PGRS_HIDE) return 0; -- cgit v1.2.1 From bbdc9f15e79876696fab6a41c7a02624a5c113de Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 31 Oct 2001 14:45:47 +0000 Subject: added typecasts to make the timers calculate with doubles, not longs as they accidentally did after the Curl_tvdiff() interface change --- lib/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 9e53f4b99..c4b1f5153 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -119,15 +119,15 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) case TIMER_NAMELOOKUP: data->progress.t_nslookup += - Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; break; case TIMER_CONNECT: data->progress.t_connect += - Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; break; case TIMER_PRETRANSFER: data->progress.t_pretransfer += - Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; break; case TIMER_POSTRANSFER: /* this is the normal end-of-transfer thing */ -- cgit v1.2.1 From c55d0bb80435aef2e06a34c006da410b47982d92 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 12 Nov 2001 08:50:59 +0000 Subject: We need at least one millisecond to calculate current speed with! I also made the getinfo() stuff divide with 1000.0 now to enforce floating point since Paul Harrington claims the 7.9.1 still uses even second resolution in the timers there --- lib/progress.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index c4b1f5153..865744654 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -119,15 +119,15 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) case TIMER_NAMELOOKUP: data->progress.t_nslookup += - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; break; case TIMER_CONNECT: data->progress.t_connect += - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; break; case TIMER_PRETRANSFER: data->progress.t_pretransfer += - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000; + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; break; case TIMER_POSTRANSFER: /* this is the normal end-of-transfer thing */ @@ -275,6 +275,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Figure out the exact time for the time span */ span_ms = Curl_tvdiff(now, data->progress.speeder_time[checkindex]); + if(0 == span_ms) + span_ms=1; /* at least one millisecond MUST have passed */ /* Calculate the average speed the last 'countindex' seconds */ data->progress.current_speed = -- cgit v1.2.1 From ca0fd33d2d3ecca13bc78893e165a34682b4dcd2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Nov 2001 15:00:50 +0000 Subject: Georg Horn's STARTTRANSFER_TIME patch --- lib/progress.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 865744654..318a6d872 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -111,22 +111,24 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) /* mistake filter */ break; case TIMER_STARTSINGLE: - /* This is set at the start of a single fetch, there may be several - fetches within an operation, why we add all other times relative - to this one */ + /* This is set at the start of a single fetch */ data->progress.t_startsingle = Curl_tvnow(); break; case TIMER_NAMELOOKUP: - data->progress.t_nslookup += + data->progress.t_nslookup = (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; break; case TIMER_CONNECT: - data->progress.t_connect += + data->progress.t_connect = (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; break; case TIMER_PRETRANSFER: - data->progress.t_pretransfer += + data->progress.t_pretransfer = + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; + break; + case TIMER_STARTTRANSFER: + data->progress.t_starttransfer = (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; break; case TIMER_POSTRANSFER: @@ -227,7 +229,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* The exact time spent so far (from the start) */ timespent = (double)Curl_tvdiff (now, data->progress.start)/1000; - data->progress.timespent = (long)timespent; + data->progress.timespent = timespent; /* The average download speed this far */ data->progress.dlspeed = -- cgit v1.2.1 From 974f314f5785156af6983675aeb28313cc8ba2ea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 07:54:55 +0000 Subject: copyright string (year) update --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 318a6d872..8c48c1ac1 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2001, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. -- cgit v1.2.1 From 62d205a2ec38ed54e359625d69a7210dc274f093 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 16 Apr 2002 07:59:20 +0000 Subject: Dirk Manske brought the patch that introduces two new CURLINFO_* values: CURLINFO_REDIRECT_TIME and CURLINFO_REDIRECT_COUNT. --- lib/progress.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8c48c1ac1..b3052e425 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -103,6 +103,15 @@ void Curl_pgrsDone(struct connectdata *conn) } } +/* reset all times except redirect */ +void Curl_pgrsResetTimes(struct SessionHandle *data) +{ + data->progress.t_nslookup = 0.0; + data->progress.t_connect = 0.0; + data->progress.t_pretransfer = 0.0; + data->progress.t_starttransfer = 0.0; +} + void Curl_pgrsTime(struct SessionHandle *data, timerid timer) { switch(timer) { @@ -134,6 +143,10 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) case TIMER_POSTRANSFER: /* this is the normal end-of-transfer thing */ break; + case TIMER_REDIRECT: + data->progress.t_redirect = + (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; + break; } } -- cgit v1.2.1 From 39028f1bd49242468126aa7d93e498e1b40952b4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 3 May 2002 12:06:04 +0000 Subject: make sure our own printf() clones are used --- lib/progress.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index b3052e425..881ab0549 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -45,6 +45,10 @@ #include "progress.h" +#define _MPRINTF_REPLACE /* use our functions only */ +#include + + static void time2str(char *r, int t) { int h = (t/3600); -- cgit v1.2.1 From bce5e0d82cfde0885e83ddfe1956dbb97ab2b0f3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 3 Jun 2002 12:46:04 +0000 Subject: T. Bharath fixed the TIMER_REDIRECT. --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 881ab0549..6a9ebc5a4 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -149,7 +149,7 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) break; case TIMER_REDIRECT: data->progress.t_redirect = - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; + (double)Curl_tvdiff(Curl_tvnow(), data->progress.start)/1000.0; break; } } -- cgit v1.2.1 From 982c5460f0eb521ce4f9526535e9d122fe8755bd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 26 Aug 2002 17:20:29 +0000 Subject: Andrew Francis removed the need for/use of MSVC pragmas --- lib/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 6a9ebc5a4..3ca71f117 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -344,8 +344,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* If we have a total estimate, we can display that and the expected time left */ if(total_estimate) { - time2str(time_left, total_estimate-(int) data->progress.timespent); - time2str(time_total, total_estimate); + time2str(time_left, (int)(total_estimate - data->progress.timespent)); + time2str(time_total, (int)total_estimate); } else { /* otherwise we blank those times */ @@ -353,7 +353,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) strcpy(time_total, "--:--:--"); } /* The time spent so far is always known */ - time2str(time_current, data->progress.timespent); + time2str(time_current, (int)data->progress.timespent); /* Get the total amount of data expected to get transfered */ total_expected_transfer = -- cgit v1.2.1 From ba4e69bebc8f7f32f3bc7faa1e13e7580754075b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2002 11:52:59 +0000 Subject: updated source code boilerplate/header --- lib/progress.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 3ca71f117..76fa18c2b 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -7,19 +7,19 @@ * * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * - * In order to be useful for every potential user, curl and libcurl are - * dual-licensed under the MPL and the MIT/X-derivate licenses. - * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the MPL or the MIT/X-derivate - * licenses. You may pick one of these licenses. + * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * $Id$ - *****************************************************************************/ + ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From f26a338a54e04d0a6907f5d2479d8b0fa9daf297 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 21:08:12 +0000 Subject: copyright year update in the source header --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 76fa18c2b..6b368ba57 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From a7c72b7abf1213c471f3fd11e6b8e3a37d526f60 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Jan 2003 10:14:20 +0000 Subject: removed the local variables for emacs and vim, use the new sample.emacs way for emacs, and vim users should provide a similar non-polluting style --- lib/progress.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 6b368ba57..414ee2c1f 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -391,11 +391,3 @@ int Curl_pgrsUpdate(struct connectdata *conn) return 0; } - -/* - * local variables: - * eval: (load-file "../curl-mode.el") - * end: - * vim600: fdm=marker - * vim: et sw=2 ts=2 sts=2 tw=78 - */ -- cgit v1.2.1 From 22569681bc2e8cb5173b042561b44cceda88589b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 14 May 2003 06:31:00 +0000 Subject: George Comninos provided a fix that calls the progress meter when waiting for FTP command responses take >1 second. --- lib/progress.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 414ee2c1f..5036efaeb 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -172,18 +172,20 @@ void Curl_pgrsSetUploadCounter(struct SessionHandle *data, double size) void Curl_pgrsSetDownloadSize(struct SessionHandle *data, double size) { - if(size > 0) { - data->progress.size_dl = size; + data->progress.size_dl = size; + if(size > 0) data->progress.flags |= PGRS_DL_SIZE_KNOWN; - } + else + data->progress.flags &= ~PGRS_DL_SIZE_KNOWN; } void Curl_pgrsSetUploadSize(struct SessionHandle *data, double size) { - if(size > 0) { - data->progress.size_ul = size; + data->progress.size_ul = size; + if(size > 0) data->progress.flags |= PGRS_UL_SIZE_KNOWN; - } + else + data->progress.flags &= ~PGRS_UL_SIZE_KNOWN; } /* EXAMPLE OUTPUT to follow: -- cgit v1.2.1 From 749f5387c19449209615b282ac738032f2a890e7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 14 Oct 2003 12:00:45 +0000 Subject: Gisle Vanem's IPv6-on-Windows patch applied! --- lib/progress.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 5036efaeb..cb64e0b06 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -24,13 +24,7 @@ #include "setup.h" #include - -#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) -#if defined(__MINGW32__) -#include -#endif #include -#endif /* 20000318 mgs * later we use _scrsize to determine the screen width, this emx library -- cgit v1.2.1 From b60e0fa97ed7ddc66d0ad6d00dfd78319bb6ad36 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 5 Jan 2004 22:29:29 +0000 Subject: David J Meyer's large file support. --- lib/progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index cb64e0b06..f788998a7 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -228,7 +228,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if (!data->progress.callback) { if(conn->resume_from) - fprintf(data->set.err, "** Resuming transfer from byte position %d\n", + fprintf(data->set.err, + "** Resuming transfer from byte position %Od\n", conn->resume_from); fprintf(data->set.err, " %% Total %% Received %% Xferd Average Speed Time Curr.\n" -- cgit v1.2.1 From 053f6c85efd0bf698f73343989474d672d0563a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Jan 2004 09:19:33 +0000 Subject: updated year in the copyright string --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index f788998a7..2da1e790b 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 686c70c5b572b14fd3af1c533426fa6d28fc23bf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 15 Jan 2004 13:08:12 +0000 Subject: use the %dk display for one extra k of progress --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 2da1e790b..8f0b8cb6f 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -62,7 +62,7 @@ static char *max5data(double bytes, char *max5) sprintf(max5, "%5d", (int)bytes); return max5; } - if(bytes < (9999*ONE_KILOBYTE)) { + if(bytes < (10000*ONE_KILOBYTE)) { sprintf(max5, "%4dk", (int)bytes/ONE_KILOBYTE); return max5; } -- cgit v1.2.1 From fac1c13895b62464abd7c4e875d46b12ec7873c0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 23 Jan 2004 08:02:12 +0000 Subject: fixed the progress meter display for files >32 bit, Gisle Vanem reported --- lib/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8f0b8cb6f..972629c64 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -59,11 +59,11 @@ static char *max5data(double bytes, char *max5) #define ONE_MEGABYTE (1024*1024) if(bytes < 100000) { - sprintf(max5, "%5d", (int)bytes); + sprintf(max5, "%5Od", (curl_off_t)bytes); return max5; } if(bytes < (10000*ONE_KILOBYTE)) { - sprintf(max5, "%4dk", (int)bytes/ONE_KILOBYTE); + sprintf(max5, "%4Odk", (curl_off_t)bytes/ONE_KILOBYTE); return max5; } if(bytes < (100*ONE_MEGABYTE)) { @@ -71,7 +71,7 @@ static char *max5data(double bytes, char *max5) sprintf(max5, "%4.1fM", bytes/ONE_MEGABYTE); return max5; } - sprintf(max5, "%4dM", (int)bytes/ONE_MEGABYTE); + sprintf(max5, "%4OdM", (curl_off_t)bytes/ONE_MEGABYTE); return max5; } -- cgit v1.2.1 From e0960727453034ac3e01e20007a9c1b261d1d135 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 27 Jan 2004 12:25:37 +0000 Subject: very big transfers now get nicer progress displayed after 9999 megabytes have been transfered! --- lib/progress.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 972629c64..b22f4a70b 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -57,6 +57,7 @@ static char *max5data(double bytes, char *max5) { #define ONE_KILOBYTE 1024 #define ONE_MEGABYTE (1024*1024) +#define ONE_GIGABYTE (1024*1024*1024) if(bytes < 100000) { sprintf(max5, "%5Od", (curl_off_t)bytes); @@ -71,7 +72,17 @@ static char *max5data(double bytes, char *max5) sprintf(max5, "%4.1fM", bytes/ONE_MEGABYTE); return max5; } +#if SIZEOF_CURL_OFF_T > 4 + if((curl_off_t)bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { + sprintf(max5, "%4OdM", (curl_off_t)bytes/ONE_MEGABYTE); + return max5; + } + /* 10000 MB - 8589934587 GB !! */ + sprintf(max5, "%4.1fG", bytes/ONE_GIGABYTE); +#else sprintf(max5, "%4OdM", (curl_off_t)bytes/ONE_MEGABYTE); +#endif + return max5; } -- cgit v1.2.1 From 4d17d6876e4b2f08380812c4ec113073b0a14639 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 29 Jan 2004 13:56:45 +0000 Subject: Dan Fandrich's cleanup patch to make pedantic compiler options cause less warnings. Minor edits by me. --- lib/progress.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index b22f4a70b..467b585c2 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -333,13 +333,15 @@ int Curl_pgrsUpdate(struct connectdata *conn) } /* Figure out the estimated time of arrival for the upload */ - if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && data->progress.ulspeed){ + if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && + (data->progress.ulspeed > 0)) { ulestimate = data->progress.size_ul / data->progress.ulspeed; ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; } /* ... and the download */ - if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && data->progress.dlspeed) { + if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && + (data->progress.dlspeed > 0)) { dlestimate = data->progress.size_dl / data->progress.dlspeed; dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; } @@ -351,7 +353,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* If we have a total estimate, we can display that and the expected time left */ - if(total_estimate) { + if(total_estimate > 0) { time2str(time_left, (int)(total_estimate - data->progress.timespent)); time2str(time_total, (int)total_estimate); } @@ -374,7 +376,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) total_transfer = data->progress.downloaded + data->progress.uploaded; /* Get the percentage of data transfered so far */ - if(total_expected_transfer) + if(total_expected_transfer > 0) total_percen=(double)(total_transfer/total_expected_transfer)*100; fprintf(data->set.err, -- cgit v1.2.1 From cb72a80fe06d96c46e69a869cceb16b491fcb23b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 1 Mar 2004 16:28:00 +0000 Subject: Use CURL_FORMAT_OFF_T for printf()inf curl_off_t variables. --- lib/progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 467b585c2..ab97d337e 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -240,7 +240,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) if (!data->progress.callback) { if(conn->resume_from) fprintf(data->set.err, - "** Resuming transfer from byte position %Od\n", + "** Resuming transfer from byte position " CURL_FORMAT_OFF_T + "\n", conn->resume_from); fprintf(data->set.err, " %% Total %% Received %% Xferd Average Speed Time Curr.\n" -- cgit v1.2.1 From 7ab3b5b3bb4c02dc00621efe13b8d3b29b819250 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Mar 2004 07:25:39 +0000 Subject: use FORMAT_OFF_T instead of CURL_FORMAT_OFF_T to reduce the complexity of having to redef that name --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index ab97d337e..f7e507685 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -240,7 +240,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) if (!data->progress.callback) { if(conn->resume_from) fprintf(data->set.err, - "** Resuming transfer from byte position " CURL_FORMAT_OFF_T + "** Resuming transfer from byte position " FORMAT_OFF_T "\n", conn->resume_from); fprintf(data->set.err, -- cgit v1.2.1 From 353f7641193ddf3f6a42d49d53ea994e4ea4388b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Mar 2004 09:31:18 +0000 Subject: Yet another curl_off_t printf format attempt, we now exclude the %-letter from FORMAT_OFF_T to allow additional options to get specified, like with '"%5" FORMAT_OFF_T'. --- lib/progress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index f7e507685..62e4624f5 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -60,11 +60,11 @@ static char *max5data(double bytes, char *max5) #define ONE_GIGABYTE (1024*1024*1024) if(bytes < 100000) { - sprintf(max5, "%5Od", (curl_off_t)bytes); + sprintf(max5, "%5" FORMAT_OFF_T, (curl_off_t)bytes); return max5; } if(bytes < (10000*ONE_KILOBYTE)) { - sprintf(max5, "%4Odk", (curl_off_t)bytes/ONE_KILOBYTE); + sprintf(max5, "%4" FORMAT_OFF_T "k", (curl_off_t)bytes/ONE_KILOBYTE); return max5; } if(bytes < (100*ONE_MEGABYTE)) { @@ -74,13 +74,13 @@ static char *max5data(double bytes, char *max5) } #if SIZEOF_CURL_OFF_T > 4 if((curl_off_t)bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { - sprintf(max5, "%4OdM", (curl_off_t)bytes/ONE_MEGABYTE); + sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)bytes/ONE_MEGABYTE); return max5; } /* 10000 MB - 8589934587 GB !! */ sprintf(max5, "%4.1fG", bytes/ONE_GIGABYTE); #else - sprintf(max5, "%4OdM", (curl_off_t)bytes/ONE_MEGABYTE); + sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)bytes/ONE_MEGABYTE); #endif return max5; @@ -240,7 +240,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) if (!data->progress.callback) { if(conn->resume_from) fprintf(data->set.err, - "** Resuming transfer from byte position " FORMAT_OFF_T + "** Resuming transfer from byte position %" FORMAT_OFF_T "\n", conn->resume_from); fprintf(data->set.err, -- cgit v1.2.1 From 0d1fc73f2119e1f75f58b32cdc9f9d45fa71ac9c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 10 Mar 2004 16:20:33 +0000 Subject: Use more curl_off_t variables when doing the progress meter calculations and argument passing and try to convert to double only when providing data to the external world. --- lib/progress.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 62e4624f5..d0421ca6c 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -165,17 +165,17 @@ void Curl_pgrsStartNow(struct SessionHandle *data) data->progress.start = Curl_tvnow(); } -void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, double size) +void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size) { data->progress.downloaded = size; } -void Curl_pgrsSetUploadCounter(struct SessionHandle *data, double size) +void Curl_pgrsSetUploadCounter(struct SessionHandle *data, curl_off_t size) { data->progress.uploaded = size; } -void Curl_pgrsSetDownloadSize(struct SessionHandle *data, double size) +void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size) { data->progress.size_dl = size; if(size > 0) @@ -184,7 +184,7 @@ void Curl_pgrsSetDownloadSize(struct SessionHandle *data, double size) data->progress.flags &= ~PGRS_DL_SIZE_KNOWN; } -void Curl_pgrsSetUploadSize(struct SessionHandle *data, double size) +void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size) { data->progress.size_ul = size; if(size > 0) @@ -211,8 +211,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) double ulpercen=0; double total_percen=0; - double total_transfer; - double total_expected_transfer; + curl_off_t total_transfer; + curl_off_t total_expected_transfer; double timespent; struct SessionHandle *data = conn->data; @@ -259,7 +259,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* The average download speed this far */ data->progress.dlspeed = - data->progress.downloaded/(timespent>0.01?timespent:1); + data->progress.downloaded/(timespent>0.01?timespent:1.0); /* The average upload speed this far */ data->progress.ulspeed = @@ -324,10 +324,10 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* There's a callback set, so we call that instead of writing anything ourselves. This really is the way to go. */ result= data->set.fprogress(data->set.progress_client, - data->progress.size_dl, - data->progress.downloaded, - data->progress.size_ul, - data->progress.uploaded); + (double)data->progress.size_dl, + (double)data->progress.downloaded, + (double)data->progress.size_ul, + (double)data->progress.uploaded); if(result) failf(data, "Callback aborted"); return result; @@ -336,15 +336,15 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && (data->progress.ulspeed > 0)) { - ulestimate = data->progress.size_ul / data->progress.ulspeed; - ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; + ulestimate = (double)data->progress.size_ul / data->progress.ulspeed; + ulpercen = ((double)data->progress.uploaded / data->progress.size_ul)*100; } /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && (data->progress.dlspeed > 0)) { - dlestimate = data->progress.size_dl / data->progress.dlspeed; - dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; + dlestimate = (double)data->progress.size_dl / data->progress.dlspeed; + dlpercen = ((double)data->progress.downloaded / data->progress.size_dl)*100; } /* Now figure out which of them that is slower and use for the for @@ -378,7 +378,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Get the percentage of data transfered so far */ if(total_expected_transfer > 0) - total_percen=(double)(total_transfer/total_expected_transfer)*100; + total_percen=((double)total_transfer/total_expected_transfer)*100; fprintf(data->set.err, "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", -- cgit v1.2.1 From 1d5a914c1c0a82e0a633f559d6500027e3030253 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 11 Mar 2004 21:48:15 +0000 Subject: Made max5data() take a curl_off_t size as argument instead of double. Should make the progress meter more accurate for large files. Also made the sprintf usage in that function avoid floating point. --- lib/progress.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index d0421ca6c..23ac0defe 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -53,34 +53,36 @@ static void time2str(char *r, int t) /* The point of this function would be to return a string of the input data, but never longer than 5 columns. Add suffix k, M, G when suitable... */ -static char *max5data(double bytes, char *max5) +static char *max5data(curl_off_t bytes, char *max5) { #define ONE_KILOBYTE 1024 #define ONE_MEGABYTE (1024*1024) #define ONE_GIGABYTE (1024*1024*1024) if(bytes < 100000) { - sprintf(max5, "%5" FORMAT_OFF_T, (curl_off_t)bytes); - return max5; + sprintf(max5, "%5" FORMAT_OFF_T, bytes); } - if(bytes < (10000*ONE_KILOBYTE)) { - sprintf(max5, "%4" FORMAT_OFF_T "k", (curl_off_t)bytes/ONE_KILOBYTE); - return max5; + else if(bytes < (10000*ONE_KILOBYTE)) { + sprintf(max5, "%4" FORMAT_OFF_T "k", (curl_off_t)(bytes/ONE_KILOBYTE)); } - if(bytes < (100*ONE_MEGABYTE)) { + else if(bytes < (100*ONE_MEGABYTE)) { /* 'XX.XM' is good as long as we're less than 100 megs */ - sprintf(max5, "%4.1fM", bytes/ONE_MEGABYTE); - return max5; + sprintf(max5, "%2d.%0dM", + (int)(bytes/ONE_MEGABYTE), + (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); } #if SIZEOF_CURL_OFF_T > 4 - if((curl_off_t)bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { - sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)bytes/ONE_MEGABYTE); - return max5; + else if(bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { + sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); } - /* 10000 MB - 8589934587 GB !! */ - sprintf(max5, "%4.1fG", bytes/ONE_GIGABYTE); + else + /* 10000 MB - 8589934587 GB !! */ + sprintf(max5, "%2d.%0dG", + (int)(bytes/ONE_GIGABYTE), + (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); #else - sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)bytes/ONE_MEGABYTE); + else + sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); #endif return max5; @@ -259,7 +261,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* The average download speed this far */ data->progress.dlspeed = - data->progress.downloaded/(timespent>0.01?timespent:1.0); + data->progress.downloaded/(timespent>0.01?timespent:1); /* The average upload speed this far */ data->progress.ulspeed = -- cgit v1.2.1 From d44f3f84f8c8eb5951d47aeb2ea8caf120a5ec29 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 23 Mar 2004 11:43:34 +0000 Subject: Fixed the time fields no never get wider than 8 letters. They can now switch to a "days + hours" or even "just days" display if the time value is very large. I also switched several calculations over to fixed-point instead of the previous doubles. --- lib/progress.c | 122 +++++++++++++++++++++++++-------------------------------- 1 file changed, 53 insertions(+), 69 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 23ac0defe..947e46641 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -26,9 +26,6 @@ #include #include -/* 20000318 mgs - * later we use _scrsize to determine the screen width, this emx library - * function needs stdlib.h to be included */ #if defined(__EMX__) #include #endif @@ -36,19 +33,34 @@ #include #include "urldata.h" #include "sendf.h" - #include "progress.h" #define _MPRINTF_REPLACE /* use our functions only */ #include - -static void time2str(char *r, int t) +/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero + byte) */ +static void time2str(char *r, long t) { - int h = (t/3600); - int m = (t-(h*3600))/60; - int s = (t-(h*3600)-(m*60)); - sprintf(r,"%2d:%02d:%02d",h,m,s); + int h; + if(!t) { + strcpy(r, "--:--:--"); + return; + } + h = (t/3600); + if(h <= 99) { + int m = (t-(h*3600))/60; + int s = (t-(h*3600)-(m*60)); + sprintf(r, "%2d:%02d:%02d",h,m,s); + } + else { + /* this equals to more than 99 hours, switch to a more suitable output + format to fit within the limits. */ + if(h/24 <= 99) + sprintf(r, " %2dd %02dh", h/24, h-(h/24)*24); + else + sprintf(r, "%7dd", h/24); + } } /* The point of this function would be to return a string of the input data, @@ -195,44 +207,27 @@ void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size) data->progress.flags &= ~PGRS_UL_SIZE_KNOWN; } -/* EXAMPLE OUTPUT to follow: - - % Total % Received % Xferd Average Speed Time Curr. - Dload Upload Total Current Left Speed -100 12345 100 12345 100 12345 12345 12345 12:12:12 12:12:12 12:12:12 12345 - - */ - int Curl_pgrsUpdate(struct connectdata *conn) { struct timeval now; int result; - char max5[6][10]; - double dlpercen=0; - double ulpercen=0; - double total_percen=0; - + int dlpercen=0; + int ulpercen=0; + int total_percen=0; curl_off_t total_transfer; curl_off_t total_expected_transfer; - double timespent; - + long timespent; struct SessionHandle *data = conn->data; - int nowindex = data->progress.speeder_c% CURR_TIME; int checkindex; - int countindex; /* amount of seconds stored in the speeder array */ - char time_left[10]; char time_total[10]; - char time_current[10]; - - double ulestimate=0; - double dlestimate=0; - - double total_estimate; - + char time_spent[10]; + long ulestimate=0; + long dlestimate=0; + long total_estimate; if(data->progress.flags & PGRS_HIDE) ; /* We do enter this function even if we don't wanna see anything, since @@ -246,26 +241,26 @@ int Curl_pgrsUpdate(struct connectdata *conn) "\n", conn->resume_from); fprintf(data->set.err, - " %% Total %% Received %% Xferd Average Speed Time Curr.\n" - " Dload Upload Total Current Left Speed\n"); + " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" + " Dload Upload Total Spent Left Speed\n"); } data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ } now = Curl_tvnow(); /* what time is it */ - /* The exact time spent so far (from the start) */ - timespent = (double)Curl_tvdiff (now, data->progress.start)/1000; + /* The time spent so far (from the start) */ + timespent = Curl_tvdiff(now, data->progress.start)/1000; - data->progress.timespent = timespent; + data->progress.timespent = (double)timespent; /* The average download speed this far */ data->progress.dlspeed = - data->progress.downloaded/(timespent>0.01?timespent:1); + data->progress.downloaded/(timespent?timespent:1); /* The average upload speed this far */ data->progress.ulspeed = - data->progress.uploaded/(timespent>0.01?timespent:1); + data->progress.uploaded/(timespent?timespent:1); if(data->progress.lastshow == Curl_tvlong(now)) return 0; /* never update this more than once a second if the end isn't @@ -338,35 +333,25 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && (data->progress.ulspeed > 0)) { - ulestimate = (double)data->progress.size_ul / data->progress.ulspeed; - ulpercen = ((double)data->progress.uploaded / data->progress.size_ul)*100; + ulestimate = data->progress.size_ul / data->progress.ulspeed; + ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; } /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && (data->progress.dlspeed > 0)) { - dlestimate = (double)data->progress.size_dl / data->progress.dlspeed; - dlpercen = ((double)data->progress.downloaded / data->progress.size_dl)*100; + dlestimate = data->progress.size_dl / data->progress.dlspeed; + dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; } /* Now figure out which of them that is slower and use for the for total estimate! */ total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; - - /* If we have a total estimate, we can display that and the expected - time left */ - if(total_estimate > 0) { - time2str(time_left, (int)(total_estimate - data->progress.timespent)); - time2str(time_total, (int)total_estimate); - } - else { - /* otherwise we blank those times */ - strcpy(time_left, "--:--:--"); - strcpy(time_total, "--:--:--"); - } - /* The time spent so far is always known */ - time2str(time_current, (int)data->progress.timespent); + /* create the three time strings */ + time2str(time_left, total_estimate > 0?(total_estimate - timespent):0); + time2str(time_total, total_estimate); + time2str(time_spent, timespent); /* Get the total amount of data expected to get transfered */ total_expected_transfer = @@ -384,18 +369,17 @@ int Curl_pgrsUpdate(struct connectdata *conn) fprintf(data->set.err, "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", - (int)total_percen, /* total % */ + total_percen, /* 3 letters */ /* total % */ max5data(total_expected_transfer, max5[2]), /* total size */ - (int)dlpercen, /* rcvd % */ + dlpercen, /* 3 letters */ /* rcvd % */ max5data(data->progress.downloaded, max5[0]), /* rcvd size */ - (int)ulpercen, /* xfer % */ + ulpercen, /* 3 letters */ /* xfer % */ max5data(data->progress.uploaded, max5[1]), /* xfer size */ - - max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ - max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ - time_total, /* total time */ - time_current, /* current time */ - time_left, /* time left */ + max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ + max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ + time_total, /* 8 letters */ /* total time */ + time_spent, /* 8 letters */ /* time spent */ + time_left, /* 8 letters */ /* time left */ max5data(data->progress.current_speed, max5[5]) /* current speed */ ); -- cgit v1.2.1 From 0aa720fa262bdf76ba4fe7f13e4be54a8a96e4c3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 23 Mar 2004 11:46:31 +0000 Subject: it actually fits to make a NNNd NNh display so this can be used up to 999 days --- lib/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 947e46641..8de80ec74 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -56,8 +56,8 @@ static void time2str(char *r, long t) else { /* this equals to more than 99 hours, switch to a more suitable output format to fit within the limits. */ - if(h/24 <= 99) - sprintf(r, " %2dd %02dh", h/24, h-(h/24)*24); + if(h/24 <= 999) + sprintf(r, "%3dd %02dh", h/24, h-(h/24)*24); else sprintf(r, "%7dd", h/24); } -- cgit v1.2.1 From 1c652dfc5db7e77a56ef38a51d9190d214276e5d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 23 Mar 2004 15:01:19 +0000 Subject: added explicit typecasts to prevent compiler warnings on variable conversions --- lib/progress.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8de80ec74..0c15e4b3d 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -304,7 +304,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) span_ms=1; /* at least one millisecond MUST have passed */ /* Calculate the average speed the last 'countindex' seconds */ - data->progress.current_speed = + data->progress.current_speed = (curl_off_t) (data->progress.speeder[nowindex]- data->progress.speeder[checkindex])/((double)span_ms/1000); } @@ -333,15 +333,15 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && (data->progress.ulspeed > 0)) { - ulestimate = data->progress.size_ul / data->progress.ulspeed; - ulpercen = (data->progress.uploaded / data->progress.size_ul)*100; + ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); + ulpercen = (long)(data->progress.uploaded / data->progress.size_ul)*100; } /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && (data->progress.dlspeed > 0)) { - dlestimate = data->progress.size_dl / data->progress.dlspeed; - dlpercen = (data->progress.downloaded / data->progress.size_dl)*100; + dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); + dlpercen = (long)(data->progress.downloaded / data->progress.size_dl)*100; } /* Now figure out which of them that is slower and use for the for @@ -365,7 +365,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Get the percentage of data transfered so far */ if(total_expected_transfer > 0) - total_percen=((double)total_transfer/total_expected_transfer)*100; + total_percen=(int)(total_transfer/total_expected_transfer)*100; fprintf(data->set.err, "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", -- cgit v1.2.1 From 306ff5649ae01afe53416fd5bc24537109ae9a03 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 23 Mar 2004 15:06:14 +0000 Subject: made time2str() use longs internally instead to prevent compiler warnings when converting to ints --- lib/progress.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 0c15e4b3d..9a1cef7aa 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -42,24 +42,24 @@ byte) */ static void time2str(char *r, long t) { - int h; + long h; if(!t) { strcpy(r, "--:--:--"); return; } h = (t/3600); if(h <= 99) { - int m = (t-(h*3600))/60; - int s = (t-(h*3600)-(m*60)); - sprintf(r, "%2d:%02d:%02d",h,m,s); + long m = (t-(h*3600))/60; + long s = (t-(h*3600)-(m*60)); + sprintf(r, "%2ld:%02ld:%02ld",h,m,s); } else { /* this equals to more than 99 hours, switch to a more suitable output format to fit within the limits. */ if(h/24 <= 999) - sprintf(r, "%3dd %02dh", h/24, h-(h/24)*24); + sprintf(r, "%3ldd %02ldh", h/24, h-(h/24)*24); else - sprintf(r, "%7dd", h/24); + sprintf(r, "%7ldd", h/24); } } -- cgit v1.2.1 From 7ba4d3464fca05266a9d62ad332658a20fb74ae7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 2 Apr 2004 07:32:03 +0000 Subject: Dirk Manske's feedback: * bring back subsecond resolution to CURLINFO_TOTAL_TIME * Fix the Curl_pgrsDone() so that the final progress update is shown properly --- lib/progress.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 9a1cef7aa..8c7ef3558 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -117,13 +117,12 @@ static char *max5data(curl_off_t bytes, char *max5) void Curl_pgrsDone(struct connectdata *conn) { struct SessionHandle *data = conn->data; - if(!(data->progress.flags & PGRS_HIDE)) { - data->progress.lastshow=0; - Curl_pgrsUpdate(conn); /* the final (forced) update */ - if(!data->progress.callback) - /* only output if we don't use progress callback */ - fprintf(data->set.err, "\n"); - } + data->progress.lastshow=0; + Curl_pgrsUpdate(conn); /* the final (forced) update */ + if(!(data->progress.flags & PGRS_HIDE) && + !data->progress.callback) + /* only output if we don't use a progress callback and we're not hidden */ + fprintf(data->set.err, "\n"); } /* reset all times except redirect */ @@ -250,9 +249,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) now = Curl_tvnow(); /* what time is it */ /* The time spent so far (from the start) */ - timespent = Curl_tvdiff(now, data->progress.start)/1000; - - data->progress.timespent = (double)timespent; + data->progress.timespent = Curl_tvdiff(now, data->progress.start)/1000.0; + timespent = (long)data->progress.timespent; /* The average download speed this far */ data->progress.dlspeed = -- cgit v1.2.1 From 2fd463e979ca57c07be4c54e945c33de8651c17c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 9 Apr 2004 09:36:31 +0000 Subject: Dirk Manske increased the resolution for what the CURLINFO_*_TIME return. --- lib/progress.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8c7ef3558..55bc3ceec 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -148,26 +148,26 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) case TIMER_NAMELOOKUP: data->progress.t_nslookup = - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; + Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); break; case TIMER_CONNECT: data->progress.t_connect = - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; + Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); break; case TIMER_PRETRANSFER: data->progress.t_pretransfer = - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; + Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); break; case TIMER_STARTTRANSFER: data->progress.t_starttransfer = - (double)Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle)/1000.0; + Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); break; case TIMER_POSTRANSFER: /* this is the normal end-of-transfer thing */ break; case TIMER_REDIRECT: data->progress.t_redirect = - (double)Curl_tvdiff(Curl_tvnow(), data->progress.start)/1000.0; + Curl_tvdiff_secs(Curl_tvnow(), data->progress.start); break; } } @@ -249,8 +249,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) now = Curl_tvnow(); /* what time is it */ /* The time spent so far (from the start) */ - data->progress.timespent = Curl_tvdiff(now, data->progress.start)/1000.0; - timespent = (long)data->progress.timespent; + data->progress.timespent = Curl_tvdiff_secs(now, data->progress.start); + timespent = (long)data->progress.timespent*1000.0; /* The average download speed this far */ data->progress.dlspeed = -- cgit v1.2.1 From 58879458288bb71b82860f58fc579d573879b526 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 19 Apr 2004 07:18:26 +0000 Subject: Gisle Vanem corrected a mistake in a recent progress fix --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 55bc3ceec..e7e5728ef 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -250,7 +250,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* The time spent so far (from the start) */ data->progress.timespent = Curl_tvdiff_secs(now, data->progress.start); - timespent = (long)data->progress.timespent*1000.0; + timespent = (long)data->progress.timespent; /* The average download speed this far */ data->progress.dlspeed = -- cgit v1.2.1 From caf7854a3ce16933557ad6ff33e6b210a2109b48 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 5 May 2004 07:45:21 +0000 Subject: if the values allow it, avoid floting point math for the current speed --- lib/progress.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index e7e5728ef..51333aff1 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -301,10 +301,21 @@ int Curl_pgrsUpdate(struct connectdata *conn) if(0 == span_ms) span_ms=1; /* at least one millisecond MUST have passed */ - /* Calculate the average speed the last 'countindex' seconds */ - data->progress.current_speed = (curl_off_t) - (data->progress.speeder[nowindex]- - data->progress.speeder[checkindex])/((double)span_ms/1000); + /* Calculate the average speed the last 'span_ms' milliseconds */ + { + curl_off_t amount = data->progress.speeder[nowindex]- + data->progress.speeder[checkindex]; + + if(amount > 0xffffffff/1000) + /* the 'amount' value is bigger than would fit in 32 bits if + multiplied with 1000, so we use the double math for this */ + data->progress.current_speed = (curl_off_t) + (amount/(span_ms/1000.0)); + else + /* the 'amount' value is small enough to fit within 32 bits even + when multiplied with 1000 */ + data->progress.current_speed = amount*1000/span_ms; + } } else /* the first second we use the main average */ -- cgit v1.2.1 From 6062ac7c37c9290f1c4951d6b7bfc02ac3cadefe Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 5 May 2004 08:43:23 +0000 Subject: made the progress meter display not overflow even if _very_ large files are transfered. The maximum size we support now is 8 exabytes, which equals to 8192 petabytes... --- lib/progress.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 51333aff1..98c101096 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -68,8 +68,10 @@ static void time2str(char *r, long t) static char *max5data(curl_off_t bytes, char *max5) { #define ONE_KILOBYTE 1024 -#define ONE_MEGABYTE (1024*1024) -#define ONE_GIGABYTE (1024*1024*1024) +#define ONE_MEGABYTE (1024* ONE_KILOBYTE) +#define ONE_GIGABYTE (1024* ONE_MEGABYTE) +#define ONE_TERRABYTE ((curl_off_t)1024* ONE_GIGABYTE) +#define ONE_PETABYTE ((curl_off_t)1024* ONE_TERRABYTE) if(bytes < 100000) { sprintf(max5, "%5" FORMAT_OFF_T, bytes); @@ -84,14 +86,31 @@ static char *max5data(curl_off_t bytes, char *max5) (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); } #if SIZEOF_CURL_OFF_T > 4 - else if(bytes < ((curl_off_t)10000*ONE_MEGABYTE)) { + else if(bytes < ( (curl_off_t)10000*ONE_MEGABYTE)) + /* 'XXXXM' is good until we're at 10000MB or above */ sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); - } - else - /* 10000 MB - 8589934587 GB !! */ + + else if(bytes < (curl_off_t)100*ONE_GIGABYTE) + /* 10000 MB - 100 GB, we show it as XX.XG */ sprintf(max5, "%2d.%0dG", (int)(bytes/ONE_GIGABYTE), (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); + + else if(bytes < (curl_off_t)10000 * ONE_GIGABYTE) + /* up to 10000GB, display without decimal: XXXXG */ + sprintf(max5, "%4dG", (int)(bytes/ONE_GIGABYTE)); + + else if(bytes < (curl_off_t)10000 * ONE_TERRABYTE) + /* up to 10000TB, display without decimal: XXXXT */ + sprintf(max5, "%4dT", (int)(bytes/ONE_TERRABYTE)); + else { + /* up to 10000PB, display without decimal: XXXXP */ + sprintf(max5, "%4dP", (int)(bytes/ONE_PETABYTE)); + + /* 16384 petabytes (16 exabytes) is maximum a 64 bit number can hold, + but this type is signed so 8192PB will be max.*/ + } + #else else sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); -- cgit v1.2.1 From 3f21fe60fc5d3662fdfd9165470bf8f51231ef94 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 5 May 2004 13:44:44 +0000 Subject: Gisle fixed the percentage to work, I adjusted it slightly to not as easily overflow on 32bit filesize-systems --- lib/progress.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 98c101096..d93d03f4c 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -362,14 +362,16 @@ int Curl_pgrsUpdate(struct connectdata *conn) if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && (data->progress.ulspeed > 0)) { ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); - ulpercen = (long)(data->progress.uploaded / data->progress.size_ul)*100; + ulpercen = (long)(100*(data->progress.uploaded/100) / + (data->progress.size_ul/100) ); } /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && (data->progress.dlspeed > 0)) { dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); - dlpercen = (long)(data->progress.downloaded / data->progress.size_dl)*100; + dlpercen = (long)(100*(data->progress.downloaded/100) / + (data->progress.size_dl/100)); } /* Now figure out which of them that is slower and use for the for @@ -393,7 +395,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Get the percentage of data transfered so far */ if(total_expected_transfer > 0) - total_percen=(int)(total_transfer/total_expected_transfer)*100; + total_percen=(int)(100*(total_transfer/100) / + (total_expected_transfer/100) ); fprintf(data->set.err, "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", -- cgit v1.2.1 From 9cf04dff6a31906b53e2cbc3308dcdb6c24105fa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 5 May 2004 14:22:46 +0000 Subject: hm, avoid division by zero more carefully with that new percentage math --- lib/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index d93d03f4c..7ff1dd004 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -360,7 +360,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && - (data->progress.ulspeed > 0)) { + (data->progress.ulspeed > 100)) { ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); ulpercen = (long)(100*(data->progress.uploaded/100) / (data->progress.size_ul/100) ); @@ -368,7 +368,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && - (data->progress.dlspeed > 0)) { + (data->progress.dlspeed > 100)) { dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); dlpercen = (long)(100*(data->progress.downloaded/100) / (data->progress.size_dl/100)); @@ -394,7 +394,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) total_transfer = data->progress.downloaded + data->progress.uploaded; /* Get the percentage of data transfered so far */ - if(total_expected_transfer > 0) + if(total_expected_transfer > 100) total_percen=(int)(100*(total_transfer/100) / (total_expected_transfer/100) ); -- cgit v1.2.1 From 60f9450594758307f0c9b2c99babafbbad4ef3e6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 20 May 2004 20:35:42 +0000 Subject: calculate upload and download speed using doubles to keep precision. deleted trailing whitespace --- lib/progress.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 7ff1dd004..01ed8ac37 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -1,8 +1,8 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -10,7 +10,7 @@ * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. - * + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. @@ -119,7 +119,7 @@ static char *max5data(curl_off_t bytes, char *max5) return max5; } -/* +/* New proposed interface, 9th of February 2000: @@ -272,15 +272,17 @@ int Curl_pgrsUpdate(struct connectdata *conn) timespent = (long)data->progress.timespent; /* The average download speed this far */ - data->progress.dlspeed = - data->progress.downloaded/(timespent?timespent:1); + data->progress.dlspeed = (curl_off_t) + (data->progress.downloaded/(data->progress.timespent>0? + data->progress.timespent:1)); /* The average upload speed this far */ - data->progress.ulspeed = - data->progress.uploaded/(timespent?timespent:1); + data->progress.ulspeed = (curl_off_t) + (data->progress.uploaded/(data->progress.timespent>0? + data->progress.timespent:1)); if(data->progress.lastshow == Curl_tvlong(now)) - return 0; /* never update this more than once a second if the end isn't + return 0; /* never update this more than once a second if the end isn't reached */ data->progress.lastshow = now.tv_sec; @@ -373,7 +375,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) dlpercen = (long)(100*(data->progress.downloaded/100) / (data->progress.size_dl/100)); } - + /* Now figure out which of them that is slower and use for the for total estimate! */ total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; @@ -384,12 +386,12 @@ int Curl_pgrsUpdate(struct connectdata *conn) time2str(time_spent, timespent); /* Get the total amount of data expected to get transfered */ - total_expected_transfer = + total_expected_transfer = (data->progress.flags & PGRS_UL_SIZE_KNOWN? data->progress.size_ul:data->progress.uploaded)+ (data->progress.flags & PGRS_DL_SIZE_KNOWN? data->progress.size_dl:data->progress.downloaded); - + /* We have transfered this much so far */ total_transfer = data->progress.downloaded + data->progress.uploaded; -- cgit v1.2.1 From aadc797225906ba02fab4e1ad29b484acd4751b3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 21 May 2004 12:23:53 +0000 Subject: quickfix to avoid division by zero, possibly we should go over all of these once and for all --- lib/progress.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 01ed8ac37..a36def75c 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -362,7 +362,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && - (data->progress.ulspeed > 100)) { + (data->progress.ulspeed>0) && + (data->progress.size_ul > 100) ) { ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); ulpercen = (long)(100*(data->progress.uploaded/100) / (data->progress.size_ul/100) ); @@ -370,7 +371,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && - (data->progress.dlspeed > 100)) { + (data->progress.dlspeed>0) && + (data->progress.size_dl>100)) { dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); dlpercen = (long)(100*(data->progress.downloaded/100) / (data->progress.size_dl/100)); -- cgit v1.2.1 From feb2dd283533f842c9b6e4cc2fcc7fd35638d5a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 11:54:11 +0000 Subject: Replaced all uses of sprintf() with the safer snprintf(). It is just a precaution to prevent mistakes to lead to buffer overflows. --- lib/progress.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index a36def75c..27cde9c38 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -51,20 +51,21 @@ static void time2str(char *r, long t) if(h <= 99) { long m = (t-(h*3600))/60; long s = (t-(h*3600)-(m*60)); - sprintf(r, "%2ld:%02ld:%02ld",h,m,s); + snprintf(r, 9, "%2ld:%02ld:%02ld",h,m,s); } else { /* this equals to more than 99 hours, switch to a more suitable output format to fit within the limits. */ if(h/24 <= 999) - sprintf(r, "%3ldd %02ldh", h/24, h-(h/24)*24); + snprintf(r, 9, "%3ldd %02ldh", h/24, h-(h/24)*24); else - sprintf(r, "%7ldd", h/24); + snprintf(r, 9, "%7ldd", h/24); } } /* The point of this function would be to return a string of the input data, - but never longer than 5 columns. Add suffix k, M, G when suitable... */ + but never longer than 5 columns (+ one zero byte). + Add suffix k, M, G when suitable... */ static char *max5data(curl_off_t bytes, char *max5) { #define ONE_KILOBYTE 1024 @@ -74,38 +75,38 @@ static char *max5data(curl_off_t bytes, char *max5) #define ONE_PETABYTE ((curl_off_t)1024* ONE_TERRABYTE) if(bytes < 100000) { - sprintf(max5, "%5" FORMAT_OFF_T, bytes); + snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes); } else if(bytes < (10000*ONE_KILOBYTE)) { - sprintf(max5, "%4" FORMAT_OFF_T "k", (curl_off_t)(bytes/ONE_KILOBYTE)); + snprintf(max5, 6, "%4" FORMAT_OFF_T "k", (curl_off_t)(bytes/ONE_KILOBYTE)); } else if(bytes < (100*ONE_MEGABYTE)) { /* 'XX.XM' is good as long as we're less than 100 megs */ - sprintf(max5, "%2d.%0dM", - (int)(bytes/ONE_MEGABYTE), - (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); + snprintf(max5, 6, "%2d.%0dM", + (int)(bytes/ONE_MEGABYTE), + (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); } #if SIZEOF_CURL_OFF_T > 4 else if(bytes < ( (curl_off_t)10000*ONE_MEGABYTE)) /* 'XXXXM' is good until we're at 10000MB or above */ - sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); + snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); else if(bytes < (curl_off_t)100*ONE_GIGABYTE) /* 10000 MB - 100 GB, we show it as XX.XG */ - sprintf(max5, "%2d.%0dG", - (int)(bytes/ONE_GIGABYTE), - (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); + snprintf(max5, 6, "%2d.%0dG", + (int)(bytes/ONE_GIGABYTE), + (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); else if(bytes < (curl_off_t)10000 * ONE_GIGABYTE) /* up to 10000GB, display without decimal: XXXXG */ - sprintf(max5, "%4dG", (int)(bytes/ONE_GIGABYTE)); + snprintf(max5, 6, "%4dG", (int)(bytes/ONE_GIGABYTE)); else if(bytes < (curl_off_t)10000 * ONE_TERRABYTE) /* up to 10000TB, display without decimal: XXXXT */ - sprintf(max5, "%4dT", (int)(bytes/ONE_TERRABYTE)); + snprintf(max5, 6, "%4dT", (int)(bytes/ONE_TERRABYTE)); else { /* up to 10000PB, display without decimal: XXXXP */ - sprintf(max5, "%4dP", (int)(bytes/ONE_PETABYTE)); + snprintf(max5, 6, "%4dP", (int)(bytes/ONE_PETABYTE)); /* 16384 petabytes (16 exabytes) is maximum a 64 bit number can hold, but this type is signed so 8192PB will be max.*/ @@ -113,7 +114,7 @@ static char *max5data(curl_off_t bytes, char *max5) #else else - sprintf(max5, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); + snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); #endif return max5; -- cgit v1.2.1 From 18dc8fbc262a411e71b5665adc322f98fd7636a1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 1 Jul 2004 07:28:36 +0000 Subject: typecast to int when the variable is int! --- lib/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 27cde9c38..9d354679c 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -366,7 +366,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) (data->progress.ulspeed>0) && (data->progress.size_ul > 100) ) { ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); - ulpercen = (long)(100*(data->progress.uploaded/100) / + ulpercen = (int)(100*(data->progress.uploaded/100) / (data->progress.size_ul/100) ); } @@ -375,7 +375,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) (data->progress.dlspeed>0) && (data->progress.size_dl>100)) { dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); - dlpercen = (long)(100*(data->progress.downloaded/100) / + dlpercen = (int)(100*(data->progress.downloaded/100) / (data->progress.size_dl/100)); } -- cgit v1.2.1 From aedadfc77907fe221a0e4d11f02329d2d841f5de Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 2 Jul 2004 11:56:26 +0000 Subject: explicit typecasts to double to prevent warnings about implicit conversions that might lose accuracy --- lib/progress.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 9d354679c..c6517ad0a 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -274,13 +274,13 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* The average download speed this far */ data->progress.dlspeed = (curl_off_t) - (data->progress.downloaded/(data->progress.timespent>0? - data->progress.timespent:1)); + ((double)data->progress.downloaded/ + (data->progress.timespent>0?data->progress.timespent:1)); /* The average upload speed this far */ data->progress.ulspeed = (curl_off_t) - (data->progress.uploaded/(data->progress.timespent>0? - data->progress.timespent:1)); + ((double)data->progress.uploaded/ + (data->progress.timespent>0?data->progress.timespent:1)); if(data->progress.lastshow == Curl_tvlong(now)) return 0; /* never update this more than once a second if the end isn't @@ -332,7 +332,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* the 'amount' value is bigger than would fit in 32 bits if multiplied with 1000, so we use the double math for this */ data->progress.current_speed = (curl_off_t) - (amount/(span_ms/1000.0)); + ((double)amount/(span_ms/1000.0)); else /* the 'amount' value is small enough to fit within 32 bits even when multiplied with 1000 */ -- cgit v1.2.1 From 9dbd6659dc9611110bc48614ee22e40b3935576f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 10 Aug 2004 06:41:13 +0000 Subject: more typecasts to please picky compilers --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index c6517ad0a..7294894a7 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -332,7 +332,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* the 'amount' value is bigger than would fit in 32 bits if multiplied with 1000, so we use the double math for this */ data->progress.current_speed = (curl_off_t) - ((double)amount/(span_ms/1000.0)); + ((double)amount/((double)span_ms/1000.0)); else /* the 'amount' value is small enough to fit within 32 bits even when multiplied with 1000 */ -- cgit v1.2.1 From 39af394a1c3ae1d8ac71ad263a7c524988702c2e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 6 Oct 2004 07:50:18 +0000 Subject: removed tabs and trailing whitespace from source --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 7294894a7..36be56ea4 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -256,7 +256,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) if (!data->progress.callback) { if(conn->resume_from) fprintf(data->set.err, - "** Resuming transfer from byte position %" FORMAT_OFF_T + "** Resuming transfer from byte position %" FORMAT_OFF_T "\n", conn->resume_from); fprintf(data->set.err, -- cgit v1.2.1 From fe46572f2b6c9380feabb3a22bff349f13456531 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 8 Oct 2004 08:16:02 +0000 Subject: prevent warning with comparison between signed and unsigned --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 36be56ea4..55f316acc 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -328,7 +328,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) curl_off_t amount = data->progress.speeder[nowindex]- data->progress.speeder[checkindex]; - if(amount > 0xffffffff/1000) + if(amount > 4294967 /* 0xffffffff/1000 */) /* the 'amount' value is bigger than would fit in 32 bits if multiplied with 1000, so we use the double math for this */ data->progress.current_speed = (curl_off_t) -- cgit v1.2.1 From ffe17a8197e73b791f6b1609bdcdc3a40818acdc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 26 Nov 2004 14:33:13 +0000 Subject: As reported in Mandrake's bug tracker bug 12289 (http://qa.mandrakesoft.com/show_bug.cgi?id=12289), curl would print a newline to "finish" the progress meter after each redirect and not only after a completed transfer. --- lib/progress.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 55f316acc..ce1adb805 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -139,10 +139,8 @@ void Curl_pgrsDone(struct connectdata *conn) struct SessionHandle *data = conn->data; data->progress.lastshow=0; Curl_pgrsUpdate(conn); /* the final (forced) update */ - if(!(data->progress.flags & PGRS_HIDE) && - !data->progress.callback) - /* only output if we don't use a progress callback and we're not hidden */ - fprintf(data->set.err, "\n"); + + data->progress.speeder_c = 0; /* reset the progress meter display */ } /* reset all times except redirect */ -- cgit v1.2.1 From b7eeb6e67fca686f840eacd6b8394edb58b07482 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 7 Sep 2006 21:49:20 +0000 Subject: Major overhaul introducing http pipelining support and shared connection cache within the multi handle. --- lib/progress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index ce1adb805..2c449362d 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -252,11 +252,11 @@ int Curl_pgrsUpdate(struct connectdata *conn) even when not displayed! */ else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if (!data->progress.callback) { - if(conn->resume_from) + if(data->reqdata.resume_from) fprintf(data->set.err, "** Resuming transfer from byte position %" FORMAT_OFF_T "\n", - conn->resume_from); + data->reqdata.resume_from); fprintf(data->set.err, " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" " Dload Upload Total Spent Left Speed\n"); -- cgit v1.2.1 From 772a985dc3318214443ddd2ad6541d520f089368 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 27 Oct 2006 03:47:57 +0000 Subject: Update copyright year, since the file has been modified --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 2c449362d..5ba829a03 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From dbaf4f93615b0ad1f34b38ec9def0b30496658d7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 10 Mar 2007 12:11:21 +0000 Subject: - Bryan Henderson introduces two things: 1) the progress callback gets called more frequently (at times) 2) libcurl *might* call the callback when it receives a signal --- lib/progress.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 5ba829a03..65bd4a7bb 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -280,9 +280,6 @@ int Curl_pgrsUpdate(struct connectdata *conn) ((double)data->progress.uploaded/ (data->progress.timespent>0?data->progress.timespent:1)); - if(data->progress.lastshow == Curl_tvlong(now)) - return 0; /* never update this more than once a second if the end isn't - reached */ data->progress.lastshow = now.tv_sec; /* Let's do the "current speed" thing, which should use the fastest @@ -359,6 +356,10 @@ int Curl_pgrsUpdate(struct connectdata *conn) return result; } + if(data->progress.lastshow == Curl_tvlong(now)) + return 0; /* never update this more than once a second if the end isn't + reached */ + /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && (data->progress.ulspeed>0) && -- cgit v1.2.1 From c8cd13337efcd45e918fab824b226e4ae6338ea0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 11 Mar 2007 09:11:29 +0000 Subject: reverted the pselect patch => http://curl.haxx.se/mail/lib-2007-03/0100.html --- lib/progress.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 65bd4a7bb..5ba829a03 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -280,6 +280,9 @@ int Curl_pgrsUpdate(struct connectdata *conn) ((double)data->progress.uploaded/ (data->progress.timespent>0?data->progress.timespent:1)); + if(data->progress.lastshow == Curl_tvlong(now)) + return 0; /* never update this more than once a second if the end isn't + reached */ data->progress.lastshow = now.tv_sec; /* Let's do the "current speed" thing, which should use the fastest @@ -356,10 +359,6 @@ int Curl_pgrsUpdate(struct connectdata *conn) return result; } - if(data->progress.lastshow == Curl_tvlong(now)) - return 0; /* never update this more than once a second if the end isn't - reached */ - /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && (data->progress.ulspeed>0) && -- cgit v1.2.1 From 072a8b2955e4a7cb4e6e278f1c8585697c513e1a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 19 Mar 2007 12:02:33 +0000 Subject: Bryan Henderson fixed the progress function so that it can get called more frequently allowing same calling frecuency for the client progress callback, while keeping the once a second frecuency for speed calculations and internal display of the transfer progress. --- lib/progress.c | 310 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 156 insertions(+), 154 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 5ba829a03..d59335971 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -246,24 +246,6 @@ int Curl_pgrsUpdate(struct connectdata *conn) long dlestimate=0; long total_estimate; - if(data->progress.flags & PGRS_HIDE) - ; /* We do enter this function even if we don't wanna see anything, since - this is were lots of the calculations are being made that will be used - even when not displayed! */ - else if(!(data->progress.flags & PGRS_HEADERS_OUT)) { - if (!data->progress.callback) { - if(data->reqdata.resume_from) - fprintf(data->set.err, - "** Resuming transfer from byte position %" FORMAT_OFF_T - "\n", - data->reqdata.resume_from); - fprintf(data->set.err, - " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" - " Dload Upload Total Spent Left Speed\n"); - } - data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ - } - now = Curl_tvnow(); /* what time is it */ /* The time spent so far (from the start) */ @@ -280,145 +262,165 @@ int Curl_pgrsUpdate(struct connectdata *conn) ((double)data->progress.uploaded/ (data->progress.timespent>0?data->progress.timespent:1)); - if(data->progress.lastshow == Curl_tvlong(now)) - return 0; /* never update this more than once a second if the end isn't - reached */ - data->progress.lastshow = now.tv_sec; - - /* Let's do the "current speed" thing, which should use the fastest - of the dl/ul speeds. Store the fasted speed at entry 'nowindex'. */ - data->progress.speeder[ nowindex ] = - data->progress.downloaded>data->progress.uploaded? - data->progress.downloaded:data->progress.uploaded; - - /* remember the exact time for this moment */ - data->progress.speeder_time [ nowindex ] = now; - - /* advance our speeder_c counter, which is increased every time we get - here and we expect it to never wrap as 2^32 is a lot of seconds! */ - data->progress.speeder_c++; - - /* figure out how many index entries of data we have stored in our speeder - array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of - transfer. Imagine, after one second we have filled in two entries, - after two seconds we've filled in three entries etc. */ - countindex = ((data->progress.speeder_c>=CURR_TIME)? - CURR_TIME:data->progress.speeder_c) - 1; - - /* first of all, we don't do this if there's no counted seconds yet */ - if(countindex) { - long span_ms; - - /* Get the index position to compare with the 'nowindex' position. - Get the oldest entry possible. While we have less than CURR_TIME - entries, the first entry will remain the oldest. */ - checkindex = (data->progress.speeder_c>=CURR_TIME)? - data->progress.speeder_c%CURR_TIME:0; - - /* Figure out the exact time for the time span */ - span_ms = Curl_tvdiff(now, - data->progress.speeder_time[checkindex]); - if(0 == span_ms) - span_ms=1; /* at least one millisecond MUST have passed */ - - /* Calculate the average speed the last 'span_ms' milliseconds */ - { - curl_off_t amount = data->progress.speeder[nowindex]- - data->progress.speeder[checkindex]; - - if(amount > 4294967 /* 0xffffffff/1000 */) - /* the 'amount' value is bigger than would fit in 32 bits if - multiplied with 1000, so we use the double math for this */ - data->progress.current_speed = (curl_off_t) - ((double)amount/((double)span_ms/1000.0)); - else - /* the 'amount' value is small enough to fit within 32 bits even - when multiplied with 1000 */ - data->progress.current_speed = amount*1000/span_ms; + /* Calculations done at most once a second, unless end is reached */ + if(data->progress.lastshow != Curl_tvlong(now)) { + + data->progress.lastshow = now.tv_sec; + + /* Let's do the "current speed" thing, which should use the fastest + of the dl/ul speeds. Store the fasted speed at entry 'nowindex'. */ + data->progress.speeder[ nowindex ] = + data->progress.downloaded>data->progress.uploaded? + data->progress.downloaded:data->progress.uploaded; + + /* remember the exact time for this moment */ + data->progress.speeder_time [ nowindex ] = now; + + /* advance our speeder_c counter, which is increased every time we get + here and we expect it to never wrap as 2^32 is a lot of seconds! */ + data->progress.speeder_c++; + + /* figure out how many index entries of data we have stored in our speeder + array. With N_ENTRIES filled in, we have about N_ENTRIES-1 seconds of + transfer. Imagine, after one second we have filled in two entries, + after two seconds we've filled in three entries etc. */ + countindex = ((data->progress.speeder_c>=CURR_TIME)? + CURR_TIME:data->progress.speeder_c) - 1; + + /* first of all, we don't do this if there's no counted seconds yet */ + if(countindex) { + long span_ms; + + /* Get the index position to compare with the 'nowindex' position. + Get the oldest entry possible. While we have less than CURR_TIME + entries, the first entry will remain the oldest. */ + checkindex = (data->progress.speeder_c>=CURR_TIME)? + data->progress.speeder_c%CURR_TIME:0; + + /* Figure out the exact time for the time span */ + span_ms = Curl_tvdiff(now, + data->progress.speeder_time[checkindex]); + if(0 == span_ms) + span_ms=1; /* at least one millisecond MUST have passed */ + + /* Calculate the average speed the last 'span_ms' milliseconds */ + { + curl_off_t amount = data->progress.speeder[nowindex]- + data->progress.speeder[checkindex]; + + if(amount > 4294967 /* 0xffffffff/1000 */) + /* the 'amount' value is bigger than would fit in 32 bits if + multiplied with 1000, so we use the double math for this */ + data->progress.current_speed = (curl_off_t) + ((double)amount/((double)span_ms/1000.0)); + else + /* the 'amount' value is small enough to fit within 32 bits even + when multiplied with 1000 */ + data->progress.current_speed = amount*1000/span_ms; + } + } + else + /* the first second we use the main average */ + data->progress.current_speed = + (data->progress.ulspeed>data->progress.dlspeed)? + data->progress.ulspeed:data->progress.dlspeed; + + } /* Calculations end */ + + if(!(data->progress.flags & PGRS_HIDE)) { + + /* progress meter has not been shut off */ + + if(data->set.fprogress) { + /* There's a callback set, so we call that instead of writing + anything ourselves. This really is the way to go. */ + result= data->set.fprogress(data->set.progress_client, + (double)data->progress.size_dl, + (double)data->progress.downloaded, + (double)data->progress.size_ul, + (double)data->progress.uploaded); + if(result) + failf(data, "Callback aborted"); + return result; } - } - else - /* the first second we use the main average */ - data->progress.current_speed = - (data->progress.ulspeed>data->progress.dlspeed)? - data->progress.ulspeed:data->progress.dlspeed; - - if(data->progress.flags & PGRS_HIDE) - return 0; - - else if(data->set.fprogress) { - /* There's a callback set, so we call that instead of writing - anything ourselves. This really is the way to go. */ - result= data->set.fprogress(data->set.progress_client, - (double)data->progress.size_dl, - (double)data->progress.downloaded, - (double)data->progress.size_ul, - (double)data->progress.uploaded); - if(result) - failf(data, "Callback aborted"); - return result; - } - /* Figure out the estimated time of arrival for the upload */ - if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && - (data->progress.ulspeed>0) && - (data->progress.size_ul > 100) ) { - ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); - ulpercen = (int)(100*(data->progress.uploaded/100) / - (data->progress.size_ul/100) ); - } + /* If there's no external callback set, use internal code to show progress */ - /* ... and the download */ - if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && - (data->progress.dlspeed>0) && - (data->progress.size_dl>100)) { - dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); - dlpercen = (int)(100*(data->progress.downloaded/100) / - (data->progress.size_dl/100)); - } + if(!(data->progress.flags & PGRS_HEADERS_OUT)) { + if(data->reqdata.resume_from) { + fprintf(data->set.err, + "** Resuming transfer from byte position %" FORMAT_OFF_T + "\n", + data->reqdata.resume_from); + } + fprintf(data->set.err, + " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" + " Dload Upload Total Spent Left Speed\n"); + data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ + } + + /* Figure out the estimated time of arrival for the upload */ + if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && + (data->progress.ulspeed>0) && + (data->progress.size_ul > 100) ) { + ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); + ulpercen = (int)(100*(data->progress.uploaded/100) / + (data->progress.size_ul/100) ); + } - /* Now figure out which of them that is slower and use for the for - total estimate! */ - total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; - - /* create the three time strings */ - time2str(time_left, total_estimate > 0?(total_estimate - timespent):0); - time2str(time_total, total_estimate); - time2str(time_spent, timespent); - - /* Get the total amount of data expected to get transfered */ - total_expected_transfer = - (data->progress.flags & PGRS_UL_SIZE_KNOWN? - data->progress.size_ul:data->progress.uploaded)+ - (data->progress.flags & PGRS_DL_SIZE_KNOWN? - data->progress.size_dl:data->progress.downloaded); - - /* We have transfered this much so far */ - total_transfer = data->progress.downloaded + data->progress.uploaded; - - /* Get the percentage of data transfered so far */ - if(total_expected_transfer > 100) - total_percen=(int)(100*(total_transfer/100) / - (total_expected_transfer/100) ); - - fprintf(data->set.err, - "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", - total_percen, /* 3 letters */ /* total % */ - max5data(total_expected_transfer, max5[2]), /* total size */ - dlpercen, /* 3 letters */ /* rcvd % */ - max5data(data->progress.downloaded, max5[0]), /* rcvd size */ - ulpercen, /* 3 letters */ /* xfer % */ - max5data(data->progress.uploaded, max5[1]), /* xfer size */ - max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ - max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ - time_total, /* 8 letters */ /* total time */ - time_spent, /* 8 letters */ /* time spent */ - time_left, /* 8 letters */ /* time left */ - max5data(data->progress.current_speed, max5[5]) /* current speed */ - ); - - /* we flush the output stream to make it appear as soon as possible */ - fflush(data->set.err); + /* ... and the download */ + if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && + (data->progress.dlspeed>0) && + (data->progress.size_dl>100)) { + dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); + dlpercen = (int)(100*(data->progress.downloaded/100) / + (data->progress.size_dl/100)); + } + + /* Now figure out which of them that is slower and use for the for + total estimate! */ + total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; + + /* create the three time strings */ + time2str(time_left, total_estimate > 0?(total_estimate - timespent):0); + time2str(time_total, total_estimate); + time2str(time_spent, timespent); + + /* Get the total amount of data expected to get transfered */ + total_expected_transfer = + (data->progress.flags & PGRS_UL_SIZE_KNOWN? + data->progress.size_ul:data->progress.uploaded)+ + (data->progress.flags & PGRS_DL_SIZE_KNOWN? + data->progress.size_dl:data->progress.downloaded); + + /* We have transfered this much so far */ + total_transfer = data->progress.downloaded + data->progress.uploaded; + + /* Get the percentage of data transfered so far */ + if(total_expected_transfer > 100) + total_percen=(int)(100*(total_transfer/100) / + (total_expected_transfer/100) ); + + fprintf(data->set.err, + "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", + total_percen, /* 3 letters */ /* total % */ + max5data(total_expected_transfer, max5[2]), /* total size */ + dlpercen, /* 3 letters */ /* rcvd % */ + max5data(data->progress.downloaded, max5[0]), /* rcvd size */ + ulpercen, /* 3 letters */ /* xfer % */ + max5data(data->progress.uploaded, max5[1]), /* xfer size */ + max5data(data->progress.dlspeed, max5[3]), /* avrg dl speed */ + max5data(data->progress.ulspeed, max5[4]), /* avrg ul speed */ + time_total, /* 8 letters */ /* total time */ + time_spent, /* 8 letters */ /* time spent */ + time_left, /* 8 letters */ /* time left */ + max5data(data->progress.current_speed, max5[5]) /* current speed */ + ); + + /* we flush the output stream to make it appear as soon as possible */ + fflush(data->set.err); + + } return 0; } -- cgit v1.2.1 From 34afb0b2576c6220b16c1b4479fd5b9015a97113 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 23 Mar 2007 04:23:53 +0000 Subject: Change spelling, ONE_TERRABYTE -> ONE_TERABYTE Shave off a couple of function calls in the part of Curl_pgrsUpdate() which is always executed when called. Fix a couple of comments. --- lib/progress.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index d59335971..9d9096069 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -71,8 +71,8 @@ static char *max5data(curl_off_t bytes, char *max5) #define ONE_KILOBYTE 1024 #define ONE_MEGABYTE (1024* ONE_KILOBYTE) #define ONE_GIGABYTE (1024* ONE_MEGABYTE) -#define ONE_TERRABYTE ((curl_off_t)1024* ONE_GIGABYTE) -#define ONE_PETABYTE ((curl_off_t)1024* ONE_TERRABYTE) +#define ONE_TERABYTE ((curl_off_t)1024* ONE_GIGABYTE) +#define ONE_PETABYTE ((curl_off_t)1024* ONE_TERABYTE) if(bytes < 100000) { snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes); @@ -101,9 +101,9 @@ static char *max5data(curl_off_t bytes, char *max5) /* up to 10000GB, display without decimal: XXXXG */ snprintf(max5, 6, "%4dG", (int)(bytes/ONE_GIGABYTE)); - else if(bytes < (curl_off_t)10000 * ONE_TERRABYTE) + else if(bytes < (curl_off_t)10000 * ONE_TERABYTE) /* up to 10000TB, display without decimal: XXXXT */ - snprintf(max5, 6, "%4dT", (int)(bytes/ONE_TERRABYTE)); + snprintf(max5, 6, "%4dT", (int)(bytes/ONE_TERABYTE)); else { /* up to 10000PB, display without decimal: XXXXP */ snprintf(max5, 6, "%4dP", (int)(bytes/ONE_PETABYTE)); @@ -249,7 +249,9 @@ int Curl_pgrsUpdate(struct connectdata *conn) now = Curl_tvnow(); /* what time is it */ /* The time spent so far (from the start) */ - data->progress.timespent = Curl_tvdiff_secs(now, data->progress.start); + data->progress.timespent = + (double)(now.tv_sec - data->progress.start.tv_sec) + + (double)(now.tv_usec - data->progress.start.tv_usec)/1000000.0; timespent = (long)data->progress.timespent; /* The average download speed this far */ @@ -263,12 +265,12 @@ int Curl_pgrsUpdate(struct connectdata *conn) (data->progress.timespent>0?data->progress.timespent:1)); /* Calculations done at most once a second, unless end is reached */ - if(data->progress.lastshow != Curl_tvlong(now)) { + if(data->progress.lastshow != (long)now.tv_sec) { data->progress.lastshow = now.tv_sec; /* Let's do the "current speed" thing, which should use the fastest - of the dl/ul speeds. Store the fasted speed at entry 'nowindex'. */ + of the dl/ul speeds. Store the faster speed at entry 'nowindex'. */ data->progress.speeder[ nowindex ] = data->progress.downloaded>data->progress.uploaded? data->progress.downloaded:data->progress.uploaded; @@ -377,7 +379,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) (data->progress.size_dl/100)); } - /* Now figure out which of them that is slower and use for the for + /* Now figure out which of them is slower and use that one for the total estimate! */ total_estimate = ulestimate>dlestimate?ulestimate:dlestimate; -- cgit v1.2.1 From 8e719e3ef5ad90b7f8ad9c82a853df1afb23afd7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 18 Apr 2007 20:02:41 +0000 Subject: - Prevent the internal progress meter from updating more frequently than once per second. --- lib/progress.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 9d9096069..ad09938f8 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -245,6 +245,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) long ulestimate=0; long dlestimate=0; long total_estimate; + bool shownow=FALSE; now = Curl_tvnow(); /* what time is it */ @@ -266,6 +267,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Calculations done at most once a second, unless end is reached */ if(data->progress.lastshow != (long)now.tv_sec) { + shownow = TRUE; data->progress.lastshow = now.tv_sec; @@ -346,7 +348,12 @@ int Curl_pgrsUpdate(struct connectdata *conn) return result; } - /* If there's no external callback set, use internal code to show progress */ + if(!shownow) + /* only show the internal progress meter once per second */ + return 0; + + /* If there's no external callback set, use internal code to show + progress */ if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if(data->reqdata.resume_from) { @@ -422,7 +429,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* we flush the output stream to make it appear as soon as possible */ fflush(data->set.err); - } + } /* !(data->progress.flags & PGRS_HIDE) */ return 0; } -- cgit v1.2.1 From 13648f8ccda6f99674ac407640474634e856804c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 24 Nov 2007 23:16:55 +0000 Subject: struct HandleData is now called struct SingleRequest, and is only for data that is inited at the start of the DO action. I removed the Curl_transfer_keeper struct completely, and I had to move out a few struct members (that had to be set before DO or used after DONE) to the UrlState struct. The SingleRequest struct is accessed with SessionHandle->req. One of the biggest reasons for doing this was the bunch of duplicate struct members in HandleData and Curl_transfer_keeper since it was really messy to keep track of two variables with the same name and basically the same purpose! --- lib/progress.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index ad09938f8..f473e8227 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -356,11 +356,10 @@ int Curl_pgrsUpdate(struct connectdata *conn) progress */ if(!(data->progress.flags & PGRS_HEADERS_OUT)) { - if(data->reqdata.resume_from) { + if(data->state.resume_from) { fprintf(data->set.err, - "** Resuming transfer from byte position %" FORMAT_OFF_T - "\n", - data->reqdata.resume_from); + "** Resuming transfer from byte position %" FORMAT_OFF_T "\n", + data->state.resume_from); } fprintf(data->set.err, " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" -- cgit v1.2.1 From 7c648782bc7c97be81c619acd8598c38b59c5832 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 3 Jul 2008 06:56:03 +0000 Subject: Introcuding a new timestamp for curl_easy_getinfo(): CURLINFO_APPCONNECT_TIME. This is set with the "application layer" handshake/connection is completed (typically SSL, TLS or SSH). By using this you can figure out the application layer's own connect time. You can extract the time stamp using curl's -w option and the new variable named 'time_appconnect'. This feature was sponsored by Lenny Rachitsky at NeuStar. --- lib/progress.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index f473e8227..2956d1a99 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -172,6 +172,10 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) data->progress.t_connect = Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); break; + case TIMER_APPCONNECT: + data->progress.t_appconnect = + Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); + break; case TIMER_PRETRANSFER: data->progress.t_pretransfer = Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); -- cgit v1.2.1 From 24b189071035e5b987c137b491532597158889b9 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 11 Aug 2008 01:22:57 +0000 Subject: s/SIZEOF_CURL_OFF_T/CURL_SIZEOF_CURL_OFF_T/g --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 2956d1a99..b0aa853f0 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -86,7 +86,7 @@ static char *max5data(curl_off_t bytes, char *max5) (int)(bytes/ONE_MEGABYTE), (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); } -#if SIZEOF_CURL_OFF_T > 4 +#if CURL_SIZEOF_CURL_OFF_T > 4 else if(bytes < ( (curl_off_t)10000*ONE_MEGABYTE)) /* 'XXXXM' is good until we're at 10000MB or above */ snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); -- cgit v1.2.1 From 4d1cd0da93be1a400cf7652fd658571bf9104359 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 12 Aug 2008 18:49:33 +0000 Subject: Fix curl_off_t sized constants usage --- lib/progress.c | 77 +++++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 41 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index b0aa853f0..939e7dbcf 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -23,14 +23,6 @@ #include "setup.h" -#include -#include - -#if defined(__EMX__) -#include -#endif - -#include #include "urldata.h" #include "sendf.h" #include "progress.h" @@ -68,53 +60,56 @@ static void time2str(char *r, long t) Add suffix k, M, G when suitable... */ static char *max5data(curl_off_t bytes, char *max5) { -#define ONE_KILOBYTE 1024 -#define ONE_MEGABYTE (1024* ONE_KILOBYTE) -#define ONE_GIGABYTE (1024* ONE_MEGABYTE) -#define ONE_TERABYTE ((curl_off_t)1024* ONE_GIGABYTE) -#define ONE_PETABYTE ((curl_off_t)1024* ONE_TERABYTE) +#define ONE_KILOBYTE CURL_OFF_T_C(1024) +#define ONE_MEGABYTE (CURL_OFF_T_C(1024) * ONE_KILOBYTE) +#define ONE_GIGABYTE (CURL_OFF_T_C(1024) * ONE_MEGABYTE) +#define ONE_TERABYTE (CURL_OFF_T_C(1024) * ONE_GIGABYTE) +#define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE) - if(bytes < 100000) { + if(bytes < CURL_OFF_T_C(100000)) snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes); - } - else if(bytes < (10000*ONE_KILOBYTE)) { - snprintf(max5, 6, "%4" FORMAT_OFF_T "k", (curl_off_t)(bytes/ONE_KILOBYTE)); - } - else if(bytes < (100*ONE_MEGABYTE)) { + + else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE) + snprintf(max5, 6, "%4" FORMAT_OFF_T "k", bytes/ONE_KILOBYTE); + + else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE) /* 'XX.XM' is good as long as we're less than 100 megs */ - snprintf(max5, 6, "%2d.%0dM", - (int)(bytes/ONE_MEGABYTE), - (int)(bytes%ONE_MEGABYTE)/(ONE_MEGABYTE/10) ); - } + snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "M", + bytes/ONE_MEGABYTE, + (bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) ); + #if CURL_SIZEOF_CURL_OFF_T > 4 - else if(bytes < ( (curl_off_t)10000*ONE_MEGABYTE)) + + else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE) /* 'XXXXM' is good until we're at 10000MB or above */ - snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); + snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE); - else if(bytes < (curl_off_t)100*ONE_GIGABYTE) + else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE) /* 10000 MB - 100 GB, we show it as XX.XG */ - snprintf(max5, 6, "%2d.%0dG", - (int)(bytes/ONE_GIGABYTE), - (int)(bytes%ONE_GIGABYTE)/(ONE_GIGABYTE/10) ); + snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "G", + bytes/ONE_GIGABYTE, + (bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) ); - else if(bytes < (curl_off_t)10000 * ONE_GIGABYTE) + else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE) /* up to 10000GB, display without decimal: XXXXG */ - snprintf(max5, 6, "%4dG", (int)(bytes/ONE_GIGABYTE)); + snprintf(max5, 6, "%4" FORMAT_OFF_T "G", bytes/ONE_GIGABYTE); - else if(bytes < (curl_off_t)10000 * ONE_TERABYTE) + else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE) /* up to 10000TB, display without decimal: XXXXT */ - snprintf(max5, 6, "%4dT", (int)(bytes/ONE_TERABYTE)); - else { + snprintf(max5, 6, "%4" FORMAT_OFF_T "T", bytes/ONE_TERABYTE); + + else /* up to 10000PB, display without decimal: XXXXP */ - snprintf(max5, 6, "%4dP", (int)(bytes/ONE_PETABYTE)); + snprintf(max5, 6, "%4" FORMAT_OFF_T "P", bytes/ONE_PETABYTE); - /* 16384 petabytes (16 exabytes) is maximum a 64 bit number can hold, - but this type is signed so 8192PB will be max.*/ - } + /* 16384 petabytes (16 exabytes) is the maximum a 64 bit unsigned number + can hold, but our data type is signed so 8192PB will be the maximum. */ #else + else - snprintf(max5, 6, "%4" FORMAT_OFF_T "M", (curl_off_t)(bytes/ONE_MEGABYTE)); + snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE); + #endif return max5; @@ -316,7 +311,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) curl_off_t amount = data->progress.speeder[nowindex]- data->progress.speeder[checkindex]; - if(amount > 4294967 /* 0xffffffff/1000 */) + if(amount > CURL_OFF_T_C(4294967) /* 0xffffffff/1000 */) /* the 'amount' value is bigger than would fit in 32 bits if multiplied with 1000, so we use the double math for this */ data->progress.current_speed = (curl_off_t) @@ -324,7 +319,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) else /* the 'amount' value is small enough to fit within 32 bits even when multiplied with 1000 */ - data->progress.current_speed = amount*1000/span_ms; + data->progress.current_speed = amount*CURL_OFF_T_C(1000)/span_ms; } } else -- cgit v1.2.1 From 66fb9ca5f6de6eb74c2c3ade7ee651a299247749 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 15 Aug 2008 02:58:15 +0000 Subject: For congruency sake with the naming of other CURL_XXXXXX_CURL_OFF_T macros, the names of the curl_off_t formatting string directives now become CURL_FORMAT_CURL_OFF_T and CURL_FORMAT_CURL_OFF_TU. CURL_FMT_OFF_T -> CURL_FORMAT_CURL_OFF_T CURL_FMT_OFF_TU -> CURL_FORMAT_CURL_OFF_TU Remove the use of an internal name for the curl_off_t formatting string directives and use the common one available from the inside and outside of the library. FORMAT_OFF_T -> CURL_FORMAT_CURL_OFF_T FORMAT_OFF_TU -> CURL_FORMAT_CURL_OFF_TU --- lib/progress.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 939e7dbcf..fbdd7cbd2 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -67,40 +67,40 @@ static char *max5data(curl_off_t bytes, char *max5) #define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE) if(bytes < CURL_OFF_T_C(100000)) - snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes); + snprintf(max5, 6, "%5" CURL_FORMAT_CURL_OFF_T, bytes); else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE) - snprintf(max5, 6, "%4" FORMAT_OFF_T "k", bytes/ONE_KILOBYTE); + snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "k", bytes/ONE_KILOBYTE); else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE) /* 'XX.XM' is good as long as we're less than 100 megs */ - snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "M", - bytes/ONE_MEGABYTE, + snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0" + CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE, (bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) ); #if CURL_SIZEOF_CURL_OFF_T > 4 else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE) /* 'XXXXM' is good until we're at 10000MB or above */ - snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE); + snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE); else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE) /* 10000 MB - 100 GB, we show it as XX.XG */ - snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "G", - bytes/ONE_GIGABYTE, + snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0" + CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE, (bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) ); else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE) /* up to 10000GB, display without decimal: XXXXG */ - snprintf(max5, 6, "%4" FORMAT_OFF_T "G", bytes/ONE_GIGABYTE); + snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE); else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE) /* up to 10000TB, display without decimal: XXXXT */ - snprintf(max5, 6, "%4" FORMAT_OFF_T "T", bytes/ONE_TERABYTE); + snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "T", bytes/ONE_TERABYTE); else /* up to 10000PB, display without decimal: XXXXP */ - snprintf(max5, 6, "%4" FORMAT_OFF_T "P", bytes/ONE_PETABYTE); + snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "P", bytes/ONE_PETABYTE); /* 16384 petabytes (16 exabytes) is the maximum a 64 bit unsigned number can hold, but our data type is signed so 8192PB will be the maximum. */ @@ -108,7 +108,7 @@ static char *max5data(curl_off_t bytes, char *max5) #else else - snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE); + snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE); #endif @@ -357,8 +357,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if(data->state.resume_from) { fprintf(data->set.err, - "** Resuming transfer from byte position %" FORMAT_OFF_T "\n", - data->state.resume_from); + "** Resuming transfer from byte position %" + CURL_FORMAT_CURL_OFF_T "\n", data->state.resume_from); } fprintf(data->set.err, " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" -- cgit v1.2.1 From ad638da2c29a61babb50fdced0333393416a199a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 16 Aug 2008 01:33:59 +0000 Subject: Library internal only C preprocessor macros FORMAT_OFF_T and FORMAT_OFF_TU remain in use as internal curl_off_t print formatting strings for the internal *printf functions which still cannot handle print formatting string directives such as "I64d", "I64u", and others available on MSVC, MinGW, Intel's ICC, and other DOS/Windows compilers. This reverts previous commit part which did: FORMAT_OFF_T -> CURL_FORMAT_CURL_OFF_T FORMAT_OFF_TU -> CURL_FORMAT_CURL_OFF_TU --- lib/progress.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index fbdd7cbd2..939e7dbcf 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -67,40 +67,40 @@ static char *max5data(curl_off_t bytes, char *max5) #define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE) if(bytes < CURL_OFF_T_C(100000)) - snprintf(max5, 6, "%5" CURL_FORMAT_CURL_OFF_T, bytes); + snprintf(max5, 6, "%5" FORMAT_OFF_T, bytes); else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE) - snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "k", bytes/ONE_KILOBYTE); + snprintf(max5, 6, "%4" FORMAT_OFF_T "k", bytes/ONE_KILOBYTE); else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE) /* 'XX.XM' is good as long as we're less than 100 megs */ - snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0" - CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE, + snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "M", + bytes/ONE_MEGABYTE, (bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) ); #if CURL_SIZEOF_CURL_OFF_T > 4 else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE) /* 'XXXXM' is good until we're at 10000MB or above */ - snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE); + snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE); else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE) /* 10000 MB - 100 GB, we show it as XX.XG */ - snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0" - CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE, + snprintf(max5, 6, "%2" FORMAT_OFF_T ".%0" FORMAT_OFF_T "G", + bytes/ONE_GIGABYTE, (bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) ); else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE) /* up to 10000GB, display without decimal: XXXXG */ - snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE); + snprintf(max5, 6, "%4" FORMAT_OFF_T "G", bytes/ONE_GIGABYTE); else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE) /* up to 10000TB, display without decimal: XXXXT */ - snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "T", bytes/ONE_TERABYTE); + snprintf(max5, 6, "%4" FORMAT_OFF_T "T", bytes/ONE_TERABYTE); else /* up to 10000PB, display without decimal: XXXXP */ - snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "P", bytes/ONE_PETABYTE); + snprintf(max5, 6, "%4" FORMAT_OFF_T "P", bytes/ONE_PETABYTE); /* 16384 petabytes (16 exabytes) is the maximum a 64 bit unsigned number can hold, but our data type is signed so 8192PB will be the maximum. */ @@ -108,7 +108,7 @@ static char *max5data(curl_off_t bytes, char *max5) #else else - snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE); + snprintf(max5, 6, "%4" FORMAT_OFF_T "M", bytes/ONE_MEGABYTE); #endif @@ -357,8 +357,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if(data->state.resume_from) { fprintf(data->set.err, - "** Resuming transfer from byte position %" - CURL_FORMAT_CURL_OFF_T "\n", data->state.resume_from); + "** Resuming transfer from byte position %" FORMAT_OFF_T "\n", + data->state.resume_from); } fprintf(data->set.err, " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" -- cgit v1.2.1 From 3e2487493ef28ea9e44931faffb04e89ed3aae8d Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Aug 2008 01:40:19 +0000 Subject: Use SIZEOF_OFF_T definition from config file --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 939e7dbcf..1c997e04d 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -78,7 +78,7 @@ static char *max5data(curl_off_t bytes, char *max5) bytes/ONE_MEGABYTE, (bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) ); -#if CURL_SIZEOF_CURL_OFF_T > 4 +#if (CURL_SIZEOF_CURL_OFF_T > 4) else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE) /* 'XXXXM' is good until we're at 10000MB or above */ -- cgit v1.2.1 From 2ecf22e37ee08a3b7421e2ca49ad45a2e5299e28 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 11 Oct 2008 01:56:04 +0000 Subject: fix compiler warning: explicit conversion of a 64-bit integral type to a smaller integral type --- lib/progress.c | 72 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 33 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 1c997e04d..69f273405 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -32,26 +32,29 @@ /* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero byte) */ -static void time2str(char *r, long t) +static void time2str(char *r, curl_off_t seconds) { - long h; - if(!t) { + curl_off_t d, h, m, s; + if(seconds <= 0) { strcpy(r, "--:--:--"); return; } - h = (t/3600); - if(h <= 99) { - long m = (t-(h*3600))/60; - long s = (t-(h*3600)-(m*60)); - snprintf(r, 9, "%2ld:%02ld:%02ld",h,m,s); + h = seconds / CURL_OFF_T_C(3600); + if(h <= CURL_OFF_T_C(99)) { + m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60); + s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60)); + snprintf(r, 9, "%2" FORMAT_OFF_T ":%02" FORMAT_OFF_T ":%02" FORMAT_OFF_T, + h, m, s); } else { /* this equals to more than 99 hours, switch to a more suitable output format to fit within the limits. */ - if(h/24 <= 999) - snprintf(r, 9, "%3ldd %02ldh", h/24, h-(h/24)*24); + d = seconds / CURL_OFF_T_C(86400); + h = (seconds - (d*CURL_OFF_T_C(86400))) / CURL_OFF_T_C(3600); + if(d <= CURL_OFF_T_C(999)) + snprintf(r, 9, "%3" FORMAT_OFF_T "d %02" FORMAT_OFF_T "h", d, h); else - snprintf(r, 9, "%7ldd", h/24); + snprintf(r, 9, "%7" FORMAT_OFF_T "d", d); } } @@ -228,12 +231,12 @@ int Curl_pgrsUpdate(struct connectdata *conn) struct timeval now; int result; char max5[6][10]; - int dlpercen=0; - int ulpercen=0; - int total_percen=0; + curl_off_t dlpercen=0; + curl_off_t ulpercen=0; + curl_off_t total_percen=0; curl_off_t total_transfer; curl_off_t total_expected_transfer; - long timespent; + curl_off_t timespent; struct SessionHandle *data = conn->data; int nowindex = data->progress.speeder_c% CURR_TIME; int checkindex; @@ -241,9 +244,9 @@ int Curl_pgrsUpdate(struct connectdata *conn) char time_left[10]; char time_total[10]; char time_spent[10]; - long ulestimate=0; - long dlestimate=0; - long total_estimate; + curl_off_t ulestimate=0; + curl_off_t dlestimate=0; + curl_off_t total_estimate; bool shownow=FALSE; now = Curl_tvnow(); /* what time is it */ @@ -252,7 +255,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->progress.timespent = (double)(now.tv_sec - data->progress.start.tv_sec) + (double)(now.tv_usec - data->progress.start.tv_usec)/1000000.0; - timespent = (long)data->progress.timespent; + timespent = (curl_off_t)data->progress.timespent; /* The average download speed this far */ data->progress.dlspeed = (curl_off_t) @@ -368,20 +371,20 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Figure out the estimated time of arrival for the upload */ if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && - (data->progress.ulspeed>0) && - (data->progress.size_ul > 100) ) { - ulestimate = (long)(data->progress.size_ul / data->progress.ulspeed); - ulpercen = (int)(100*(data->progress.uploaded/100) / - (data->progress.size_ul/100) ); + (data->progress.ulspeed > CURL_OFF_T_C(0)) && + (data->progress.size_ul > CURL_OFF_T_C(100)) ) { + ulestimate = data->progress.size_ul / data->progress.ulspeed; + ulpercen = data->progress.uploaded / + (data->progress.size_ul/CURL_OFF_T_C(100)); } /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && - (data->progress.dlspeed>0) && - (data->progress.size_dl>100)) { - dlestimate = (long)(data->progress.size_dl / data->progress.dlspeed); - dlpercen = (int)(100*(data->progress.downloaded/100) / - (data->progress.size_dl/100)); + (data->progress.dlspeed > CURL_OFF_T_C(0)) && + (data->progress.size_dl > CURL_OFF_T_C(100))) { + dlestimate = data->progress.size_dl / data->progress.dlspeed; + dlpercen = data->progress.downloaded / + (data->progress.size_dl/CURL_OFF_T_C(100)); } /* Now figure out which of them is slower and use that one for the @@ -404,12 +407,15 @@ int Curl_pgrsUpdate(struct connectdata *conn) total_transfer = data->progress.downloaded + data->progress.uploaded; /* Get the percentage of data transfered so far */ - if(total_expected_transfer > 100) - total_percen=(int)(100*(total_transfer/100) / - (total_expected_transfer/100) ); + if(total_expected_transfer > CURL_OFF_T_C(100)) + total_percen = total_transfer / + (total_expected_transfer/CURL_OFF_T_C(100)); fprintf(data->set.err, - "\r%3d %s %3d %s %3d %s %s %s %s %s %s %s", + "\r" + "%3" FORMAT_OFF_T " %s " + "%3" FORMAT_OFF_T " %s " + "%3" FORMAT_OFF_T " %s %s %s %s %s %s %s", total_percen, /* 3 letters */ /* total % */ max5data(total_expected_transfer, max5[2]), /* total size */ dlpercen, /* 3 letters */ /* rcvd % */ -- cgit v1.2.1 From 223d84810435d1fa3937e46488f6a4763de06972 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 31 Oct 2009 18:51:50 +0000 Subject: - Gabriel Kuri reported a problem with CURLINFO_CONTENT_LENGTH_DOWNLOAD if the download was 0 bytes, as libcurl would then return the size as unknown (-1) and not 0. I wrote a fix and test case 566 to verify it. --- lib/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 69f273405..eddd852c1 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -211,7 +211,7 @@ void Curl_pgrsSetUploadCounter(struct SessionHandle *data, curl_off_t size) void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size) { data->progress.size_dl = size; - if(size > 0) + if(size >= 0) data->progress.flags |= PGRS_DL_SIZE_KNOWN; else data->progress.flags &= ~PGRS_DL_SIZE_KNOWN; @@ -220,7 +220,7 @@ void Curl_pgrsSetDownloadSize(struct SessionHandle *data, curl_off_t size) void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size) { data->progress.size_ul = size; - if(size > 0) + if(size >= 0) data->progress.flags |= PGRS_UL_SIZE_KNOWN; else data->progress.flags &= ~PGRS_UL_SIZE_KNOWN; -- cgit v1.2.1 From 257f2376d59ebde87645c207d5006d4657352bbb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 4 Nov 2009 23:09:17 +0000 Subject: - I fixed several problems with the transfer progress meter. It showed the wrong percentage for small files, most notable for <1000 bytes and could easily end up showing more than 100% at the end. It also didn't show any percentage, transfer size or estimated transfer times when transferring less than 100 bytes. --- lib/progress.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index eddd852c1..c96db2abb 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -370,21 +370,29 @@ int Curl_pgrsUpdate(struct connectdata *conn) } /* Figure out the estimated time of arrival for the upload */ - if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && - (data->progress.ulspeed > CURL_OFF_T_C(0)) && - (data->progress.size_ul > CURL_OFF_T_C(100)) ) { + if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && + (data->progress.ulspeed > CURL_OFF_T_C(0))) { ulestimate = data->progress.size_ul / data->progress.ulspeed; - ulpercen = data->progress.uploaded / - (data->progress.size_ul/CURL_OFF_T_C(100)); + + if(data->progress.size_ul > CURL_OFF_T_C(10000) ) + ulpercen = data->progress.uploaded / + (data->progress.size_ul/CURL_OFF_T_C(100)); + else + ulpercen = (data->progress.uploaded*100) / + data->progress.size_ul; } /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && - (data->progress.dlspeed > CURL_OFF_T_C(0)) && - (data->progress.size_dl > CURL_OFF_T_C(100))) { + (data->progress.dlspeed > CURL_OFF_T_C(0)) ) { dlestimate = data->progress.size_dl / data->progress.dlspeed; - dlpercen = data->progress.downloaded / - (data->progress.size_dl/CURL_OFF_T_C(100)); + + if(data->progress.size_dl > CURL_OFF_T_C(10000)) + dlpercen = data->progress.downloaded / + (data->progress.size_dl/CURL_OFF_T_C(100)); + else + dlpercen = (data->progress.downloaded*100) / + data->progress.size_dl; } /* Now figure out which of them is slower and use that one for the @@ -407,9 +415,11 @@ int Curl_pgrsUpdate(struct connectdata *conn) total_transfer = data->progress.downloaded + data->progress.uploaded; /* Get the percentage of data transfered so far */ - if(total_expected_transfer > CURL_OFF_T_C(100)) + if(total_expected_transfer > CURL_OFF_T_C(10000)) total_percen = total_transfer / - (total_expected_transfer/CURL_OFF_T_C(100)); + (total_expected_transfer/CURL_OFF_T_C(100)); + else if(total_expected_transfer > 0) + total_percen = (total_transfer*100) / total_expected_transfer; fprintf(data->set.err, "\r" -- cgit v1.2.1 From 3f56d1283020d3a6b8bc115080f2bb0d9a61fe27 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 5 Nov 2009 15:00:28 +0000 Subject: avoid division by zero --- lib/progress.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index c96db2abb..f7bc377e4 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -370,27 +370,27 @@ int Curl_pgrsUpdate(struct connectdata *conn) } /* Figure out the estimated time of arrival for the upload */ - if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && + if((data->progress.flags & PGRS_UL_SIZE_KNOWN) && (data->progress.ulspeed > CURL_OFF_T_C(0))) { ulestimate = data->progress.size_ul / data->progress.ulspeed; - if(data->progress.size_ul > CURL_OFF_T_C(10000) ) + if(data->progress.size_ul > CURL_OFF_T_C(10000)) ulpercen = data->progress.uploaded / (data->progress.size_ul/CURL_OFF_T_C(100)); - else + else if(data->progress.size_ul > CURL_OFF_T_C(0)) ulpercen = (data->progress.uploaded*100) / data->progress.size_ul; } /* ... and the download */ if((data->progress.flags & PGRS_DL_SIZE_KNOWN) && - (data->progress.dlspeed > CURL_OFF_T_C(0)) ) { + (data->progress.dlspeed > CURL_OFF_T_C(0))) { dlestimate = data->progress.size_dl / data->progress.dlspeed; if(data->progress.size_dl > CURL_OFF_T_C(10000)) dlpercen = data->progress.downloaded / (data->progress.size_dl/CURL_OFF_T_C(100)); - else + else if(data->progress.size_dl > CURL_OFF_T_C(0)) dlpercen = (data->progress.downloaded*100) / data->progress.size_dl; } @@ -418,7 +418,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) if(total_expected_transfer > CURL_OFF_T_C(10000)) total_percen = total_transfer / (total_expected_transfer/CURL_OFF_T_C(100)); - else if(total_expected_transfer > 0) + else if(total_expected_transfer > CURL_OFF_T_C(0)) total_percen = (total_transfer*100) / total_expected_transfer; fprintf(data->set.err, -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/progress.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index f7bc377e4..e0758f2a8 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 34ef39015e3064ca61f48428911ed6ce89738875 Mon Sep 17 00:00:00 2001 From: Julien Chaffraix Date: Sun, 20 Mar 2011 18:00:29 -0700 Subject: progress: don't print the last update on a separate line. Curl_posttransfer is called too soon to add the final new line. Moved the new line logic to pgrsDone as there is no more call to update the progress status after this call. Reported by: Dmitri Shubin http://curl.haxx.se/mail/lib-2010-12/0162.html --- lib/progress.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index e0758f2a8..49047f1a6 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -137,6 +137,12 @@ void Curl_pgrsDone(struct connectdata *conn) data->progress.lastshow=0; Curl_pgrsUpdate(conn); /* the final (forced) update */ + if(!(data->progress.flags & PGRS_HIDE) && + !data->progress.callback) + /* only output if we don't use a progress callback and we're not + * hidden */ + fprintf(data->set.err, "\n"); + data->progress.speeder_c = 0; /* reset the progress meter display */ } -- cgit v1.2.1 From 1702a2c08d3a0ed5945f34e6cd38436611f65164 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Tue, 19 Apr 2011 15:54:13 +0200 Subject: Fix a couple of spelling errors in lib/ Found with codespell. --- lib/progress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 49047f1a6..e37c34d99 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -409,17 +409,17 @@ int Curl_pgrsUpdate(struct connectdata *conn) time2str(time_total, total_estimate); time2str(time_spent, timespent); - /* Get the total amount of data expected to get transfered */ + /* Get the total amount of data expected to get transferred */ total_expected_transfer = (data->progress.flags & PGRS_UL_SIZE_KNOWN? data->progress.size_ul:data->progress.uploaded)+ (data->progress.flags & PGRS_DL_SIZE_KNOWN? data->progress.size_dl:data->progress.downloaded); - /* We have transfered this much so far */ + /* We have transferred this much so far */ total_transfer = data->progress.downloaded + data->progress.uploaded; - /* Get the percentage of data transfered so far */ + /* Get the percentage of data transferred so far */ if(total_expected_transfer > CURL_OFF_T_C(10000)) total_percen = total_transfer / (total_expected_transfer/CURL_OFF_T_C(100)); -- cgit v1.2.1 From b903186fa0189ff241d756d25d07fdfe9885ae49 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 20 Apr 2011 15:17:42 +0200 Subject: source cleanup: unify look, style and indent levels By the use of a the new lib/checksrc.pl script that checks that our basic source style rules are followed. --- lib/progress.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index e37c34d99..8655dc4c2 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -369,8 +369,10 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->state.resume_from); } fprintf(data->set.err, - " %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" - " Dload Upload Total Spent Left Speed\n"); + " %% Total %% Received %% Xferd Average Speed " + "Time Time Time Current\n" + " Dload Upload " + "Total Spent Left Speed\n"); data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ } -- cgit v1.2.1 From 27b8814017a19009b22e4b51aea1ae711ec20459 Mon Sep 17 00:00:00 2001 From: Ben Winslow Date: Fri, 22 Jul 2011 22:50:58 +0200 Subject: progress: reset flags at transfer start When an easy handle is used to download an URI which has no Content-Length header (or equivalent) after downloading an URI which does, the value from the previous transfer is reused and returned by CURLINFO_CONTENT_LENGTH_DOWNLOAD. This is because the progress flags (used to determine whether such a header was received) are not reset between transfers. Bug: http://curl.haxx.se/bug/view.cgi?id=3370895 --- lib/progress.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8655dc4c2..9f20a0068 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -201,6 +201,7 @@ void Curl_pgrsStartNow(struct SessionHandle *data) { data->progress.speeder_c = 0; /* reset the progress meter display */ data->progress.start = Curl_tvnow(); + data->progress.flags = 0; } void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size) -- cgit v1.2.1 From 15379f0614c56281b71dfc7b07b5e63955ccd9ac Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 7 Aug 2011 22:26:57 +0200 Subject: Curl_pgrsStartNow: clear all bits except HIDE Bug: http://curl.haxx.se/bug/view.cgi?id=3385258 Reported by: Ben Winslow --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 9f20a0068..9ad924108 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -201,7 +201,7 @@ void Curl_pgrsStartNow(struct SessionHandle *data) { data->progress.speeder_c = 0; /* reset the progress meter display */ data->progress.start = Curl_tvnow(); - data->progress.flags = 0; + data->progress.flags &= ~PGRS_HIDE; /* clear all bits except HIDE */ } void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size) -- cgit v1.2.1 From 93ba8b9560f9089379189d94edbab217f1822684 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 15 Aug 2011 22:08:58 +0200 Subject: Curl_pgrsStartNow: clear all flags but HIDE As bug 3385258 pointed out but I missed up the fix for. This is another take at a fix. Bug: http://curl.haxx.se/bug/view.cgi?id=3392101 Reported by: Wu Yongzheng --- lib/progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 9ad924108..8966854fa 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -201,7 +201,7 @@ void Curl_pgrsStartNow(struct SessionHandle *data) { data->progress.speeder_c = 0; /* reset the progress meter display */ data->progress.start = Curl_tvnow(); - data->progress.flags &= ~PGRS_HIDE; /* clear all bits except HIDE */ + data->progress.flags &= PGRS_HIDE; /* clear all bits except HIDE */ } void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size) -- cgit v1.2.1 From 40c27e299f97e36c4c2ecc697397f5626737513b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 22 Sep 2011 22:34:54 +0200 Subject: Curl_pgrsStartNow: keep HEADERS_OUT set To avoid that the progress meter headers get output between each transfer, make sure the bits gets kept when (re-)inited. Reported by: Christopher Stone --- lib/progress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 8966854fa..1514e1edd 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -201,7 +201,8 @@ void Curl_pgrsStartNow(struct SessionHandle *data) { data->progress.speeder_c = 0; /* reset the progress meter display */ data->progress.start = Curl_tvnow(); - data->progress.flags &= PGRS_HIDE; /* clear all bits except HIDE */ + /* clear all bits except HIDE and HEADERS_OUT */ + data->progress.flags &= PGRS_HIDE|PGRS_HEADERS_OUT; } void Curl_pgrsSetDownloadCounter(struct SessionHandle *data, curl_off_t size) -- cgit v1.2.1 From 51d4885ca046654d37b6bdf31540180693e35e09 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Dec 2011 15:05:50 +0100 Subject: Curl_pgrsTime: store now in an auto variable It makes it easier to introduce debug outputs in this function, and everything in the function is using the value anyway so it might even be more efficient. --- lib/progress.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 1514e1edd..6abe72e56 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -157,6 +157,8 @@ void Curl_pgrsResetTimes(struct SessionHandle *data) void Curl_pgrsTime(struct SessionHandle *data, timerid timer) { + struct timeval now = Curl_tvnow(); + switch(timer) { default: case TIMER_NONE: @@ -164,35 +166,34 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) break; case TIMER_STARTSINGLE: /* This is set at the start of a single fetch */ - data->progress.t_startsingle = Curl_tvnow(); + data->progress.t_startsingle = now; break; case TIMER_NAMELOOKUP: data->progress.t_nslookup = - Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); + Curl_tvdiff_secs(now, data->progress.t_startsingle); break; case TIMER_CONNECT: data->progress.t_connect = - Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); + Curl_tvdiff_secs(now, data->progress.t_startsingle); break; case TIMER_APPCONNECT: data->progress.t_appconnect = - Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); + Curl_tvdiff_secs(now, data->progress.t_startsingle); break; case TIMER_PRETRANSFER: data->progress.t_pretransfer = - Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); + Curl_tvdiff_secs(now, data->progress.t_startsingle); break; case TIMER_STARTTRANSFER: data->progress.t_starttransfer = - Curl_tvdiff_secs(Curl_tvnow(), data->progress.t_startsingle); + Curl_tvdiff_secs(now, data->progress.t_startsingle); break; case TIMER_POSTRANSFER: /* this is the normal end-of-transfer thing */ break; case TIMER_REDIRECT: - data->progress.t_redirect = - Curl_tvdiff_secs(Curl_tvnow(), data->progress.start); + data->progress.t_redirect = Curl_tvdiff_secs(now, data->progress.start); break; } } -- cgit v1.2.1 From c834213ad52c52431e9ca597862dc81839cabe84 Mon Sep 17 00:00:00 2001 From: Gokhan Sengun Date: Mon, 19 Dec 2011 14:35:20 +0100 Subject: FTP: perform active connections non-blocking 1- Two new error codes are introduced. CURLE_FTP_ACCEPT_FAILED to be set whenever ACCEPTing fails because of FTP server connected. CURLE_FTP_ACCEPT_TIMEOUT to be set whenever ACCEPTing timeouts. Neither of these errors are considered fatal and control connection remains OK because it could just be a firewall blocking server to connect to the client. 2- One new setopt option was introduced. CURLOPT_ACCEPTTIMEOUT_MS It sets the maximum amount of time FTP client is going to wait for a server to connect. Internal default accept timeout is 60 seconds. --- lib/progress.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 6abe72e56..1eeb78052 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -169,6 +169,10 @@ void Curl_pgrsTime(struct SessionHandle *data, timerid timer) data->progress.t_startsingle = now; break; + case TIMER_STARTACCEPT: + data->progress.t_acceptdata = Curl_tvnow(); + break; + case TIMER_NAMELOOKUP: data->progress.t_nslookup = Curl_tvdiff_secs(now, data->progress.t_startsingle); -- cgit v1.2.1 From c44d45db86b880df5facd6b560491e03530f876e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 23 Mar 2012 23:42:37 +0100 Subject: HTTP: reset expected DL/UL sizes on redirects With FOLLOWLOCATION enabled. When a 3xx page is downloaded and the download size was known (like with a Content-Length header), but the subsequent URL (transfered after the 3xx page) was chunked encoded, then the previous "known download size" would linger and cause the progress meter to get incorrect information, ie the former value would remain being sent in. This could easily result in downloads that were WAY larger than "expected" and would cause >100% outputs with the curl command line tool. Test case 599 was created and it was used to repeat the bug and then verify the fix. Bug: http://curl.haxx.se/bug/view.cgi?id=3510057 Reported by: Michael Wallner --- lib/progress.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 1eeb78052..4c9a63acb 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -146,13 +146,16 @@ void Curl_pgrsDone(struct connectdata *conn) data->progress.speeder_c = 0; /* reset the progress meter display */ } -/* reset all times except redirect */ -void Curl_pgrsResetTimes(struct SessionHandle *data) +/* reset all times except redirect, and reset the known transfer sizes */ +void Curl_pgrsResetTimesSizes(struct SessionHandle *data) { data->progress.t_nslookup = 0.0; data->progress.t_connect = 0.0; data->progress.t_pretransfer = 0.0; data->progress.t_starttransfer = 0.0; + + Curl_pgrsSetDownloadSize(data, 0); + Curl_pgrsSetUploadSize(data, 0); } void Curl_pgrsTime(struct SessionHandle *data, timerid timer) -- cgit v1.2.1 From 6cd084a3b5129d9ab8db3e5bc0f094943d7eef89 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 10 Jun 2012 23:39:04 +0200 Subject: Curl_pgrsDone: return int and acknowledge return code Since Curl_pgrsDone() itself calls Curl_pgrsUpdate() which may return an abort instruction or similar we need to return that info back and subsequently properly handle return codes from Curl_pgrsDone() where used. (Spotted by a Coverity scan) --- lib/progress.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/progress.c') diff --git a/lib/progress.c b/lib/progress.c index 4c9a63acb..e73f01811 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -131,11 +131,14 @@ static char *max5data(curl_off_t bytes, char *max5) */ -void Curl_pgrsDone(struct connectdata *conn) +int Curl_pgrsDone(struct connectdata *conn) { + int rc; struct SessionHandle *data = conn->data; data->progress.lastshow=0; - Curl_pgrsUpdate(conn); /* the final (forced) update */ + rc = Curl_pgrsUpdate(conn); /* the final (forced) update */ + if(rc) + return rc; if(!(data->progress.flags & PGRS_HIDE) && !data->progress.callback) @@ -144,6 +147,7 @@ void Curl_pgrsDone(struct connectdata *conn) fprintf(data->set.err, "\n"); data->progress.speeder_c = 0; /* reset the progress meter display */ + return 0; } /* reset all times except redirect, and reset the known transfer sizes */ @@ -241,6 +245,10 @@ void Curl_pgrsSetUploadSize(struct SessionHandle *data, curl_off_t size) data->progress.flags &= ~PGRS_UL_SIZE_KNOWN; } +/* + * Curl_pgrsUpdate() returns 0 for success or the value returned by the + * progress callback! + */ int Curl_pgrsUpdate(struct connectdata *conn) { struct timeval now; -- cgit v1.2.1