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