GNURLMOPT_TIMERDATA(3)
π GNURLMOPT_TIMERDATA(3) π
okay bestie, so this page lives in the curl_multi_setopt options section of the manual (that's the family it belongs to, iykyk) and it's all about one tiny little pointer. let's get into it π
β¨ NAME β¨
CURLMOPT_TIMERDATA β a custom pointer you get to pass along to your timer callback π«Ά
β¨ SYNOPSIS β¨
#include <gnurl/curl.h>
CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERDATA, void *pointer);
β¨ DESCRIPTION β¨
so basically this is a data pointer π« β you hand it over and it gets passed to the timer callback that you set with the CURLMOPT_TIMERFUNCTION(3) option. that's it. that's the whole job.
and the important part, no cap: libcurl will not touch this pointer. like, at all. it doesn't peek at it, it doesn't free it, it doesn't reorganize it. it only ever gets passed in to the timer callback's userp argument. your pointer, your business π
β¨ DEFAULT β¨
NULL
(iconic, honestly. starts out empty πΈ)
β¨ PROTOCOLS β¨
All β every single one of them, periodt π
β¨ EXAMPLE β¨
lowkey a whole GLib situation in here, but it slays:
static gboolean timeout_cb(gpointer user_data)
{
int running;
if(user_data) {
g_free(user_data);
curl_multi_setopt(curl_handle, CURLMOPT_TIMERDATA, NULL);
}
curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running);
return G_SOURCE_REMOVE;
}
static int timerfunc(CURLM *multi, long timeout_ms, void *userp)
{
guint *id = userp;
if(id)
g_source_remove(*id);
/* -1 means we should just delete our timer. */
if(timeout_ms == -1) {
g_free(id);
id = NULL;
}
else {
if(!id)
id = g_new(guint, 1);
*id = g_timeout_add(timeout_ms, timeout_cb, id);
}
curl_multi_setopt(multi, CURLMOPT_TIMERDATA, id);
return 0;
}
curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc);
β¨ AVAILABILITY β¨
added in 7.16.0 π°οΈ (yes she's been around a minute, respect her)
β¨ RETURN VALUE β¨
CURLM_OKβ slay, the option is supported πCURLM_UNKNOWN_OPTIONβ nope, not supported π
β¨ SEE ALSO β¨
π reminder bestie: this pointer is yours to manage. libcurl is literally never gonna free it for you, so if you malloc it, you're the one who has to clean it up. main character responsibility β¨
that's the whole page, you ate that π mwah π
libcurl 7.37.0 Β· 17 Jun 2014 β that's the version and date this little love letter shipped with, bye bestie π¦π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2017, 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