CURLOPT_SOCKOPTDATA.md (1503B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_SOCKOPTDATA 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_OPENSOCKETFUNCTION (3) 9 - CURLOPT_SOCKOPTFUNCTION (3) 10 Protocol: 11 - All 12 Added-in: 7.16.0 13 --- 14 15 # NAME 16 17 CURLOPT_SOCKOPTDATA - pointer to pass to sockopt callback 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SOCKOPTDATA, void *pointer); 25 ~~~ 26 27 # DESCRIPTION 28 29 Pass a *pointer* that is untouched by libcurl and passed as the first 30 argument in the sockopt callback set with CURLOPT_SOCKOPTFUNCTION(3). 31 32 # DEFAULT 33 34 NULL 35 36 # %PROTOCOLS% 37 38 # EXAMPLE 39 40 ~~~c 41 static 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 50 int 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 74 Returns *CURLE_OK* if the option is supported, and *CURLE_UNKNOWN_OPTION* if not.