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