xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_CONNECTTIMEOUT.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
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_CONNECTTIMEOUT
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_LOW_SPEED_LIMIT (3)
9*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_MAX_RECV_SPEED_LARGE (3)
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_TIMEOUT (3)
11*6236dae4SAndroid Build Coastguard WorkerProtocol:
12*6236dae4SAndroid Build Coastguard Worker  - All
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.7
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_CONNECTTIMEOUT - timeout for the connect phase
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_CONNECTTIMEOUT, long timeout);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerPass a long. It sets the maximum time in seconds that you allow the connection
31*6236dae4SAndroid Build Coastguard Workerphase to take. This timeout only limits the connection phase, it has no impact
32*6236dae4SAndroid Build Coastguard Workeronce libcurl has connected. The connection phase includes the name resolve
33*6236dae4SAndroid Build Coastguard Worker(DNS) and all protocol handshakes and negotiations until there is an
34*6236dae4SAndroid Build Coastguard Workerestablished connection with the remote side.
35*6236dae4SAndroid Build Coastguard Worker
36*6236dae4SAndroid Build Coastguard WorkerSet this option to zero to switch to the default built-in connection timeout -
37*6236dae4SAndroid Build Coastguard Worker300 seconds. See also the CURLOPT_TIMEOUT(3) option.
38*6236dae4SAndroid Build Coastguard Worker
39*6236dae4SAndroid Build Coastguard WorkerCURLOPT_CONNECTTIMEOUT_MS(3) is the same function but set in milliseconds.
40*6236dae4SAndroid Build Coastguard Worker
41*6236dae4SAndroid Build Coastguard WorkerIf both CURLOPT_CONNECTTIMEOUT(3) and CURLOPT_CONNECTTIMEOUT_MS(3)
42*6236dae4SAndroid Build Coastguard Workerare set, the value set last is used.
43*6236dae4SAndroid Build Coastguard Worker
44*6236dae4SAndroid Build Coastguard WorkerThe connection timeout is included in the general all-covering
45*6236dae4SAndroid Build Coastguard WorkerCURLOPT_TIMEOUT(3):
46*6236dae4SAndroid Build Coastguard Worker
47*6236dae4SAndroid Build Coastguard WorkerWith CURLOPT_CONNECTTIMEOUT(3) set to 3 and CURLOPT_TIMEOUT(3) set
48*6236dae4SAndroid Build Coastguard Workerto 5, the operation can never last longer than 5 seconds, and the connection
49*6236dae4SAndroid Build Coastguard Workerphase cannot last longer than 3 seconds.
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard WorkerWith CURLOPT_CONNECTTIMEOUT(3) set to 4 and CURLOPT_TIMEOUT(3) set
52*6236dae4SAndroid Build Coastguard Workerto 2, the operation can never last longer than 2 seconds. Including the
53*6236dae4SAndroid Build Coastguard Workerconnection phase.
54*6236dae4SAndroid Build Coastguard Worker
55*6236dae4SAndroid Build Coastguard WorkerThis option may cause libcurl to use the SIGALRM signal to timeout system
56*6236dae4SAndroid Build Coastguard Workercalls on builds not using asynch DNS. In Unix-like systems, this might cause
57*6236dae4SAndroid Build Coastguard Workersignals to be used unless CURLOPT_NOSIGNAL(3) is set.
58*6236dae4SAndroid Build Coastguard Worker
59*6236dae4SAndroid Build Coastguard Worker# DEFAULT
60*6236dae4SAndroid Build Coastguard Worker
61*6236dae4SAndroid Build Coastguard Worker300
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
64*6236dae4SAndroid Build Coastguard Worker
65*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard Worker~~~c
68*6236dae4SAndroid Build Coastguard Workerint main(void)
69*6236dae4SAndroid Build Coastguard Worker{
70*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
71*6236dae4SAndroid Build Coastguard Worker  if(curl) {
72*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
73*6236dae4SAndroid Build Coastguard Worker
74*6236dae4SAndroid Build Coastguard Worker    /* complete connection within 10 seconds */
75*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
76*6236dae4SAndroid Build Coastguard Worker
77*6236dae4SAndroid Build Coastguard Worker    curl_easy_perform(curl);
78*6236dae4SAndroid Build Coastguard Worker  }
79*6236dae4SAndroid Build Coastguard Worker}
80*6236dae4SAndroid Build Coastguard Worker~~~
81*6236dae4SAndroid Build Coastguard Worker
82*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
83*6236dae4SAndroid Build Coastguard Worker
84*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
85*6236dae4SAndroid Build Coastguard Worker
86*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK. Returns CURLE_BAD_FUNCTION_ARGUMENT if set to a negative
87*6236dae4SAndroid Build Coastguard Workervalue or a value that when converted to milliseconds is too large.
88