CURLOPT_TCP_NODELAY(3)

πŸ¦‹ CURLOPT_TCP_NODELAY β€” the TCP_NODELAY option, bestie edition πŸ¦‹

okay so this is from the Library Functions Manual, and it's literally the whole glow-up guide to the TCP_NODELAY option. no cap, it's shorter than you'd think and honestly iconic for it. πŸ’…


✨ SYNOPSIS ✨

like, here's the whole vibe in code form:

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_NODELAY, long nodelay);

πŸ’– DESCRIPTION πŸ’–

so you pass a long that says whether TCP_NODELAY is gonna be set or cleared β€” 1L = set, 0 = clear. and guess what, the option is set by default already, main character behavior tbh. 🫢

heads up bestie: this has no effect after the connection has been established. like, the door's already closed, you can't change the fit now. 😭

setting this option to 1L disables the Nagle algorithm on connections created using this handle. and what does that algorithm even do? it exists to minimize the number of small packets on the network (and by "small packets" we mean TCP segments less than the Maximum Segment Size for the network, iykyk). 🌸

maximizing the amount of data sent per TCP segment is lowkey good because it amortizes the overhead of the send. every byte pulling its weight, slay. ✨ but β€” and this is the plot twist β€” in some cases small segments may need to be sent without delay. that's less efficient than sending larger amounts of data at a time, and it can contribute to congestion on the network if overdone. so like, use it with taste, not like a menace. πŸ’€


πŸŽ€ DEFAULT πŸŽ€

1


🌈 PROTOCOLS 🌈

this functionality affects tcp only. just tcp. that's the whole list. periodt. πŸ‘‘


πŸ”₯ EXAMPLE πŸ”₯

here's the moment you've been waiting for, copy it exactly fr fr:

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    /* leave Nagle enabled */
    curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 0L);
    curl_easy_perform(curl);
  }
}

not me setting it to 0L to leave Nagle enabled β€” the comment says it all bestie, respect the comment. πŸ™ˆ


🧚 HISTORY 🧚

the default was changed to 1 from 0 in 7.50.2. a real character arc. πŸ’œ


⭐ AVAILABILITY ⭐

added in curl 7.11.2. vintage but still eating. πŸ“


πŸ’… RETURN VALUE πŸ’…

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK β€” we love a zero. ✨ non-zero means an error occurred, and you should go see libcurl-errors(3) for the tea.


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the page! brought to you by libcurl, dated 2026-10-12 β€” the CURLOPT_TCP_NODELAY(3) of our hearts. go forth and nodelay responsibly, bestie πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from