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