GNURLOPT_C...ETFUNCTION(3)
π NAME π β GNURLOPT_C...ETFUNCTION(3) from the curl_easy_setopt options manual π
okay so bestie, this whole page is about CURLOPT_CLOSESOCKETFUNCTION β a callback to socket close replacement function. yes, that's the vibe. π«Ά
β¨ SYNOPSIS β¨
like, here's the exact shape of it, no cap:
#include <gnurl/curl.h>
int closesocket_callback(void *clientp, curl_socket_t item);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CLOSESOCKETFUNCTION,
closesocket_callback);
π¦ DESCRIPTION π¦
Pass a pointer to your callback function β it should match the prototype shown above, bestie. π
This callback function gets called by libcurl instead of the close(3) or closesocket(3) call when sockets are closed. and this is literally not for any other file descriptors, okay? It's pretty much the reverse to the CURLOPT_OPENSOCKETFUNCTION(3) option. Return 0 to signal success and 1 if there was an error. π₯
The clientp pointer is set with CURLOPT_CLOSESOCKETDATA(3). item is the socket libcurl wants to be closed. π
πΈ DEFAULT πΈ
By default libcurl uses the standard socket close function. classic default behavior, lowkey iconic. β¨
π PROTOCOLS π
All β periodt. π
π EXAMPLE π
here's the example in all its main-character glory:
static int closesocket(void *clientp, curl_socket_t item)
{
printf("libcurl wants to close %d now\n", (int)item);
return 0;
}
/* call this function to close sockets */
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket);
curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &sockfd);
β AVAILABILITY β
Added in 7.21.7. π«
π RETURN VALUE π
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. fr fr. π«Ά
π§ SEE ALSO π§
(yes, that trailing comma on the second one is giving original paperwork energy, and we kept it π)
cute lil sign-off: this page says libcurl 7.37.0 and 16 Jun 2014 at the bottom, so mwah π β that's the source/version and date, bestie. π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms