GNURLOPT_LOW_SPEED_LIMIT(3)

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

πŸ’… GNURLOPT_LOW_SPEED_LIMIT πŸ’…

okay bestie, so this is one of those curl_easy_setopt options β€” yes, the whole "options" family, the manual-page nepo baby of the curl world β€” and it is so useful it's not even funny. this page is GNURLOPT_LOW_SPEED_LIMIT(3) and it's about telling your transfer "girl, if you're gonna be slow, I need you to at least be quiet about it" (and then aborting). let's get into it πŸŽ€


✨ NAME ✨

CURLOPT_LOW_SPEED_LIMIT β€” set low speed limit in bytes per second. literally that. no cap. 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_LOW_SPEED_LIMIT, long speedlimit);

that's it. that's the whole vibe check. πŸ’œ


🌈 DESCRIPTION 🌈

so you pass a long as the parameter β€” like, an actual long, not an int, okay, we're being precise here. and that long is the average transfer speed in bytes per second that the transfer should be below during CURLOPT_LOW_SPEED_TIME(3) seconds for libcurl to consider it too slow and abort. 😭

yes, this one works as a team with CURLOPT_LOW_SPEED_TIME(3) β€” the limit is the speed threshold, the time one is how long you're willing to sit there watching it crawl. together they're the "you have N seconds to go faster than X bytes/sec or we're done here" duo. iconic honestly. ✨

the way it works is: libcurl measures the average speed, and if it stays under your number for that many seconds, it calls it and aborts. so if you don't set the time option too, this one is just out here with zero backup. πŸ’€


πŸŽ€ DEFAULT πŸŽ€

0 β€” which means disabled. as in, off. not a thing. this check does not happen. so if you want this behavior you gotta actually ask for it, bestie. πŸ‘‘


🧚 PROTOCOLS 🧚

All of them. every single protocol. she's universal. 🫢


πŸ”₯ EXAMPLE πŸ”₯

here's the whole thing, laid out for you β€” and yes, that comment about 30 bytes/sec over 60 seconds is doing a lot of the explaining here, keep them together:

curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, url);
  /* abort if slower than 30 bytes/sec during 60 seconds */
  curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60L);
  curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 30L);
  res = curl_easy_perform(curl);
  if(CURLE_OPERATION_TIMEDOUT == res) {
    printf("Timeout!\n");
  }
  /* always cleanup */
  curl_easy_cleanup(curl);
}

like β€” set the URL, set the patience window (60L), set the speed floor (30L), perform, check for CURLE_OPERATION_TIMEDOUT, scream "Timeout!", and always cleanup. the cleanup is not optional, don't be that girl. 🚨

ngl the CURLE_OPERATION_TIMEDOUT check is the main character here β€” that's how you find out your low-speed limit actually fired. πŸ’–

⭐ AVAILABILITY ⭐

Always. she was born ready. πŸ¦‹


πŸ’œ RETURN VALUE πŸ’œ

Returns CURLE_OK. that's it. that's the whole return value. slay. βœ…


🌸 SEE ALSO 🌸


kisses bestie, this page is from libcurl 7.37.0, dated 17 Jun 2014 β€” old money, still relevant, still paying rent, mwah πŸ’…πŸ’–πŸŽ€

πŸ“¦ where this page comes from