1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLMOPT_SOCKETDATA 5Section: 3 6Source: libcurl 7See-also: 8 - CURLMOPT_SOCKETFUNCTION (3) 9 - CURLMOPT_TIMERFUNCTION (3) 10 - curl_multi_socket_action (3) 11Protocol: 12 - All 13Added-in: 7.15.4 14--- 15 16# NAME 17 18CURLMOPT_SOCKETDATA - custom pointer passed to the socket callback 19 20# SYNOPSIS 21 22~~~c 23#include <curl/curl.h> 24 25CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_SOCKETDATA, void *pointer); 26~~~ 27 28# DESCRIPTION 29 30A data *pointer* to pass to the socket callback set with the 31CURLMOPT_SOCKETFUNCTION(3) option. 32 33This pointer is not touched by libcurl but is only passed in as the socket 34callback's **clientp** argument. 35 36# DEFAULT 37 38NULL 39 40# %PROTOCOLS% 41 42# EXAMPLE 43 44~~~c 45struct priv { 46 void *ours; 47}; 48 49static 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 67int 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 81Returns CURLM_OK. 82