CURLOPT_XFERINFOFUNCTION(3)
π CURLOPT_XFERINFOFUNCTION(3) π
okay bestie, welcome to the Library Functions Manual page for CURLOPT_XFERINFOFUNCTION(3) β the progress meter callback. it's literally the callback libcurl hits up when it wants to give you progress tea. iconic behavior.
β¨ NAME β¨
CURLOPT_XFERINFOFUNCTION β progress meter callback. that's the whole name, no notes. π
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
int progress_callback(void *clientp,
curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XFERINFOFUNCTION,
progress_callback);
π¦ DESCRIPTION π¦
Pass a pointer to your callback function, which should match the prototype shown above. yes, the exact prototype, bestie β don't freestyle the types. π
This function gets called by libcurl instead of its internal equivalent with a frequent interval. While data is being transferred it gets called frequently, and during slow periods like when nothing is being transferred it can slow down to about one call per second. so it's giving "chatty when busy, chill when idle." β
clientp is the pointer set with CURLOPT_XFERINFODATA(3), it is not used by libcurl but is only passed along from the application to the callback. so it's your little private bag of stuff β libcurl is just the messenger. π«Ά
The callback gets told how much data libcurl is about to transfer and has already transferred, in number of bytes. dltotal is the total number of bytes libcurl expects to download in this transfer. dlnow is the number of bytes downloaded so far. ultotal is the total number of bytes libcurl expects to upload in this transfer. ulnow is the number of bytes uploaded so far. numbers, numbers, numbers but make it cute. π
Unknown/unused argument values passed to the callback are set to zero (like if you only download data, the upload size remains 0). Many times the callback is called one or more times first, before it knows the data sizes so a program must be made to handle that. lowkey important: handle the zeros and the early calls, bestie. π
Return zero from the callback if everything is fine. easy. β¨
Return 1 from this callback to make libcurl abort the transfer and return CURLE_ABORTED_BY_CALLBACK. so if you need to bail, that's the dramatic exit. π
If your callback function returns CURL_PROGRESSFUNC_CONTINUE it makes libcurl to continue executing the default progress function. yes, that's a real return value, don't @ me. π
If you transfer data with the multi interface, this function is not called during periods of idleness unless you call the appropriate libcurl function that performs transfers. so no surprise calls while it's just vibing doing nothing. π΄
CURLOPT_NOPROGRESS(3) must be set to 0 to make this function actually get called. like, actually actually. set it to zero or your callback is just gonna sit there looking cute and never run. π«
π DEFAULT π
NULL β use the internal progress meter. That is rarely wanted by users. respectfully, most people are not trying to keep the default. π
π₯ PROTOCOLS π₯
This functionality affects all supported protocols. all of them. every single one. periodt. π
π§ EXAMPLE π§
struct progress {
char *private;
size_t size;
};
static int xferinfo_callback(void *clientp,
curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow)
{
struct progress *memory = clientp;
printf("my ptr: %p\n", memory->private);
/* use the values */
return 0; /* all is good */
}
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
struct progress data;
/* pass struct to callback */
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &data);
/* enable progress callback getting called */
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo_callback);
}
}
π AVAILABILITY π
Added in curl 7.32.0. vintage-ish but still cute. β¨
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3). so zero = slay, non-zero = check the errors page, bestie. π«Ά
π SEE ALSO π
mwah π β this cutie was brought to you by libcurl, dated 2026-10-12, and it's the CURLOPT_XFERINFOFUNCTION(3) page. bye bestie π«Ά
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms