node/test/parallel/test-net-server-keepalive.js
theanarkh dbe5874c7e
net: fix net.Server keepalive and noDelay
PR-URL: https://github.com/nodejs/node/pull/43497
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-06-22 15:10:18 +01:00

26 lines
853 B
JavaScript

'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);
});