On 30 November 2011 23:04, Daniel Stenberg <[email protected]> wrote: > On Wed, 30 Nov 2011, Rob Ward wrote: > > I would have thought that a time counter is an obvious solution however >> maybe using the curl time isn't? It may very well be suitable to add it >> directly into the Progress example, this would then also show how to use >> the transaction timing as well. If that is OK and what's desired I can make >> a patch that adds it. >> > > No, you're right. Using the curl time isn't as obvious. I think it sounds > like a good idea! > > > -- > > / daniel.haxx.se > ------------------------------**------------------------------**------- > List admin: > http://cool.haxx.se/list/**listinfo/curl-library<http://cool.haxx.se/list/listinfo/curl-library> > Etiquette: > http://curl.haxx.se/mail/**etiquette.html<http://curl.haxx.se/mail/etiquette.html> >
First pass on the patch that add this to the progress example attached for review. Let me know about any changes that are desired. I've tested this on a large file from my server(I slowed connection to make it easier and made the limit for amount to download higher for the test). Cheers, Rob -- ------------------------------ Rob Ward www.rob-ward.co.uk
From 1624a0f26898b81cd548cb66f6e302afb2bf7bb8 Mon Sep 17 00:00:00 2001 From: Rob Ward <[email protected]> Date: Thu, 1 Dec 2011 09:20:40 +0000 Subject: [PATCH] Example: Edit progress function example - include timed interval Adds a timer based off of CURLINFO_TOTAL_TIME that is used to perform certain actions after a minimum amount of time has passed using the progress function. As a consequence the curl handle is now also passed into the progress function. Progress example now also includes an example of how to retreive the TOTAL_TIME and print it out. --- docs/examples/progressfunc.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/docs/examples/progressfunc.c b/docs/examples/progressfunc.c index 42ed328..cb9fd94 100644 --- a/docs/examples/progressfunc.c +++ b/docs/examples/progressfunc.c @@ -22,17 +22,34 @@ #include <stdio.h> #include <curl/curl.h> -#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000 +#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000 +#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3 + +double lastruntime = 0; static int progress(void *p, double dltotal, double dlnow, double ultotal, double ulnow) { + CURL* curl = (CURL*)p; + double curtime = 0; + + curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime); + + //under certain circumstances it may be desirable for certain functionality + //to only fun every N seconds, in order to do this the transaction time can + //be used + if((curtime - lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL) { + lastruntime = curtime; + fprintf(stderr, "TOTAL TIME: %f \r\n", curtime); + } + fprintf(stderr, "UP: %g of %g DOWN: %g of %g\r\n", ulnow, ultotal, dlnow, dltotal); if(dlnow > STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES) return 1; + return 0; } @@ -45,7 +62,11 @@ int main(void) if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, curl); //pass the curl + //pointer into the + //progress function curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); + res = curl_easy_perform(curl); if(res) -- 1.7.4.1
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
