GNURLOPT_TCP_KEEPALIVE(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

hey bestie πŸ’– welcome to the curl_easy_setopt options manual β€” today's main character is GNURLOPT_TCP_KEEPALIVE(3). lowkey a tiny page, highkey useful if you want your TCP keepalive behavior to be your thing. no cap, let's go ✨

πŸŽ€ NAME πŸŽ€

  • CURLOPT_TCP_KEEPALIVE β€” enable TCP keep-alive probing πŸ’…

✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_KEEPALIVE, long
probe);

okay so you call curl_easy_setopt with your CURL *handle, pass the CURLOPT_TCP_KEEPALIVE option, and hand over a long probe value. that's the whole signature, periodt 🫢

πŸ’– DESCRIPTION πŸ’–

Pass a long, bestie. If it's set to 1, TCP keepalive probes will be sent πŸ”₯. The delay and frequency of these probes can be controlled by the CURLOPT_TCP_KEEPIDLE(3) and CURLOPT_TCP_KEEPINTVL(3) options, provided the operating system supports them β€” iykyk. Set it to 0 (that's the default behavior) to disable keepalive probes. literally that simple, no notes πŸ’œ

πŸ¦‹ DEFAULT πŸ¦‹

0 β€” out of the box, keepalive probes are disabled. the default is giving "off" 😌

🌈 PROTOCOLS 🌈

All β€” every protocol, all of them, slay πŸ’…

πŸ“ EXAMPLE πŸ“

here's the exact little code moment from the page:

CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://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);

  curl_easy_perform(curl);
}

that's it β€” iconic behavior 🧚

⭐ AVAILABILITY ⭐

Added in 7.25.0 β€” she's been here, and she ate πŸ‘‘

πŸ‘‘ RETURN VALUE πŸ‘‘

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. so if you get CURLE_UNKNOWN_OPTION, it's literally not supported β€” read the room 😭

🧚 SEE ALSO 🧚

go peek at CURLOPT_TCP_KEEPIDLE(3), CURLOPT_TCP_KEEPINTVL(3), πŸ’œ


okay bye bestie! this page is from libcurl 7.37.0, dated 19 Jun 2014, and it's literally GNURLOPT_TCP_KEEPALIVE(3) β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from