1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_SOCKOPTDATA
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_OPENSOCKETFUNCTION (3)
9  - CURLOPT_SOCKOPTFUNCTION (3)
10Protocol:
11  - All
12Added-in: 7.16.0
13---
14
15# NAME
16
17CURLOPT_SOCKOPTDATA - pointer to pass to sockopt callback
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTDATA, void *pointer);
25~~~
26
27# DESCRIPTION
28
29Pass a *pointer* that is untouched by libcurl and passed as the first
30argument in the sockopt callback set with CURLOPT_SOCKOPTFUNCTION(3).
31
32# DEFAULT
33
34NULL
35
36# %PROTOCOLS%
37
38# EXAMPLE
39
40~~~c
41static int sockopt_callback(void *clientp, curl_socket_t curlfd,
42                            curlsocktype purpose)
43{
44  int val = *(int *)clientp;
45  setsockopt((int)curlfd, SOL_SOCKET, SO_RCVBUF,
46             (const char *)&val, sizeof(val));
47  return CURL_SOCKOPT_OK;
48}
49
50int main(void)
51{
52  CURL *curl = curl_easy_init();
53  if(curl) {
54    CURLcode res;
55    int recvbuffersize = 256 * 1024;
56
57    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
58
59    /* call this function to set options for the socket */
60    curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
61    curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, &recvbuffersize);
62
63    res = curl_easy_perform(curl);
64
65    curl_easy_cleanup(curl);
66  }
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