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-nodelay.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

27 lines
820 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer({
noDelay: true
}, common.mustCall((socket) => {
socket._handle.setNoDelay = common.mustNotCall();
socket.setNoDelay(true);
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);
clientHandle.setNoDelay = setNoDelay;
});
onconnection.call(server._handle, err, clientHandle);
});