[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 10/163: examples/progressfunc: make it build on old
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 10/163: examples/progressfunc: make it build on older libcurls |
Date: |
Sun, 05 Aug 2018 12:35:36 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository gnurl.
commit ccf85d4c2b1b2fac2f6cbac31d719bfa73b76ed2
Author: Daniel Stenberg <address@hidden>
AuthorDate: Fri May 18 10:28:17 2018 +0200
examples/progressfunc: make it build on older libcurls
This example was changed in ce2140a8c1 to use the new microsecond based
getinfo option. This change makes it conditionally keep using the older
option so that the example still builds with older libcurl versions.
Closes #2584
---
docs/examples/progressfunc.c | 39 +++++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/docs/examples/progressfunc.c b/docs/examples/progressfunc.c
index 52a3c0834..51d75366c 100644
--- a/docs/examples/progressfunc.c
+++ b/docs/examples/progressfunc.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <address@hidden>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <address@hidden>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -27,11 +27,25 @@
#include <stdio.h>
#include <curl/curl.h>
-#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000
+#if LIBCURL_VERSION_NUM >= 0x073d00
+/* In libcurl 7.61.0, support was added for extracting the time in plain
+ microseconds. Older libcurl versions are stuck in using 'double' for this
+ information so we complicate this example a bit by supporting either
+ approach. */
+#define TIME_IN_US 1 /* microseconds */
+#define TIMETYPE curl_off_t
+#define TIMEOPT CURLINFO_TOTAL_TIME_T
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3000000
+#else
+#define TIMETYPE double
+#define TIMEOPT CURLINFO_TOTAL_TIME
+#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3
+#endif
+
+#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000
struct myprogress {
- curl_off_t lastruntime;
+ TIMETYPE lastruntime; /* type depends on version, see above */
CURL *curl;
};
@@ -42,17 +56,21 @@ static int xferinfo(void *p,
{
struct myprogress *myp = (struct myprogress *)p;
CURL *curl = myp->curl;
- curl_off_t curtime = 0;
+ TIMETYPE curtime = 0;
- curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &curtime);
+ curl_easy_getinfo(curl, TIMEOPT, &curtime);
/* under certain circumstances it may be desirable for certain functionality
to only run every N seconds, in order to do this the transaction time can
be used */
if((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL) {
myp->lastruntime = curtime;
+#ifdef TIME_IN_US
fprintf(stderr, "TOTAL TIME: %" CURL_FORMAT_CURL_OFF_T ".%06ld\r\n",
(curtime / 1000000), (long)(curtime % 1000000));
+#else
+ fprintf(stderr, "TOTAL TIME: %f \r\n", curtime);
+#endif
}
fprintf(stderr, "UP: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
@@ -65,6 +83,7 @@ static int xferinfo(void *p,
return 0;
}
+#if LIBCURL_VERSION_NUM < 0x072000
/* for libcurl older than 7.32.0 (CURLOPT_PROGRESSFUNCTION) */
static int older_progress(void *p,
double dltotal, double dlnow,
@@ -76,7 +95,7 @@ static int older_progress(void *p,
(curl_off_t)ultotal,
(curl_off_t)ulnow);
}
-
+#endif
int main(void)
{
@@ -91,10 +110,6 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
- curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, older_progress);
- /* pass the struct pointer into the progress function */
- curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &prog);
-
#if LIBCURL_VERSION_NUM >= 0x072000
/* xferinfo was introduced in 7.32.0, no earlier libcurl versions will
compile as they won't have the symbols around.
@@ -110,6 +125,10 @@ int main(void)
/* pass the struct pointer into the xferinfo function, note that this is
an alias to CURLOPT_PROGRESSDATA */
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog);
+#else
+ curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, older_progress);
+ /* pass the struct pointer into the progress function */
+ curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &prog);
#endif
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] branch master updated (cb5937f5c -> 2a23ac742), gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 03/163: rand: fix typo, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 02/163: schannel: disable manual verify if APIs not available, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 12/163: checksrc: fix too long line, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 04/163: schannel_verify: fix build for non-schannel, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 07/163: openssl: acknowledge --tls-max for default version too, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 13/163: curl_fnmatch: only allow two asterisks for matching, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 09/163: stub_gssapi: fix numerous 'unused parameter' warnings, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 10/163: examples/progressfunc: make it build on older libcurls,
gnunet <=
- [GNUnet-SVN] [gnurl] 01/163: schannel: disable client cert option if APIs not available, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 05/163: tests/libtest/Makefile: Do not unconditionally add gcc-specific flags, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 15/163: configure: replace AC_TRY_RUN with CURL_RUN_IFELSE, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 23/163: schannel: make CAinfo parsing resilient to CR/LF, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 35/163: schannel: add failf calls for client certificate failures, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 25/163: tftp: make sure error is zero terminated before printfing it, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 06/163: bump: start working on the pending 7.61.0, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 20/163: KNOWN_BUGS: mention the -O with %-encoded file names, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 22/163: CURLOPT_ACCEPT_ENCODING.3: add brotli and clarify a bit, gnunet, 2018/08/05
- [GNUnet-SVN] [gnurl] 11/163: docs: mention HAproxy protocol "version 1", gnunet, 2018/08/05