Loading lib/progress.c +76 −55 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms Loading @@ -31,6 +31,7 @@ /* check rate limits within this many recent milliseconds, at minimum. */ #define MIN_RATE_LIMIT_PERIOD 3000 #ifndef CURL_DISABLE_PROGRESS_METER /* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero byte) */ static void time2str(char *r, curl_off_t seconds) Loading Loading @@ -119,6 +120,7 @@ static char *max5data(curl_off_t bytes, char *max5) return max5; } #endif /* Loading Loading @@ -362,23 +364,14 @@ void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size) } } /* * Curl_pgrsUpdate() returns 0 for success or the value returned by the * progress callback! */ int Curl_pgrsUpdate(struct connectdata *conn) static void progress_calc(struct connectdata *conn, struct curltime now) { struct curltime now; curl_off_t timespent; curl_off_t timespent_ms; /* milliseconds */ struct Curl_easy *data = conn->data; int nowindex = data->progress.speeder_c% CURR_TIME; bool shownow = FALSE; curl_off_t dl = data->progress.downloaded; curl_off_t ul = data->progress.uploaded; now = Curl_now(); /* what time is it */ /* The time spent so far (from the start) */ data->progress.timespent = Curl_timediff_us(now, data->progress.start); timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */ Loading @@ -399,8 +392,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Calculations done at most once a second, unless end is reached */ if(data->progress.lastshow != now.tv_sec) { int countindex; /* amount of seconds stored in the speeder array */ shownow = TRUE; int nowindex = data->progress.speeder_c% CURR_TIME; data->progress.lastshow = now.tv_sec; /* Let's do the "current speed" thing, with the dl + ul speeds Loading Loading @@ -434,8 +426,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->progress.speeder_c%CURR_TIME:0; /* Figure out the exact time for the time span */ span_ms = Curl_timediff(now, data->progress.speeder_time[checkindex]); span_ms = Curl_timediff(now, data->progress.speeder_time[checkindex]); if(0 == span_ms) span_ms = 1; /* at least one millisecond MUST have passed */ Loading @@ -461,8 +452,25 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->progress.ulspeed + data->progress.dlspeed; } /* Calculations end */ } if(!(data->progress.flags & PGRS_HIDE)) { #ifndef CURL_DISABLE_PROGRESS_METER static void progress_meter(struct connectdata *conn, struct curltime now) { struct Curl_easy *data = conn->data; bool shownow = FALSE; if(data->progress.lastshow != now.tv_sec) { if(!(data->progress.flags & PGRS_HIDE)) shownow = TRUE; } if(!shownow) /* only show the internal progress meter once per second */ return; else { /* If there's no external callback set, use internal code to show progress */ /* progress meter has not been shut off */ char max5[6][10]; curl_off_t dlpercen = 0; Loading @@ -476,42 +484,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) curl_off_t ulestimate = 0; curl_off_t dlestimate = 0; curl_off_t total_estimate; if(data->set.fxferinfo) { int result; /* There's a callback set, call that */ Curl_set_in_callback(data, true); result = data->set.fxferinfo(data->set.progress_client, data->progress.size_dl, data->progress.downloaded, data->progress.size_ul, data->progress.uploaded); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } if(data->set.fprogress) { int result; /* The older deprecated callback is set, call that */ Curl_set_in_callback(data, true); 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); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } 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 */ curl_off_t timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */ if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if(data->state.resume_from) { Loading Loading @@ -595,13 +569,60 @@ int Curl_pgrsUpdate(struct connectdata *conn) 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 */ max5data(data->progress.current_speed, max5[5]) ); /* we flush the output stream to make it appear as soon as possible */ fflush(data->set.err); } /* don't show now */ } #else /* progress bar disabled */ #define progress_meter(x,y) #endif } /* !(data->progress.flags & PGRS_HIDE) */ /* * Curl_pgrsUpdate() returns 0 for success or the value returned by the * progress callback! */ int Curl_pgrsUpdate(struct connectdata *conn) { struct Curl_easy *data = conn->data; struct curltime now = Curl_now(); /* what time is it */ progress_calc(conn, now); if(!(data->progress.flags & PGRS_HIDE)) { if(data->set.fxferinfo) { int result; /* There's a callback set, call that */ Curl_set_in_callback(data, true); result = data->set.fxferinfo(data->set.progress_client, data->progress.size_dl, data->progress.downloaded, data->progress.size_ul, data->progress.uploaded); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } if(data->set.fprogress) { int result; /* The older deprecated callback is set, call that */ Curl_set_in_callback(data, true); 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); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } } progress_meter(conn, now); return 0; } Loading
lib/progress.c +76 −55 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms Loading @@ -31,6 +31,7 @@ /* check rate limits within this many recent milliseconds, at minimum. */ #define MIN_RATE_LIMIT_PERIOD 3000 #ifndef CURL_DISABLE_PROGRESS_METER /* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero byte) */ static void time2str(char *r, curl_off_t seconds) Loading Loading @@ -119,6 +120,7 @@ static char *max5data(curl_off_t bytes, char *max5) return max5; } #endif /* Loading Loading @@ -362,23 +364,14 @@ void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size) } } /* * Curl_pgrsUpdate() returns 0 for success or the value returned by the * progress callback! */ int Curl_pgrsUpdate(struct connectdata *conn) static void progress_calc(struct connectdata *conn, struct curltime now) { struct curltime now; curl_off_t timespent; curl_off_t timespent_ms; /* milliseconds */ struct Curl_easy *data = conn->data; int nowindex = data->progress.speeder_c% CURR_TIME; bool shownow = FALSE; curl_off_t dl = data->progress.downloaded; curl_off_t ul = data->progress.uploaded; now = Curl_now(); /* what time is it */ /* The time spent so far (from the start) */ data->progress.timespent = Curl_timediff_us(now, data->progress.start); timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */ Loading @@ -399,8 +392,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) /* Calculations done at most once a second, unless end is reached */ if(data->progress.lastshow != now.tv_sec) { int countindex; /* amount of seconds stored in the speeder array */ shownow = TRUE; int nowindex = data->progress.speeder_c% CURR_TIME; data->progress.lastshow = now.tv_sec; /* Let's do the "current speed" thing, with the dl + ul speeds Loading Loading @@ -434,8 +426,7 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->progress.speeder_c%CURR_TIME:0; /* Figure out the exact time for the time span */ span_ms = Curl_timediff(now, data->progress.speeder_time[checkindex]); span_ms = Curl_timediff(now, data->progress.speeder_time[checkindex]); if(0 == span_ms) span_ms = 1; /* at least one millisecond MUST have passed */ Loading @@ -461,8 +452,25 @@ int Curl_pgrsUpdate(struct connectdata *conn) data->progress.ulspeed + data->progress.dlspeed; } /* Calculations end */ } if(!(data->progress.flags & PGRS_HIDE)) { #ifndef CURL_DISABLE_PROGRESS_METER static void progress_meter(struct connectdata *conn, struct curltime now) { struct Curl_easy *data = conn->data; bool shownow = FALSE; if(data->progress.lastshow != now.tv_sec) { if(!(data->progress.flags & PGRS_HIDE)) shownow = TRUE; } if(!shownow) /* only show the internal progress meter once per second */ return; else { /* If there's no external callback set, use internal code to show progress */ /* progress meter has not been shut off */ char max5[6][10]; curl_off_t dlpercen = 0; Loading @@ -476,42 +484,8 @@ int Curl_pgrsUpdate(struct connectdata *conn) curl_off_t ulestimate = 0; curl_off_t dlestimate = 0; curl_off_t total_estimate; if(data->set.fxferinfo) { int result; /* There's a callback set, call that */ Curl_set_in_callback(data, true); result = data->set.fxferinfo(data->set.progress_client, data->progress.size_dl, data->progress.downloaded, data->progress.size_ul, data->progress.uploaded); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } if(data->set.fprogress) { int result; /* The older deprecated callback is set, call that */ Curl_set_in_callback(data, true); 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); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } 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 */ curl_off_t timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */ if(!(data->progress.flags & PGRS_HEADERS_OUT)) { if(data->state.resume_from) { Loading Loading @@ -595,13 +569,60 @@ int Curl_pgrsUpdate(struct connectdata *conn) 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 */ max5data(data->progress.current_speed, max5[5]) ); /* we flush the output stream to make it appear as soon as possible */ fflush(data->set.err); } /* don't show now */ } #else /* progress bar disabled */ #define progress_meter(x,y) #endif } /* !(data->progress.flags & PGRS_HIDE) */ /* * Curl_pgrsUpdate() returns 0 for success or the value returned by the * progress callback! */ int Curl_pgrsUpdate(struct connectdata *conn) { struct Curl_easy *data = conn->data; struct curltime now = Curl_now(); /* what time is it */ progress_calc(conn, now); if(!(data->progress.flags & PGRS_HIDE)) { if(data->set.fxferinfo) { int result; /* There's a callback set, call that */ Curl_set_in_callback(data, true); result = data->set.fxferinfo(data->set.progress_client, data->progress.size_dl, data->progress.downloaded, data->progress.size_ul, data->progress.uploaded); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } if(data->set.fprogress) { int result; /* The older deprecated callback is set, call that */ Curl_set_in_callback(data, true); 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); Curl_set_in_callback(data, false); if(result) failf(data, "Callback aborted"); return result; } } progress_meter(conn, now); return 0; }