Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: activate setNoDelay by default #40778

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ function initSocketHandle(self) {
self._handle.onread = onStreamRead;
self[async_id_symbol] = getNewAsyncId(self._handle);

if (self._handle.setNoDelay && self[kSetNoDelay] === true)
self._handle.setNoDelay(true);

let userBuf = self[kBuffer];
if (userBuf) {
const bufGen = self[kBufferGen];
Expand Down Expand Up @@ -307,7 +310,7 @@ function Socket(options) {
this[kHandle] = null;
this._parent = null;
this._host = null;
this[kSetNoDelay] = false;
this[kSetNoDelay] = true;
this[kLastWriteQueueSize] = 0;
this[kTimeout] = null;
this[kBuffer] = null;
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-net-socket-setnodelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const genSetNoDelay = (desiredArg) => (enable) => {
// setNoDelay should default to true
let socket = new net.Socket({
handle: {
setNoDelay: common.mustCall(genSetNoDelay(true)),
setNoDelay: common.mustCall(genSetNoDelay(true), 1),
readStart() {}
}
});
Expand All @@ -29,19 +29,19 @@ truthyValues.forEach((testVal) => socket.setNoDelay(testVal));

socket = new net.Socket({
handle: {
setNoDelay: common.mustNotCall(),
setNoDelay: common.mustCall(() => {}, 2),
readStart() {}
}
});
falseyValues.forEach((testVal) => socket.setNoDelay(testVal));

socket = new net.Socket({
handle: {
setNoDelay: common.mustCall(() => {}, 3),
setNoDelay: common.mustCall(() => {}, 5),
readStart() {}
}
});
truthyValues.concat(falseyValues).concat(truthyValues)
falseyValues.concat(truthyValues).concat(falseyValues).concat(truthyValues)
.forEach((testVal) => socket.setNoDelay(testVal));

// If a handler doesn't have a setNoDelay function it shouldn't be called.
Expand All @@ -52,5 +52,5 @@ socket = new net.Socket({
readStart() {}
}
});
const returned = socket.setNoDelay(true);
const returned = socket.setNoDelay(false);
assert.ok(returned instanceof net.Socket);