CURLMOPT_SOCKETDATA(3)

πŸ’… CURLMOPT_SOCKETDATA(3) πŸ’…

ok so this is a page from the Library Functions Manual, and bestie, it's about CURLMOPT_SOCKETDATA β€” the custom pointer you pass to your socket callback. it's giving "little messenger bag of vibes" and honestly? iconic.


✨ NAME ✨

CURLMOPT_SOCKETDATA β€” a custom pointer that gets passed to the socket callback 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: you've got a data pointer, right? and you want it to show up as the clientp argument in your socket callback. that callback is the one you set with the CURLMOPT_SOCKETFUNCTION(3) option. boom, that's it.

the way libcurl handles this pointer: it does not touch it at all. like, zero. it's not dereferencing it, not poking at it, not borrowing it without asking. it literally just hands it to your socket callback as the clientp argument and minds its own business. periodt. πŸ‘‘

so whatever you wanna stash in there? yours. your little treasure chest. πŸ’–


⭐ DEFAULT ⭐

NULL

(it's nothing until you make it something, bestie πŸŽ€)


🌈 PROTOCOLS 🌈

this functionality affects all supported protocols. every single one. no cap. πŸ¦‹


πŸ’œ EXAMPLE πŸ’œ

this example is so cute, it's literally the whole vibe β€” a struct priv holding your pointer, and then sock_cb doing a little vibe check on what to figure out what to do:

struct priv {
  void *ours;
};

static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
{
  struct priv *p = sockp;
  printf("my ptr: %p\n", p->ours);

  if(what == CURL_POLL_REMOVE) {
    /* remove the socket from our collection */
  }
  if(what & CURL_POLL_IN) {
    /* wait for read on this socket */
  }
  if(what & CURL_POLL_OUT) {
    /* wait for write on this socket */
  }

  return 0;
}

int main(void)
{
  struct priv setup;
  CURLM *multi = curl_multi_init();
  /* ... use socket callback and custom pointer */
  curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
  curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup);
}

see how CURLMOPT_SOCKETFUNCTION gets the callback and CURLMOPT_SOCKETDATA gets &setup? they're a matching set, bestie. soulmate options. ✨


🌸 AVAILABILITY 🌸

added in curl 7.15.4 β€” vintage, but make it fashion. πŸ‘‘


πŸ’… RETURN VALUE πŸ’…

returns CURLM_OK. that's it. slay. πŸŽ€


πŸ”₯ SEE ALSO πŸ”₯


ok that's the whole page, you ate that 🫢 this little gem is brought to you by libcurl, dated 2026-10-12, and honestly the copyright/license vibes are right there in the source if you need them β€” go be the main character of your own event loop πŸ’–βœ¨πŸŒ·

πŸ“¦ where this page comes from