CURLMOPT_SOCKETDATA.md (1487B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLMOPT_SOCKETDATA 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLMOPT_SOCKETFUNCTION (3) 9 - CURLMOPT_TIMERFUNCTION (3) 10 - curl_multi_socket_action (3) 11 Protocol: 12 - All 13 Added-in: 7.15.4 14 --- 15 16 # NAME 17 18 CURLMOPT_SOCKETDATA - custom pointer passed to the socket callback 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETDATA, void *pointer); 26 ~~~ 27 28 # DESCRIPTION 29 30 A data *pointer* to pass to the socket callback set with the 31 CURLMOPT_SOCKETFUNCTION(3) option. 32 33 This pointer is not touched by libcurl but is only passed in as the socket 34 callback's **clientp** argument. 35 36 # DEFAULT 37 38 NULL 39 40 # %PROTOCOLS% 41 42 # EXAMPLE 43 44 ~~~c 45 struct priv { 46 void *ours; 47 }; 48 49 static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) 50 { 51 struct priv *p = sockp; 52 printf("my ptr: %p\n", p->ours); 53 54 if(what == CURL_POLL_REMOVE) { 55 /* remove the socket from our collection */ 56 } 57 if(what & CURL_POLL_IN) { 58 /* wait for read on this socket */ 59 } 60 if(what & CURL_POLL_OUT) { 61 /* wait for write on this socket */ 62 } 63 64 return 0; 65 } 66 67 int main(void) 68 { 69 struct priv setup; 70 CURLM *multi = curl_multi_init(); 71 /* ... use socket callback and custom pointer */ 72 curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, sock_cb); 73 curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, &setup); 74 } 75 ~~~ 76 77 # %AVAILABILITY% 78 79 # RETURN VALUE 80 81 Returns CURLM_OK.