1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLMOPT_TIMERFUNCTION 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLMOPT_SOCKETFUNCTION (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLMOPT_TIMERDATA (3) 10*6236dae4SAndroid Build Coastguard WorkerProtocol: 11*6236dae4SAndroid Build Coastguard Worker - All 12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.16.0 13*6236dae4SAndroid Build Coastguard Worker--- 14*6236dae4SAndroid Build Coastguard Worker 15*6236dae4SAndroid Build Coastguard Worker# NAME 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard WorkerCURLMOPT_TIMERFUNCTION - callback to receive timeout values 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker~~~c 22*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard Workerint timer_callback(CURLM *multi, /* multi handle */ 25*6236dae4SAndroid Build Coastguard Worker long timeout_ms, /* timeout in number of ms */ 26*6236dae4SAndroid Build Coastguard Worker void *clientp); /* private callback pointer */ 27*6236dae4SAndroid Build Coastguard Worker 28*6236dae4SAndroid Build Coastguard WorkerCURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_TIMERFUNCTION, timer_callback); 29*6236dae4SAndroid Build Coastguard Worker~~~ 30*6236dae4SAndroid Build Coastguard Worker 31*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 32*6236dae4SAndroid Build Coastguard Worker 33*6236dae4SAndroid Build Coastguard WorkerPass a pointer to your callback function, which should match the prototype 34*6236dae4SAndroid Build Coastguard Workershown above. 35*6236dae4SAndroid Build Coastguard Worker 36*6236dae4SAndroid Build Coastguard WorkerCertain features, such as timeouts and retries, require you to call libcurl 37*6236dae4SAndroid Build Coastguard Workereven when there is no activity on the file descriptors. 38*6236dae4SAndroid Build Coastguard Worker 39*6236dae4SAndroid Build Coastguard WorkerYour callback function **timer_callback** should install a single 40*6236dae4SAndroid Build Coastguard Workernon-repeating timer with an expire time of **timeout_ms** milliseconds. When 41*6236dae4SAndroid Build Coastguard Workerthat timer fires, call either curl_multi_socket_action(3) or 42*6236dae4SAndroid Build Coastguard Workercurl_multi_perform(3), depending on which interface you use. 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard WorkerIf this callback is called when a timer is already running, this new expire 45*6236dae4SAndroid Build Coastguard Workertime *replaces* the former timeout. The application should then effectively 46*6236dae4SAndroid Build Coastguard Workercancel the old timeout and set a new timeout using this new expire time. 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard WorkerA **timeout_ms** value of -1 passed to this callback means you should delete 49*6236dae4SAndroid Build Coastguard Workerthe timer. All other values are valid expire times in number of milliseconds. 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard WorkerThe **timer_callback** is called when the timeout expire time is changed. 52*6236dae4SAndroid Build Coastguard Worker 53*6236dae4SAndroid Build Coastguard WorkerThe **clientp** pointer is set with CURLMOPT_TIMERDATA(3). 54*6236dae4SAndroid Build Coastguard Worker 55*6236dae4SAndroid Build Coastguard WorkerThe timer callback should return 0 on success, and -1 on error. If this 56*6236dae4SAndroid Build Coastguard Workercallback returns error, **all** transfers currently in progress in this multi 57*6236dae4SAndroid Build Coastguard Workerhandle are aborted and made to fail. 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard WorkerThis callback can be used instead of, or in addition to, 60*6236dae4SAndroid Build Coastguard Workercurl_multi_timeout(3). 61*6236dae4SAndroid Build Coastguard Worker 62*6236dae4SAndroid Build Coastguard Worker**WARNING:** do not call libcurl directly from within the callback itself when 63*6236dae4SAndroid Build Coastguard Workerthe **timeout_ms** value is zero, since it risks triggering an unpleasant 64*6236dae4SAndroid Build Coastguard Workerrecursive behavior that immediately calls another call to the callback with a 65*6236dae4SAndroid Build Coastguard Workerzero timeout... 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard Worker# DEFAULT 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard WorkerNULL 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 74*6236dae4SAndroid Build Coastguard Worker 75*6236dae4SAndroid Build Coastguard Worker~~~c 76*6236dae4SAndroid Build Coastguard Workerstruct priv { 77*6236dae4SAndroid Build Coastguard Worker void *custom; 78*6236dae4SAndroid Build Coastguard Worker}; 79*6236dae4SAndroid Build Coastguard Worker 80*6236dae4SAndroid Build Coastguard Workerstatic int timerfunc(CURLM *multi, long timeout_ms, void *clientp) 81*6236dae4SAndroid Build Coastguard Worker{ 82*6236dae4SAndroid Build Coastguard Worker struct priv *mydata = clientp; 83*6236dae4SAndroid Build Coastguard Worker printf("our ptr: %p\n", mydata->custom); 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard Worker if(timeout_ms) { 86*6236dae4SAndroid Build Coastguard Worker /* this is the new single timeout to wait for */ 87*6236dae4SAndroid Build Coastguard Worker } 88*6236dae4SAndroid Build Coastguard Worker else { 89*6236dae4SAndroid Build Coastguard Worker /* delete the timeout, nothing to wait for now */ 90*6236dae4SAndroid Build Coastguard Worker } 91*6236dae4SAndroid Build Coastguard Worker} 92*6236dae4SAndroid Build Coastguard Worker 93*6236dae4SAndroid Build Coastguard Workerint main(void) 94*6236dae4SAndroid Build Coastguard Worker{ 95*6236dae4SAndroid Build Coastguard Worker struct priv mydata; 96*6236dae4SAndroid Build Coastguard Worker CURLM *multi = curl_multi_init(); 97*6236dae4SAndroid Build Coastguard Worker curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, timerfunc); 98*6236dae4SAndroid Build Coastguard Worker curl_multi_setopt(multi, CURLMOPT_TIMERDATA, &mydata); 99*6236dae4SAndroid Build Coastguard Worker} 100*6236dae4SAndroid Build Coastguard Worker~~~ 101*6236dae4SAndroid Build Coastguard Worker 102*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 103*6236dae4SAndroid Build Coastguard Worker 104*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 105*6236dae4SAndroid Build Coastguard Worker 106*6236dae4SAndroid Build Coastguard WorkerReturns CURLM_OK if the option is supported, and CURLM_UNKNOWN_OPTION if not. 107