CURLOPT_TCP_KEEPCNT(3)
π CURLOPT_TCP_KEEPCNT(3) π
ok so this is a page straight out of the libcurl Library Functions Manual, and it's about CURLOPT_TCP_KEEPCNT β the maximum number of TCP keep-alive probes. yes bestie, we're getting into how many times your socket gets to poke the server before it gives up and ghosts. π«Ά
β¨ NAME β¨
CURLOPT_TCP_KEEPCNT β maximum number of TCP keep-alive probes, like, ever π₯
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_KEEPCNT, long cnt);
π¦ DESCRIPTION π¦
so you pass a long, okay? that's the whole vibe. it sets the number of probes to send before dropping the connection. literally just "how many times do we tap the server on the shoulder before we're like, ok bye". π
super important, no cap: not all operating systems support this option. so if it's not doing anything on your box, that's the OS being a hater, not you. π
this whole thing was added in 8.9.0, so if you're on something older it's giving nonexistent.
the maximum value this option accepts is INT_MAX or whatever your system allows. any larger value is capped to this amount β so like, don't try to be cute with a giant number, it's not gonna happen. π
π DEFAULT π
9
nine. iconic. periodt. π
π PROTOCOLS π
this functionality affects tcp only β tcp girlies only, everyone else can see themselves out. π
β EXAMPLE β
ok here's the whole thing, copy it verbatim, don't touch my code:
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);
/* set 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);
}
}
π AVAILABILITY π
added in curl 8.9.0 β baby of the keep-alive family, lowkey the newest member. πΌ
π§ RETURN VALUE π§
curl_easy_setopt(3) returns a CURLcode indicating success or error. that's the whole tea.
CURLE_OK(which is0) means everything was OK β slay. β- non-zero means an error occurred β not slay. π
if you got the non-zero one, go see libcurl-errors(3) and it'll tell you what went wrong, iykyk.
π SEE ALSO π
the whole keep-alive friend group, go say hi to all of them π«Ά
ok that's the page!! this beauty is brought to you by libcurl, dated 2026-10-12, and honestly? she ate. now go forth and keep those connections alive, bestie π¦β¨π
π¦ 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