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