Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
net: Add noDelay to net.Socket() options
Add the noDelay option to the net.Socket() options such that
.setNoDelay() will be called when a socket is created
  • Loading branch information
rustyconover committed Feb 26, 2020
commit 24697c2bdab4167ca8240b94832b6b39186d1bb5
4 changes: 4 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ added: v0.3.4
* `allowHalfOpen` {boolean} Indicates whether half-opened TCP connections
are allowed. See [`net.createServer()`][] and the [`'end'`][] event
for details. **Default:** `false`.
* `noDelay` {boolean} A boolean with which to call [`socket.setNoDelay()`][]
when a socket connection is established. This only applies when the
underlying connection is a TCP socket.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add default values.

* `readable` {boolean} Allow reads on the socket when an `fd` is passed,
otherwise ignored. **Default:** `false`.
* `writable` {boolean} Allow writes on the socket when an `fd` is passed,
Expand Down Expand Up @@ -1262,6 +1265,7 @@ Returns `true` if input is a version 6 IP address, otherwise returns `false`.
[`socket.pause()`]: #net_socket_pause
[`socket.resume()`]: #net_socket_resume
[`socket.setEncoding()`]: #net_socket_setencoding_encoding
[`socket.setNoDelay()`]: #net_socket_setnodelay_nodelay
[`socket.setTimeout()`]: #net_socket_settimeout_timeout_callback
[`socket.setTimeout(timeout)`]: #net_socket_settimeout_timeout_callback
[half-closed]: https://tools.ietf.org/html/rfc1122
Expand Down
4 changes: 4 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ function Socket(options) {
this.server = null;
this._server = null;

if (options.noDelay !== undefined) {
this.setNoDelay(options.noDelay);
}

// Used after `.destroy()`
this[kBytesRead] = 0;
this[kBytesWritten] = 0;
Expand Down