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