Progress information
The progress callback is what gets called regularly and repeatedly for eachtransfer during the entire lifetime of the transfer. The old callback was setwithCURLOPT_PROGRESSFUNCTION
but the modern and preferred callback is setwithCURLOPT_XFERINFOFUNCTION
:
curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, xfer_callback);
Thexfer_callback
function must match this prototype:
int xfer_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
If this option is set andCURLOPT_NOPROGRESS
is set to 0 (zero), thiscallback function gets called by libcurl with a frequent interval. While datais being transferred it gets called frequently, and during slow periods likewhen nothing is being transferred it can slow down to about one call persecond.
Theclientp pointer points to the private data set withCURLOPT_XFERINFODATA
:
curl_easy_setopt(handle, CURLOPT_XFERINFODATA, custom_pointer);
The callback gets told how much data libcurl is about to transfer and hastransferred, in number of bytes:
dltotal
is the total number of bytes libcurl expects to download inthis transfer.dlnow
is the number of bytes downloaded so far.ultotal
is the total number of bytes libcurl expects to upload in thistransfer.ulnow
is the number of bytes uploaded so far.
Unknown/unused argument values passed to the callback are set to zero (like ifyou only download data, the upload size remains zero). Many times the callbackis called one or more times first, before it knows the data sizes, so aprogram must be made to handle that.
Returning a non-zero value from this callback causes libcurl to abort thetransfer and returnCURLE_ABORTED_BY_CALLBACK
.
If you transfer data with the multi interface, this function is not calledduring periods of idleness unless you call the appropriate libcurl functionthat performs transfers.
(The deprecated callbackCURLOPT_PROGRESSFUNCTION
worked identically butinstead of taking arguments of typecurl_off_t
, it useddouble
.)