CURLOPT_SOCKOPTDATA(3)
π CURLOPT_SOCKOPTDATA(3) π
okay so this is a page from the Library Functions Manual (the libcurl crew π) and it's honestly such a cute lil concept: it's the "give my callback a snack" option. bestie, it's literally one pointer. that's the whole vibe. β¨
β¨ NAME β¨
CURLOPT_SOCKOPTDATA β a pointer to pass to your sockopt callback π«Ά
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTDATA, void *pointer);
π¦ DESCRIPTION π¦
so here's the tea π₯: you hand libcurl a pointer, and libcurl is soooo respectful about it β it does not touch it, periodt. it just holds onto it and passes it straight through as the first argument of your sockopt callback, the one you set with CURLOPT_SOCKOPTFUNCTION(3).
it's giving "here's my emotional support pointer, pls deliver it to my callback untouched" ππ
π DEFAULT π
NULL
(iconic empty-hands behaviour, no notes)
π PROTOCOLS π
this functionality affects all supported protocols β every single one, no cap π
β EXAMPLE β
ok so this is the whole thing, copy it exactly, it's gorgeous:
static int sockopt_callback(void *clientp, curl_socket_t curlfd,
curlsocktype purpose)
{
int val = *(int *)clientp;
setsockopt((int)curlfd, SOL_SOCKET, SO_RCVBUF,
(const char *)&val, sizeof(val));
return CURL_SOCKOPT_OK;
}
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
int recvbuffersize = 256 * 1024;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
/* call this function to set options for the socket */
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &recvbuffersize);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
see how &recvbuffersize (that's 256 * 1024, a whole 256KB of buffer, she's thriving π
) gets handed over as clientp? the callback then dereferences it into val and calls setsockopt((int)curlfd, SOL_SOCKET, SO_RCVBUF, (const char *)&val, sizeof(val)) and returns CURL_SOCKOPT_OK. main character energy, honestly. π
π§ AVAILABILITY π§
Added in curl 7.16.0 β vintage but still slaying π
π RETURN VALUE π
CURLE_OKβ if the option is supported π₯³CURLE_UNKNOWN_OPTIONβ if it's not π
πΈ SEE ALSO πΈ
β οΈ friendly reminder bestie: the pointer is passed through untouched, so keep whatever it points at alive for as long as the callback might need it. no dangling vibes, iykyk π
and that's the whole page, mwah π«Ά this was libcurl version 2026-10-12, page CURLOPT_SOCKOPTDATA(3) β go set some socket options, love u, bye πππ¦
π¦ 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