CURLOPT_CLOSESOCKETDATA(3)
π NAME π
okay bestie, welcome to the CURLOPT_CLOSESOCKETDATA(3) page from the Library Functions Manual β this one is all about the pointer passed to the socket close callback. slay, very niche, very useful π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CLOSESOCKETDATA,
void *pointer);
π¦ DESCRIPTION π¦
So you pass in a pointer, right? And libcurl literally leaves it untouched β no cap, it does not mess with it. Then libcurl passes that same pointer as the first argument in the closesocket callback that you set with CURLOPT_CLOSESOCKETFUNCTION(3). itβs giving βcustom data, but make it socket-close flavoredβ π
β οΈ heads up bestie: when youβre using multi/share handles, your callback may get invoked even after the easy handle has been cleaned up. The callback and data are inherited by a new connection, and that connection may live longer than the transfer itself in the multi/share handleβs connection cache. iykyk π
π DEFAULT π
NULL
like, nothing by default. no data, no drama π«Ά
π PROTOCOLS π
This functionality affects all supported protocols. every single one, periodt β¨
π EXAMPLE π
struct priv {
void *custom;
};
static int closesocket(void *clientp, curl_socket_t item)
{
struct priv *my = clientp;
printf("our ptr: %p\n", my->custom);
printf("libcurl wants to close %d now\n", (int)item);
return 0;
}
int main(void)
{
struct priv myown;
CURL *curl = curl_easy_init();
/* call this function to close sockets */
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
π AVAILABILITY π
Added in curl 7.21.7 β vintage but iconic π
π₯ RETURN VALUE π₯
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK(0) means everything was OK β we love a zero π- non-zero means an error occurred, so go see
libcurl-errors(3)bestie π
π§ SEE ALSO π§
go read those too, theyβre the friend group of this page πΈ
mwah π β source/version: libcurl Β· date: 2026-10-12 Β· this little icon has been served fresh π
π¦ 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