aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2013-06-15 14:57:01 +0200
committerDaniel Stenberg <daniel@haxx.se>2013-07-18 23:44:06 +0200
commit12d01cb6fa914519d1ced0223cd9ff96a2634de9 (patch)
treedb88a3af7f2868b6da72aab5543495b73786600e /lib
parent90695fb2c508803a09581b0ca8f55eaa36749a69 (diff)
CURLOPT_XFERINFOFUNCTION: introducing a new progress callback
CURLOPT_XFERINFOFUNCTION is now the preferred progress callback function and CURLOPT_PROGRESSFUNCTION is considered deprecated. This new callback uses pure 'curl_off_t' arguments to pass on full resolution sizes. It otherwise retains the same characteristics: the same call rate, the same meanings for the arguments and the return code is used the same way. The progressfunc.c example is updated to show how to use the new callback for newer libcurls while supporting the older one if built with an older libcurl or even built with a newer libcurl while running with an older.
Diffstat (limited to 'lib')
-rw-r--r--lib/progress.c19
-rw-r--r--lib/url.c12
-rw-r--r--lib/urldata.h3
3 files changed, 28 insertions, 6 deletions
diff --git a/lib/progress.c b/lib/progress.c
index 4cff2b76e..dac7f8d6e 100644
--- a/lib/progress.c
+++ b/lib/progress.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2013, 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
@@ -357,12 +357,21 @@ int Curl_pgrsUpdate(struct connectdata *conn)
} /* 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. */
+ if(data->set.fxferinfo) {
+ /* There's a callback set, call that */
+ result= data->set.fxferinfo(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;
+ }
+ else if(data->set.fprogress) {
+ /* The older deprecated callback is set, call that */
result= data->set.fprogress(data->set.progress_client,
(double)data->progress.size_dl,
(double)data->progress.downloaded,
diff --git a/lib/url.c b/lib/url.c
index c2bbfb30b..cda4e4825 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -1609,8 +1609,20 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
data->progress.callback = TRUE; /* no longer internal */
else
data->progress.callback = FALSE; /* NULL enforces internal */
+ break;
+
+ case CURLOPT_XFERINFOFUNCTION:
+ /*
+ * Transfer info callback function
+ */
+ data->set.fxferinfo = va_arg(param, curl_xferinfo_callback);
+ if(data->set.fxferinfo)
+ data->progress.callback = TRUE; /* no longer internal */
+ else
+ data->progress.callback = FALSE; /* NULL enforces internal */
break;
+
case CURLOPT_PROGRESSDATA:
/*
* Custom client data to pass to the progress callback
diff --git a/lib/urldata.h b/lib/urldata.h
index 47841e1f4..e245bfb4f 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1428,7 +1428,8 @@ struct UserDefined {
curl_read_callback fread_func; /* function that reads the input */
int is_fread_set; /* boolean, has read callback been set to non-NULL? */
int is_fwrite_set; /* boolean, has write callback been set to non-NULL? */
- curl_progress_callback fprogress; /* function for progress information */
+ curl_progress_callback fprogress; /* OLD and deprecated progress callback */
+ curl_xferinfo_callback fxferinfo; /* progress callback */
curl_debug_callback fdebug; /* function that write informational data */
curl_ioctl_callback ioctl_func; /* function for I/O control */
curl_sockopt_callback fsockopt; /* function for setting socket options */