1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_TCP_KEEPALIVE 5Section: 3 6Source: libcurl 7See-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) 13Protocol: 14 - TCP 15Added-in: 7.25.0 16--- 17 18# NAME 19 20CURLOPT_TCP_KEEPALIVE - TCP keep-alive probing 21 22# SYNOPSIS 23 24~~~c 25#include <curl/curl.h> 26 27CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_KEEPALIVE, long probe); 28~~~ 29 30# DESCRIPTION 31 32Pass a long. If set to 1, TCP keepalive probes are used. The delay and 33frequency of these probes can be controlled by the 34CURLOPT_TCP_KEEPIDLE(3), CURLOPT_TCP_KEEPINTVL(3), and CURLOPT_TCP_KEEPCNT(3) 35options, provided the operating system supports them. Set to 0 (default behavior) 36to disable keepalive probes. 37 38# DEFAULT 39 400 41 42# %PROTOCOLS% 43 44# EXAMPLE 45 46~~~c 47int 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 74Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 75