1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_CONNECT_ONLY
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_HTTPPROXYTUNNEL (3)
9  - CURLOPT_VERBOSE (3)
10  - curl_easy_recv (3)
11  - curl_easy_send (3)
12---
13
14# NAME
15
16CURLOPT_CONNECT_ONLY - stop when connected to target server
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CONNECT_ONLY, long only);
24~~~
25
26# DESCRIPTION
27
28Pass a long. If the parameter equals 1, it tells the library to perform all
29the required proxy authentication and connection setup, but no data transfer,
30and then return.
31
32The option can be used to simply test a connection to a server, but is more
33useful when used with the CURLINFO_ACTIVESOCKET(3) option to
34curl_easy_getinfo(3) as the library can set up the connection and then
35the application can obtain the most recently used socket for special data
36transfers.
37
38Since 7.86.0, this option can be set to '2' and if HTTP or WebSocket are used,
39libcurl performs the request and reads all response headers before handing
40over control to the application.
41
42Transfers marked connect only do not reuse any existing connections and
43connections marked connect only are not allowed to get reused.
44
45If the connect only transfer is done using the multi interface, the particular
46easy handle must remain added to the multi handle for as long as the
47application wants to use it. Once it has been removed with
48curl_multi_remove_handle(3), curl_easy_send(3) and
49curl_easy_recv(3) do not function.
50
51# DEFAULT
52
530
54
55# PROTOCOLS
56
57HTTP, SMTP, POP3 and IMAP. For WS and WSS starting in 7.86.0.
58
59# EXAMPLE
60
61~~~c
62int main(void)
63{
64  CURL *curl = curl_easy_init();
65  if(curl) {
66    CURLcode ret;
67    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
68    curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
69    ret = curl_easy_perform(curl);
70    if(ret == CURLE_OK) {
71      /* only connected! */
72    }
73  }
74}
75~~~
76
77# AVAILABILITY
78
79Added in 7.15.2
80
81# RETURN VALUE
82
83Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
84