CURLOPT_TCP_KEEPALIVE.md (1702B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_TCP_KEEPALIVE 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_LOW_SPEED_LIMIT (3) 9 - CURLOPT_MAX_RECV_SPEED_LARGE (3) 10 - CURLOPT_TCP_KEEPIDLE (3) 11 - CURLOPT_TCP_KEEPINTVL (3) 12 - CURLOPT_TCP_KEEPCNT (3) 13 Protocol: 14 - TCP 15 Added-in: 7.25.0 16 --- 17 18 # NAME 19 20 CURLOPT_TCP_KEEPALIVE - TCP keep-alive probing 21 22 # SYNOPSIS 23 24 ~~~c 25 #include <curl/curl.h> 26 27 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_KEEPALIVE, long probe); 28 ~~~ 29 30 # DESCRIPTION 31 32 Pass a long. If set to 1, TCP keepalive probes are used. The delay and 33 frequency of these probes can be controlled by the 34 CURLOPT_TCP_KEEPIDLE(3), CURLOPT_TCP_KEEPINTVL(3), and CURLOPT_TCP_KEEPCNT(3) 35 options, provided the operating system supports them. Set to 0 (default behavior) 36 to disable keepalive probes. 37 38 # DEFAULT 39 40 0 41 42 # %PROTOCOLS% 43 44 # EXAMPLE 45 46 ~~~c 47 int main(void) 48 { 49 CURL *curl = curl_easy_init(); 50 if(curl) { 51 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 52 53 /* enable TCP keep-alive for this transfer */ 54 curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); 55 56 /* keep-alive idle time to 120 seconds */ 57 curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L); 58 59 /* interval time between keep-alive probes: 60 seconds */ 60 curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L); 61 62 /* maximum number of keep-alive probes: 3 */ 63 curl_easy_setopt(curl, CURLOPT_TCP_KEEPCNT, 3L); 64 65 curl_easy_perform(curl); 66 } 67 } 68 ~~~ 69 70 # %AVAILABILITY% 71 72 # RETURN VALUE 73 74 curl_easy_setopt(3) returns a CURLcode indicating success or error. 75 76 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 77 libcurl-errors(3).