1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_CLOSESOCKETDATA 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_CLOSESOCKETFUNCTION (3) 9 - CURLOPT_OPENSOCKETFUNCTION (3) 10Protocol: 11 - All 12--- 13 14# NAME 15 16CURLOPT_CLOSESOCKETDATA - pointer passed to the socket close callback 17 18# SYNOPSIS 19 20~~~c 21#include <curl/curl.h> 22 23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CLOSESOCKETDATA, 24 void *pointer); 25~~~ 26 27# DESCRIPTION 28 29Pass a *pointer* that remains untouched by libcurl and passed as the first 30argument in the closesocket callback set with 31CURLOPT_CLOSESOCKETFUNCTION(3). 32 33# DEFAULT 34 35The default value of this parameter is NULL. 36 37# EXAMPLE 38 39~~~c 40struct priv { 41 void *custom; 42}; 43 44static int closesocket(void *clientp, curl_socket_t item) 45{ 46 struct priv *my = clientp; 47 printf("our ptr: %p\n", my->custom); 48 49 printf("libcurl wants to close %d now\n", (int)item); 50 return 0; 51} 52 53int main(void) 54{ 55 struct priv myown; 56 CURL *curl = curl_easy_init(); 57 58 /* call this function to close sockets */ 59 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket); 60 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &myown); 61 62 curl_easy_perform(curl); 63 curl_easy_cleanup(curl); 64} 65~~~ 66 67# AVAILABILITY 68 69Added in 7.21.7 70 71# RETURN VALUE 72 73Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 74