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