0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-net-server-keepalive.js
theanarkh 8e19dab677
net: fix net keepalive and noDelay
1. support setKeepAlive again
2. set keepalive and nodelay to socket which is created by server

PR-URL: https://github.com/nodejs/node/pull/43561
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-06-29 10:58:35 +01:00

36 lines
1.3 KiB
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) => {
const setKeepAlive = socket._handle.setKeepAlive;
socket._handle.setKeepAlive = common.mustCall((enable, initialDelay) => {
assert.strictEqual(enable, true);
assert.match(String(initialDelay), /^2|3$/);
return setKeepAlive.call(socket._handle, enable, initialDelay);
}, 2);
socket.setKeepAlive(true, 1000);
socket.setKeepAlive(true, 2000);
socket.setKeepAlive(true, 3000);
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);
clientHandle.setKeepAlive = setKeepAlive;
});
onconnection.call(server._handle, err, clientHandle);
});