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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms