-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: fix net.Server keepalive and noDelay
PR-URL: #43497 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
3 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const server = net.createServer({ | ||
keepAlive: true, | ||
keepAliveInitialDelay: 1000 | ||
}, common.mustCall((socket) => { | ||
socket.destroy(); | ||
server.close(); | ||
})).listen(0, common.mustCall(() => { | ||
net.connect(server.address().port); | ||
})); | ||
|
||
const onconnection = server._handle.onconnection; | ||
server._handle.onconnection = common.mustCall((err, clientHandle) => { | ||
const setKeepAlive = clientHandle.setKeepAlive; | ||
clientHandle.setKeepAlive = common.mustCall((enable, initialDelayMsecs) => { | ||
assert.strictEqual(enable, server.keepAlive); | ||
assert.strictEqual(initialDelayMsecs, server.keepAliveInitialDelay); | ||
setKeepAlive.call(clientHandle, enable, initialDelayMsecs); | ||
}); | ||
onconnection.call(server._handle, err, clientHandle); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const server = net.createServer({ | ||
noDelay: true | ||
}, common.mustCall((socket) => { | ||
socket.destroy(); | ||
server.close(); | ||
})).listen(0, common.mustCall(() => { | ||
net.connect(server.address().port); | ||
})); | ||
|
||
const onconnection = server._handle.onconnection; | ||
server._handle.onconnection = common.mustCall((err, clientHandle) => { | ||
const setNoDelay = clientHandle.setNoDelay; | ||
clientHandle.setNoDelay = common.mustCall((enable) => { | ||
assert.strictEqual(enable, server.noDelay); | ||
setNoDelay.call(clientHandle, enable); | ||
}); | ||
onconnection.call(server._handle, err, clientHandle); | ||
}); |