1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const net = require('net'); 5 6const server = net.createServer({ 7 keepAlive: true, 8 keepAliveInitialDelay: 1000 9}, common.mustCall((socket) => { 10 const setKeepAlive = socket._handle.setKeepAlive; 11 socket._handle.setKeepAlive = common.mustCall((enable, initialDelay) => { 12 assert.strictEqual(enable, true); 13 assert.match(String(initialDelay), /^2|3$/); 14 return setKeepAlive.call(socket._handle, enable, initialDelay); 15 }, 2); 16 socket.setKeepAlive(true, 1000); 17 socket.setKeepAlive(true, 2000); 18 socket.setKeepAlive(true, 3000); 19 socket.destroy(); 20 server.close(); 21})).listen(0, common.mustCall(() => { 22 net.connect(server.address().port); 23})); 24 25const onconnection = server._handle.onconnection; 26server._handle.onconnection = common.mustCall((err, clientHandle) => { 27 const setKeepAlive = clientHandle.setKeepAlive; 28 clientHandle.setKeepAlive = common.mustCall((enable, initialDelayMsecs) => { 29 assert.strictEqual(enable, server.keepAlive); 30 assert.strictEqual(initialDelayMsecs, server.keepAliveInitialDelay); 31 setKeepAlive.call(clientHandle, enable, initialDelayMsecs); 32 clientHandle.setKeepAlive = setKeepAlive; 33 }); 34 onconnection.call(server._handle, err, clientHandle); 35}); 36