CURLOPT_TCP_NODELAY.md (1817B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_TCP_NODELAY 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_BUFFERSIZE (3) 9 - CURLOPT_SOCKOPTFUNCTION (3) 10 - CURLOPT_TCP_KEEPALIVE (3) 11 Protocol: 12 - TCP 13 Added-in: 7.11.2 14 --- 15 16 # NAME 17 18 CURLOPT_TCP_NODELAY - the TCP_NODELAY option 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TCP_NODELAY, long nodelay); 26 ~~~ 27 28 # DESCRIPTION 29 30 Pass a long specifying whether the *TCP_NODELAY* option is to be set or 31 cleared (1L = set, 0 = clear). The option is set by default. This has no 32 effect after the connection has been established. 33 34 Setting this option to 1L disables the Nagle algorithm on connections created 35 using this handle. The purpose of this algorithm is to minimize the number of 36 small packets on the network (where "small packets" means TCP segments less 37 than the Maximum Segment Size for the network). 38 39 Maximizing the amount of data sent per TCP segment is good because it 40 amortizes the overhead of the send. However, in some cases small segments may 41 need to be sent without delay. This is less efficient than sending larger 42 amounts of data at a time, and can contribute to congestion on the network if 43 overdone. 44 45 # DEFAULT 46 47 1 48 49 # %PROTOCOLS% 50 51 # EXAMPLE 52 53 ~~~c 54 int main(void) 55 { 56 CURL *curl = curl_easy_init(); 57 if(curl) { 58 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 59 /* leave Nagle enabled */ 60 curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 0L); 61 curl_easy_perform(curl); 62 } 63 } 64 ~~~ 65 66 # HISTORY 67 68 The default was changed to 1 from 0 in 7.50.2. 69 70 # %AVAILABILITY% 71 72 # RETURN VALUE 73 74 curl_easy_setopt(3) returns a CURLcode indicating success or error. 75 76 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 77 libcurl-errors(3).