GNURLMOPT_TIMERDATA(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸŽ€ 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