1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_XFERINFOFUNCTION 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_NOPROGRESS (3) 9 - CURLOPT_XFERINFODATA (3) 10Protocol: 11 - All 12Added-in: 7.32.0 13--- 14 15# NAME 16 17CURLOPT_XFERINFOFUNCTION - progress meter callback 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24int progress_callback(void *clientp, 25 curl_off_t dltotal, 26 curl_off_t dlnow, 27 curl_off_t ultotal, 28 curl_off_t ulnow); 29 30CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XFERINFOFUNCTION, 31 progress_callback); 32~~~ 33 34# DESCRIPTION 35 36Pass a pointer to your callback function, which should match the prototype 37shown above. 38 39This function gets called by libcurl instead of its internal equivalent with a 40frequent interval. While data is being transferred it gets called frequently, 41and during slow periods like when nothing is being transferred it can slow 42down to about one call per second. 43 44*clientp* is the pointer set with CURLOPT_XFERINFODATA(3), it is not 45used by libcurl but is only passed along from the application to the callback. 46 47The callback gets told how much data libcurl is about to transfer and has 48already transferred, in number of bytes. *dltotal* is the total number of 49bytes libcurl expects to download in this transfer. *dlnow* is the number 50of bytes downloaded so far. *ultotal* is the total number of bytes libcurl 51expects to upload in this transfer. *ulnow* is the number of bytes 52uploaded so far. 53 54Unknown/unused argument values passed to the callback are set to zero (like if 55you only download data, the upload size remains 0). Many times the callback is 56called one or more times first, before it knows the data sizes so a program 57must be made to handle that. 58 59Return zero from the callback if everything is fine. 60 61Return 1 from this callback to make libcurl abort the transfer and return 62*CURLE_ABORTED_BY_CALLBACK*. 63 64If your callback function returns CURL_PROGRESSFUNC_CONTINUE it makes libcurl 65to continue executing the default progress function. 66 67If you transfer data with the multi interface, this function is not called 68during periods of idleness unless you call the appropriate libcurl function 69that performs transfers. 70 71CURLOPT_NOPROGRESS(3) must be set to 0 to make this function actually 72get called. 73 74# DEFAULT 75 76NULL - use the internal progress meter. That is rarely wanted by users. 77 78# %PROTOCOLS% 79 80# EXAMPLE 81 82~~~c 83struct progress { 84 char *private; 85 size_t size; 86}; 87 88static size_t progress_callback(void *clientp, 89 curl_off_t dltotal, 90 curl_off_t dlnow, 91 curl_off_t ultotal, 92 curl_off_t ulnow) 93{ 94 struct progress *memory = clientp; 95 printf("my ptr: %p\n", memory->private); 96 97 /* use the values */ 98 99 return 0; /* all is good */ 100} 101 102int main(void) 103{ 104 CURL *curl = curl_easy_init(); 105 if(curl) { 106 struct progress data; 107 108 /* pass struct to callback */ 109 curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &data); 110 111 /* enable progress callback getting called */ 112 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); 113 114 curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback); 115 } 116} 117~~~ 118 119# %AVAILABILITY% 120 121# RETURN VALUE 122 123Returns CURLE_OK. 124