GNURLOPT_XFERINFOFUNCTION(3)
π GNURLOPT_XFERINFOFUNCTION π
okay so this page lives in the curl_easy_setopt options manual section (yes, gnurl's β icon behavior), and it's all about one very specific callback. grab a strawberry π and let's go.
β¨ NAME β¨
CURLOPT_XFERINFOFUNCTION β the callback to the progress meter function. that's it, that's the vibe. π
π¦ SYNOPSIS π¦
#include <gnurl/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);
like, copy that prototype exactly, bestie. it is not a suggestion. π
π DESCRIPTION π
so you pass in a pointer to your callback function β and it has to match the prototype shown above, no freelancing. β¨
libcurl calls your function instead of its internal equivalent one, and it does it on a frequent interval. when data is actually moving it gets called very frequently (like, main-character energy frequent), and during slow periods β say, when nothing is being transferred at all β it can chill out to about one call per second. lowkey polite of it.
clientp is the pointer you set with CURLOPT_XFERINFODATA(3). libcurl itself does not use it β it just carries it along from your app to the callback, like a note passed in class. π«Ά
the callback gets told how much data libcurl will transfer and has transferred, in number of bytes:
dltotalβ total number of bytes libcurl expects to download in this transferdlnowβ number of bytes downloaded so farultotalβ total number of bytes libcurl expects to upload in this transferulnowβ number of bytes uploaded so far
unknown / unused argument values passed to the callback get set to zero (so if you're only downloading, the upload size stays 0). and ngl, lots of times the callback gets called once or more first, before it even knows the data sizes β so your program must be built to handle that. fr fr, don't skip that part. π
if your callback returns CURL_PROGRESSFUNC_CONTINUE, libcurl goes ahead and keeps executing the default progress function. slay.
returning any other non-zero value from this callback makes libcurl abort the transfer and return CURLE_ABORTED_BY_CALLBACK. π so like, be careful what you return, okay?
if you transfer data with the multi interface, this function will not be called during periods of idleness β unless you call the appropriate libcurl function that performs transfers. iykyk.
heads up bestie:CURLOPT_NOPROGRESS(3)must be set to0to make this function actually get called. that's the whole vibe check. if you forget, nothing happens and you'll be confused for an hour. π
πΈ DEFAULT πΈ
by default, libcurl has an internal progress meter. that's rarely wanted by users. iconic of libcurl to ship it anyway.
π PROTOCOLS π
All β every single one. π
β EXAMPLE β
https://curl.haxx.se/libcurl/c/progressfunc.html
π§ AVAILABILITY π§
added in 7.32.0. this callback replaces CURLOPT_PROGRESSFUNCTION(3). out with the old, in with the new β¨
π₯ RETURN VALUE π₯
returns CURLE_OK. simple. clean. no notes.
π SEE ALSO π
and that's the page, bestie! π«Ά this little masterpiece came from libcurl 7.37.0, dated 17 Jun 2014 β ancient, but the vibes are timeless. mwah π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms