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