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: CURLOPT_TIMEOUT 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_CONNECTTIMEOUT (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_LOW_SPEED_LIMIT (3) 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_TCP_KEEPALIVE (3) 11*6236dae4SAndroid Build Coastguard Worker - CURLOPT_TIMEOUT_MS (3) 12*6236dae4SAndroid Build Coastguard WorkerProtocol: 13*6236dae4SAndroid Build Coastguard Worker - All 14*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1 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 WorkerCURLOPT_TIMEOUT - maximum time the transfer is allowed to complete 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 WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_TIMEOUT, 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 WorkerPass a long as parameter containing *timeout* - the maximum time in 32*6236dae4SAndroid Build Coastguard Workerseconds that you allow the entire transfer operation to take. The whole thing, 33*6236dae4SAndroid Build Coastguard Workerfrom start to end. Normally, name lookups can take a considerable time and 34*6236dae4SAndroid Build Coastguard Workerlimiting operations risk aborting perfectly normal operations. 35*6236dae4SAndroid Build Coastguard Worker 36*6236dae4SAndroid Build Coastguard WorkerCURLOPT_TIMEOUT_MS(3) is the same function but set in milliseconds. 37*6236dae4SAndroid Build Coastguard Worker 38*6236dae4SAndroid Build Coastguard WorkerIf both CURLOPT_TIMEOUT(3) and CURLOPT_TIMEOUT_MS(3) are set, the 39*6236dae4SAndroid Build Coastguard Workervalue set last is used. 40*6236dae4SAndroid Build Coastguard Worker 41*6236dae4SAndroid Build Coastguard WorkerSince this option puts a hard limit on how long time a request is allowed to 42*6236dae4SAndroid Build Coastguard Workertake, it has limited use in dynamic use cases with varying transfer 43*6236dae4SAndroid Build Coastguard Workertimes. That is especially apparent when using the multi interface, which may 44*6236dae4SAndroid Build Coastguard Workerqueue the transfer, and that time is included. You are advised to explore 45*6236dae4SAndroid Build Coastguard WorkerCURLOPT_LOW_SPEED_LIMIT(3), CURLOPT_LOW_SPEED_TIME(3) or using 46*6236dae4SAndroid Build Coastguard WorkerCURLOPT_PROGRESSFUNCTION(3) to implement your own timeout logic. 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard WorkerThe connection timeout set with CURLOPT_CONNECTTIMEOUT(3) is included in 49*6236dae4SAndroid Build Coastguard Workerthis general all-covering timeout. 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard WorkerWith CURLOPT_CONNECTTIMEOUT(3) set to 3 and CURLOPT_TIMEOUT(3) set 52*6236dae4SAndroid Build Coastguard Workerto 5, the operation can never last longer than 5 seconds. 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerWith CURLOPT_CONNECTTIMEOUT(3) set to 4 and CURLOPT_TIMEOUT(3) set 55*6236dae4SAndroid Build Coastguard Workerto 2, the operation can never last longer than 2 seconds. 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard WorkerThis option may cause libcurl to use the SIGALRM signal to timeout system 58*6236dae4SAndroid Build Coastguard Workercalls on builds not using asynch DNS. In Unix-like systems, this might cause 59*6236dae4SAndroid Build Coastguard Workersignals to be used unless CURLOPT_NOSIGNAL(3) is set. 60*6236dae4SAndroid Build Coastguard Worker 61*6236dae4SAndroid Build Coastguard Worker# DEFAULT 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker0 (zero) which means it never times out during transfer. 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard Worker~~~c 70*6236dae4SAndroid Build Coastguard Workerint main(void) 71*6236dae4SAndroid Build Coastguard Worker{ 72*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 73*6236dae4SAndroid Build Coastguard Worker if(curl) { 74*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 75*6236dae4SAndroid Build Coastguard Worker 76*6236dae4SAndroid Build Coastguard Worker /* complete within 20 seconds */ 77*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L); 78*6236dae4SAndroid Build Coastguard Worker 79*6236dae4SAndroid Build Coastguard Worker curl_easy_perform(curl); 80*6236dae4SAndroid Build Coastguard Worker } 81*6236dae4SAndroid Build Coastguard Worker} 82*6236dae4SAndroid Build Coastguard Worker~~~ 83*6236dae4SAndroid Build Coastguard Worker 84*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 85*6236dae4SAndroid Build Coastguard Worker 86*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 87*6236dae4SAndroid Build Coastguard Worker 88*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK. Returns CURLE_BAD_FUNCTION_ARGUMENT if set to a negative 89*6236dae4SAndroid Build Coastguard Workervalue or a value that when converted to milliseconds is too large. 90