Skip to content

Commit

Permalink
doc: clarify socket.setNoDelay() explanation
Browse files Browse the repository at this point in the history
Change the description of socket.setNoDelay() to make it clear
that sockets have Nagle's algorithm enabled by default.

Better document the tradeoff of having the algorithm enabled.

Explain the behavior of the function based on the passed arguments.

PR-URL: #31541
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
rustyconover authored and codebytere committed Feb 17, 2020
1 parent faec87b commit 3ba0a22
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,16 @@ added: v0.1.90
* `noDelay` {boolean} **Default:** `true`
* Returns: {net.Socket} The socket itself.

Disables the Nagle algorithm. By default TCP connections use the Nagle
algorithm, they buffer data before sending it off. Setting `true` for
`noDelay` will immediately fire off data each time `socket.write()` is called.
Enable/disable the use of Nagle's algorithm.

When a TCP connection is created, it will have Nagle's algorithm enabled.

Nagle's algorithm delays data before it is sent via the network. It attempts
to optimize throughput at the expense of latency.

Passing `true` for `noDelay` or not passing an argument will disable Nagle's
algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
algorithm.

### `socket.setTimeout(timeout[, callback])`
<!-- YAML
Expand Down

0 comments on commit 3ba0a22

Please sign in to comment.