GNURLOPT_PROGRESSFUNCTION(3)
π GNURLOPT_PROGRESSFUNCTION(3) β curl_easy_setopt options, bestie edition
okay so real talk, this one lives in the curl_easy_setopt options family (gnurl girlies, you know the drill) and it's literally all about getting a callback when your transfer makes progress. let's get into it π
β¨ NAME β¨
CURLOPT_PROGRESSFUNCTION β the callback-to-progress-meter-function situation. that's it, that's the vibe π¦
πΈ SYNOPSIS πΈ
#include <gnurl/curl.h>
int progress_callback(void *clientp,
double dltotal,
double dlnow,
double ultotal,
double ulnow);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROGRESSFUNCTION,
progress_callback);
like, you pass a pointer to your callback function and it has to match that prototype up there exactly. no improvising, bestie π
π DESCRIPTION π
So you hand over a pointer to your callback function (matching the prototype above, fr fr) and libcurl calls yours instead of its own internal equivalent, on a pretty frequent interval. While data is actually being transferred it gets called very frequently β like, constantly, main character energy β and during slow periods, i.e. when nothing's going anywhere, it can chill down to about one call per second. π΄
ngl, the docs themselves say: we encourage users to use the newer CURLOPT_XFERINFOFUNCTION(3) instead, if you can. so likeβ¦ if you can, slay, do that one. β¨
clientp is the pointer you set with CURLOPT_PROGRESSDATA(3). libcurl does not use it β it literally just carries it from your application over to the callback. a little messenger. a vibe courier. π«Ά
The callback gets told how much data libcurl will transfer and how much it has transferred, in number of bytes:
dltotalβ the total number of bytes libcurl expects to download in this transferdlnowβ the number of bytes downloaded so farultotalβ the total number of bytes libcurl expects to upload in this transferulnowβ the number of bytes uploaded so far
Unknown / unused argument values passed to the callback get set to zero (so if you're only downloading data, the upload size stays at 0). and heads up β many times the callback gets called one or more times first, before it even knows the data sizes, so your program absolutely has to be built to handle that. no cap, plan for it π
Now the return value behaviour, and this part is important:
- If your callback returns
CURL_PROGRESSFUNC_CONTINUE, libcurl will continue executing the default progress function. cute, non-disruptive π§ - Returning any other non-zero value will cause libcurl to abort the transfer and return
CURLE_ABORTED_BY_CALLBACK. so like, don't return random non-zero values unless you mean it π
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. you gotta poke it π«΅
And the big one: CURLOPT_NOPROGRESS(3) must be set to 0 to make this function actually get called. set that or your callback is just sitting there, iconic but unemployed π
π DEFAULT π
By default, libcurl has an internal progress meter. That's rarely wanted by users. like, respectfully, nobody's asking for it π
π₯ PROTOCOLS π₯
All β every single one, we love an inclusive queen π
β EXAMPLE β
https://curl.haxx.se/libcurl/c/progressfunc.html
go look at the example, it's giving tutorial π
π AVAILABILITY π
Always β she's been here the whole time π¦
π RETURN VALUE π
Returns CURLE_OK. simple, clean, no drama β¨
π SEE ALSO π
(yeah the trailing comma is literally in the source, leaving it exactly as found, iykyk π«Ά)
π one last vibe check reminder: non-zero return = transfer aborted withCURLE_ABORTED_BY_CALLBACK. andCURLOPT_NOPROGRESS(3)to0or nothing happens at all. periodt.
okay that's the whole page!! brought to you by libcurl 7.37.0, dated 17 Jun 2014 β yes she's vintage, yes she still ate ππ byeee π§ββοΈ
π¦ 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