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