CURLOPT_TCP_KEEPALIVE(3)
π CURLOPT_TCP_KEEPALIVE β TCP keep-alive probing π
okay bestie, this is a page from the libcurl manual, specifically CURLOPT_TCP_KEEPALIVE(3). yes, the all-caps name is a lot, but she's iconic, we move.
β¨ NAME β¨
CURLOPT_TCP_KEEPALIVE β literally just TCP keep-alive probing. that's it. that's the whole vibe π«Ά
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_KEEPALIVE, long probe);
π DESCRIPTION π
so you pass a long. that's the move. π
- if you set it to 1, TCP keepalive probes are used. like, your connection is out there poking the other side going "hey bestie, u still there?? π"
- the delay and frequency of those probes can be controlled by the
CURLOPT_TCP_KEEPIDLE(3),CURLOPT_TCP_KEEPINTVL(3), andCURLOPT_TCP_KEEPCNT(3)options β provided the operating system supports them. that caveat is doing heavy lifting ngl, some OSes just don't wanna π - set it to 0 (this is the default behavior) to disable keepalive probes. dead it. no probes. β¨
π¦ DEFAULT π¦
0
like, off. no cap. she's chill by default.
π PROTOCOLS π
This functionality affects tcp only. just tcp. nobody else invited to this party π
β EXAMPLE β
this is the whole thing, verbatim, no edits, she's beautiful:
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* enable TCP keep-alive for this transfer */
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
/* keep-alive idle time to 120 seconds */
curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
/* interval time between keep-alive probes: 60 seconds */
curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
/* maximum number of keep-alive probes: 3 */
curl_easy_setopt(curl, CURLOPT_TCP_KEEPCNT, 3L);
curl_easy_perform(curl);
}
}
look at her go. 1L turns it on, 120L idle seconds, 60L between probes, 3L max probes. ate. π₯
π AVAILABILITY π
Added in curl 7.25.0. vintage-ish. still slays.
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error. that's the messenger, she tells you how it went.
CURLE_OK(0) means everything was OK. we love a zero. π«Ά- non-zero means an error occurred β see
libcurl-errors(3)for the full breakdown of what went wrong.
lowkey important: don't ignore a non-zero return, bestie, that's your program telling you something's up π
π§ SEE ALSO π§
CURLOPT_LOW_SPEED_LIMIT(3)CURLOPT_MAX_RECV_SPEED_LARGE(3)CURLOPT_TCP_KEEPCNT(3)CURLOPT_TCP_KEEPIDLE(3)CURLOPT_TCP_KEEPINTVL(3)
go read those too, they're the friend group, they come as a set π
and that's the page!! brought to you by libcurl, dated 2026-10-12, and originally filed under CURLOPT_TCP_KEEPALIVE(3). mwah π go keep those TCP connections alive, queen πβ¨
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms