We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download two part of file using the same CURL easy_hanle with maxspeed.
The speed limit is also effective for the second download.
curl-7_76_1
data->progress.ul_limit_size / data->progress.dl_limit_size was not reset to zero at the beginning.
diff --git a/lib/progress.c b/lib/progress.c index cc040a8..c9ff706 100644 --- a/lib/progress.c +++ b/lib/progress.c @@ -241,6 +241,8 @@ void Curl_pgrsStartNow(struct Curl_easy *data) data->progress.is_t_startransfer_set = false; data->progress.ul_limit_start = data->progress.start; data->progress.dl_limit_start = data->progress.start; + data->progress.ul_limit_size = 0; + data->progress.dl_limit_size = 0; data->progress.downloaded = 0; data->progress.uploaded = 0; /* clear all bits except HIDE and HEADERS_OUT */
#include <stdio.h> #include <string.h> #include <curl/curl.h> static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { static time_t time_last = 0; static double dlnow_last = 0; time_t now = time(NULL); if (time_last == 0) { time_last = now; dlnow_last = dlnow; } if (now > time_last + 1) { printf("Speed: %.2f KB/S, Progress: %.2f %%\n", (dlnow - dlnow_last) / (now - time_last) / 1024, dlnow / dltotal * 100); time_last = now; dlnow_last = dlnow; } return 0; } static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata) { return size * nmemb; } void perform(CURLM *multi_handle, CURL *easy_handle) { CURLMcode mcode = curl_multi_add_handle(multi_handle, easy_handle); CURLcode result = CURLE_OK; while (!mcode) { int still_running = 0; int numfds = 0; mcode = curl_multi_perform(multi_handle, &still_running); if (!mcode && !still_running) { int rc; CURLMsg *msg = curl_multi_info_read(multi_handle, &rc); if (msg) { result = msg->data.result; printf("Curl result: %d\n", result); break; } }else { long timeout; curl_multi_timeout(multi_handle, &timeout); if (timeout < 0) { timeout = 100; } curl_multi_wait(multi_handle, NULL, 0, timeout, &numfds); } } curl_multi_remove_handle(multi_handle, easy_handle); } int main() { curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); printf("Curl version: %s\n", data->version); CURLM *multi_handle = curl_multi_init(); if (!multi_handle) { return -1; } CURL *easy_handle = curl_easy_init(); if (!easy_handle) { return -1; } const char *url = "https://xxx.com/file/bin/10MB.bin"; curl_easy_setopt(easy_handle, CURLOPT_URL, url); curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress_callback); curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(easy_handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(easy_handle, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(easy_handle, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t)65535); char range[32] = {'\0'}; strcpy(range, "0-1000000"); curl_easy_setopt(easy_handle, CURLOPT_RANGE, range); perform(multi_handle, easy_handle); strcpy(range, "1000001-2000000"); curl_easy_setopt(easy_handle, CURLOPT_RANGE, range); perform(multi_handle, easy_handle); curl_easy_cleanup(easy_handle); curl_multi_cleanup(multi_handle); return 0; }
The text was updated successfully, but these errors were encountered:
Seems accurate! Can you make a "real" pull request out of this change or would you like me to do it?
Sorry, something went wrong.
It's better for you to do it.
progress: reset limit_size variables at transfer start
7b1e85a
Otherwise the old value would linger from a previous use and would mess up the network speed cap logic. Reported-by: Ymir1711 on github Fixes #7042
1a20689
Successfully merging a pull request may close this issue.
I did this
Download two part of file using the same CURL easy_hanle with maxspeed.
I expected the following
The speed limit is also effective for the second download.
curl/libcurl version
curl-7_76_1
Issue
data->progress.ul_limit_size / data->progress.dl_limit_size was not reset to zero at the beginning.
Diff
Demo
The text was updated successfully, but these errors were encountered: