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