CURLMOPT_TIMERDATA.md (1471B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLMOPT_TIMERDATA 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLMOPT_SOCKETFUNCTION (3) 9 - CURLMOPT_TIMERFUNCTION (3) 10 Protocol: 11 - All 12 Added-in: 7.16.0 13 --- 14 15 # NAME 16 17 CURLMOPT_TIMERDATA - custom pointer to pass to timer callback 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERDATA, void *pointer); 25 ~~~ 26 27 # DESCRIPTION 28 29 A data **pointer** to pass to the timer callback set with the 30 CURLMOPT_TIMERFUNCTION(3) option. 31 32 This pointer is not touched by libcurl but is only be passed in to the timer 33 callback's **clientp** argument. 34 35 # DEFAULT 36 37 NULL 38 39 # %PROTOCOLS% 40 41 # EXAMPLE 42 43 ~~~c 44 struct priv { 45 void *custom; 46 }; 47 48 static int timerfunc(CURLM *multi, long timeout_ms, void *clientp) 49 { 50 struct priv *mydata = clientp; 51 printf("our ptr: %p\n", mydata->custom); 52 53 if(timeout_ms >= 0) { 54 /* this is the new single timeout to wait for */ 55 } 56 else { 57 /* delete the timeout, nothing to wait for now */ 58 } 59 return 0; 60 } 61 62 int main(void) 63 { 64 struct priv mydata; 65 CURLM *multi = curl_multi_init(); 66 curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc); 67 curl_multi_setopt(multi, CURLMOPT_TIMERDATA, &mydata); 68 } 69 ~~~ 70 71 # %AVAILABILITY% 72 73 # RETURN VALUE 74 75 curl_multi_setopt(3) returns a CURLMcode indicating success or error. 76 77 CURLM_OK (0) means everything was OK, non-zero means an error occurred, see 78 libcurl-errors(3).