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