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: curl_multi_timeout 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - curl_multi_fdset (3) 9*6236dae4SAndroid Build Coastguard Worker - curl_multi_info_read (3) 10*6236dae4SAndroid Build Coastguard Worker - curl_multi_setopt (3) 11*6236dae4SAndroid Build Coastguard Worker - curl_multi_socket (3) 12*6236dae4SAndroid Build Coastguard WorkerProtocol: 13*6236dae4SAndroid Build Coastguard Worker - All 14*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.15.4 15*6236dae4SAndroid Build Coastguard Worker--- 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard Worker# NAME 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Workercurl_multi_timeout - how long to wait for action before proceeding 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 22*6236dae4SAndroid Build Coastguard Worker 23*6236dae4SAndroid Build Coastguard Worker~~~c 24*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 25*6236dae4SAndroid Build Coastguard Worker 26*6236dae4SAndroid Build Coastguard WorkerCURLMcode curl_multi_timeout(CURLM *multi_handle, long *timeout); 27*6236dae4SAndroid Build Coastguard Worker~~~ 28*6236dae4SAndroid Build Coastguard Worker 29*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 30*6236dae4SAndroid Build Coastguard Worker 31*6236dae4SAndroid Build Coastguard WorkerAn application using the libcurl multi interface should call 32*6236dae4SAndroid Build Coastguard Workercurl_multi_timeout(3) to figure out how long it should wait for socket 33*6236dae4SAndroid Build Coastguard Workeractions - at most - before proceeding. 34*6236dae4SAndroid Build Coastguard Worker 35*6236dae4SAndroid Build Coastguard WorkerProceeding means either doing the socket-style timeout action: call the 36*6236dae4SAndroid Build Coastguard Workercurl_multi_socket_action(3) function with the **sockfd** argument set 37*6236dae4SAndroid Build Coastguard Workerto CURL_SOCKET_TIMEOUT, or call curl_multi_perform(3) if you are using 38*6236dae4SAndroid Build Coastguard Workerthe simpler and older multi interface approach. 39*6236dae4SAndroid Build Coastguard Worker 40*6236dae4SAndroid Build Coastguard WorkerThe timeout value returned in the long **timeout** points to, is in number 41*6236dae4SAndroid Build Coastguard Workerof milliseconds at this moment. If 0, it means you should proceed immediately 42*6236dae4SAndroid Build Coastguard Workerwithout waiting for anything. If it returns -1, there is no timeout at all set. 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard WorkerAn application that uses the *multi_socket* API should not use this function. 45*6236dae4SAndroid Build Coastguard WorkerIt should instead use the CURLMOPT_TIMERFUNCTION(3) option for proper and 46*6236dae4SAndroid Build Coastguard Workerdesired behavior. 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard WorkerNote: if libcurl returns a -1 timeout here, it just means that libcurl 49*6236dae4SAndroid Build Coastguard Workercurrently has no stored timeout value. You must not wait too long (more than a 50*6236dae4SAndroid Build Coastguard Workerfew seconds perhaps) before you call curl_multi_perform(3) again. 51*6236dae4SAndroid Build Coastguard Worker 52*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 55*6236dae4SAndroid Build Coastguard Worker 56*6236dae4SAndroid Build Coastguard Worker~~~c 57*6236dae4SAndroid Build Coastguard Workerint main(void) 58*6236dae4SAndroid Build Coastguard Worker{ 59*6236dae4SAndroid Build Coastguard Worker struct timeval timeout; 60*6236dae4SAndroid Build Coastguard Worker long timeo; 61*6236dae4SAndroid Build Coastguard Worker fd_set fdread; 62*6236dae4SAndroid Build Coastguard Worker fd_set fdwrite; 63*6236dae4SAndroid Build Coastguard Worker fd_set fdexcep; 64*6236dae4SAndroid Build Coastguard Worker int maxfd; 65*6236dae4SAndroid Build Coastguard Worker CURLM *multi = curl_multi_init(); 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard Worker curl_multi_timeout(multi, &timeo); 68*6236dae4SAndroid Build Coastguard Worker if(timeo < 0) 69*6236dae4SAndroid Build Coastguard Worker /* no set timeout, use a default */ 70*6236dae4SAndroid Build Coastguard Worker timeo = 980; 71*6236dae4SAndroid Build Coastguard Worker 72*6236dae4SAndroid Build Coastguard Worker timeout.tv_sec = timeo / 1000; 73*6236dae4SAndroid Build Coastguard Worker timeout.tv_usec = (timeo % 1000) * 1000; 74*6236dae4SAndroid Build Coastguard Worker 75*6236dae4SAndroid Build Coastguard Worker /* wait for activities no longer than the set timeout */ 76*6236dae4SAndroid Build Coastguard Worker select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); 77*6236dae4SAndroid Build Coastguard Worker} 78*6236dae4SAndroid Build Coastguard Worker~~~ 79*6236dae4SAndroid Build Coastguard Worker 80*6236dae4SAndroid Build Coastguard Worker# TYPICAL USAGE 81*6236dae4SAndroid Build Coastguard Worker 82*6236dae4SAndroid Build Coastguard WorkerCall curl_multi_timeout(3), then wait for action on the sockets. Figure 83*6236dae4SAndroid Build Coastguard Workerout which sockets to wait for by calling curl_multi_fdset(3). 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard WorkerWhen there is activity or timeout, call curl_multi_perform(3) and then 86*6236dae4SAndroid Build Coastguard Workerloop - until all transfers are complete. 87*6236dae4SAndroid Build Coastguard Worker 88*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 89*6236dae4SAndroid Build Coastguard Worker 90*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 91*6236dae4SAndroid Build Coastguard Worker 92*6236dae4SAndroid Build Coastguard WorkerThe standard CURLMcode for multi interface error codes. 93