CURLOPT_CONNECTTIMEOUT.md (2309B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_CONNECTTIMEOUT 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_LOW_SPEED_LIMIT (3) 9 - CURLOPT_MAX_RECV_SPEED_LARGE (3) 10 - CURLOPT_TIMEOUT (3) 11 Protocol: 12 - All 13 Added-in: 7.7 14 --- 15 16 # NAME 17 18 CURLOPT_CONNECTTIMEOUT - timeout for the connect phase 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CONNECTTIMEOUT, long timeout); 26 ~~~ 27 28 # DESCRIPTION 29 30 Pass a long. It sets the maximum time in seconds that you allow the connection 31 phase to take. This timeout only limits the connection phase, it has no impact 32 once libcurl has connected. The connection phase includes the name resolve 33 (DNS) and all protocol handshakes and negotiations until there is an 34 established connection with the remote side. 35 36 Set this option to zero to switch to the default built-in connection timeout - 37 300 seconds. See also the CURLOPT_TIMEOUT(3) option. 38 39 CURLOPT_CONNECTTIMEOUT_MS(3) is the same function but set in milliseconds. 40 41 If both CURLOPT_CONNECTTIMEOUT(3) and CURLOPT_CONNECTTIMEOUT_MS(3) 42 are set, the value set last is used. 43 44 The connection timeout is included in the general all-covering 45 CURLOPT_TIMEOUT(3): 46 47 With CURLOPT_CONNECTTIMEOUT(3) set to 3 and CURLOPT_TIMEOUT(3) set 48 to 5, the operation can never last longer than 5 seconds, and the connection 49 phase cannot last longer than 3 seconds. 50 51 With CURLOPT_CONNECTTIMEOUT(3) set to 4 and CURLOPT_TIMEOUT(3) set 52 to 2, the operation can never last longer than 2 seconds. Including the 53 connection phase. 54 55 This option may cause libcurl to use the SIGALRM signal to timeout system 56 calls on builds not using asynch DNS. In Unix-like systems, this might cause 57 signals to be used unless CURLOPT_NOSIGNAL(3) is set. 58 59 # DEFAULT 60 61 300 62 63 # %PROTOCOLS% 64 65 # EXAMPLE 66 67 ~~~c 68 int main(void) 69 { 70 CURL *curl = curl_easy_init(); 71 if(curl) { 72 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 73 74 /* complete connection within 10 seconds */ 75 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L); 76 77 curl_easy_perform(curl); 78 } 79 } 80 ~~~ 81 82 # %AVAILABILITY% 83 84 # RETURN VALUE 85 86 curl_easy_setopt(3) returns a CURLcode indicating success or error. 87 88 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 89 libcurl-errors(3).