curl_easy_upkeep(3)
π curl_easy_upkeep(3) π
okay so bestie, welcome to the curl_easy_upkeep(3) page β it lives in the Library Functions Manual and it's literally the "keep your connections from ghosting you" function. let's get into it π«Ά
β¨ NAME β¨
curl_easy_upkeep β keep existing connections alive π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_upkeep(CURL *handle);
πΈ DESCRIPTION πΈ
so like, some protocols have these things called "connection upkeep" mechanisms, right? and what they do is send a lil bit of traffic on the connections you already have open, just to keep them alive. why? because it can stop those connections from getting closed by overzealous firewalls, for example π firewalls stay doing the most.
for HTTP/2 there's an upkeep mechanism: when the connection upkeep interval gets exceeded and you call curl_easy_upkeep(3), an HTTP/2 PING frame gets sent on the connection. iconic behavior, no cap π₯
for MQTT, the upkeep interval defines when to send ping requests so the server doesn't just disconnect you. rude of it, but okay π
the thing is, this function has to be explicitly called for any of that upkeep work to actually happen. it's not doing it behind your back, it's not that kind of function. the connection upkeep interval itself is set with CURLOPT_UPKEEP_INTERVAL_MS(3) β
and here's a fun one: if you call this function on an easy handle that uses a shared connection cache, then upkeep gets performed on the connections in that cache β even if those connections were never used by that easy handle. main character energy honestly. (Added in 8.10.0) π
π¦ PROTOCOLS π¦
this functionality affects all supported protocols β every single one, periodt π
π EXAMPLE π
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
/* Make a connection to an HTTP/2 server. */
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Set the interval to 30000ms / 30s */
curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L);
curl_easy_perform(curl);
/* Perform more work here. */
/* While the connection is being held open, curl_easy_upkeep() can be
called. If curl_easy_upkeep() is called and the time since the last
upkeep exceeds the interval, then an HTTP/2 PING is sent. */
curl_easy_upkeep(curl);
/* Perform more work here. */
/* always cleanup */
curl_easy_cleanup(curl);
}
}
π AVAILABILITY π
added in curl 7.62.0 β so she's been around a minute, iykyk β¨
π RETURN VALUE π
this function returns a CURLcode that tells you whether it slayed or flopped β success or error, basically.
CURLE_OK(0) means everything was OK π- non-zero means an error occurred β go see
libcurl-errors(3)for the deets
and listen: if CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3), there can be an error message stored in that error buffer when non-zero is returned. so check it, bestie π«Ά
π SEE ALSO π
that's the whole page, you ate that π and just so you know where this masterpiece came from: it's libcurl, dated 2026-10-12, and it's the curl_easy_upkeep(3) page. mwah ππ§
π¦ 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