GNURLMOPT_SOCKETDATA(3)

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

πŸ’… GNURLMOPT_SOCKETDATA(3) πŸ’…

okay so bestie, this is a page from the curl_multi_setopt options section of the gnurl manual, and it’s lowkey iconic because it’s all about the custom pointer you hand to your socket callback. periodt. ✨

🌸 NAME 🌸

  • CURLMOPT_SOCKETDATA β€” custom pointer passed to the socket callback 🫢

✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETDATA, void *pointer);

πŸ’– DESCRIPTION πŸ’–

okay so CURLMOPT_SOCKETDATA is literally the data pointer you pass to the socket callback that you set with the CURLMOPT_SOCKETFUNCTION(3) option. that’s the whole vibe check. πŸ’…

libcurl will not touch this pointer β€” no cap β€” it will only pass it into the socket callback’s userp argument. so it’s your cute lil’ custom pointer, and libcurl just carries it over fr fr. πŸŽ€

πŸŽ€ DEFAULT πŸŽ€

NULL β€” yep, the default is just NULL, bestie. πŸ™ˆ

πŸ¦‹ PROTOCOLS πŸ¦‹

All β€” every protocol, slay. 🌈

πŸ”₯ EXAMPLE πŸ”₯

the manual’s example is iconic, so here it is exactly:

static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
{
  GlobalInfo *g = (GlobalInfo*) cbp;
  SockInfo *fdp = (SockInfo*) sockp;

  if(what == CURL_POLL_REMOVE) {
    remsock(fdp);
  }
  else {
    if(!fdp) {
      addsock(s, e, what, g);
    }
    else {
      setsock(fdp, s, e, what, g);
    }
  }
  return 0;
}

main()
{
  GlobalInfo setup;
  /* ... use socket callback and custom pointer */
  curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
  curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
}

⭐ AVAILABILITY ⭐

Added in 7.15.4 β€” so this one has been around for a minute. πŸ‘‘

πŸ‘‘ RETURN VALUE πŸ‘‘

Returns CURLM_OK. that’s it, that’s the return value. πŸ’–

🌈 SEE ALSO 🌈


okay bye bestie πŸ’– this page is from libcurl 7.39.0 and dated 3 Nov 2014 β€” periodt, mwah πŸ’‹

πŸ“¦ where this page comes from