11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst net = require('net');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst server = net.createServer({
71cb0ef41Sopenharmony_ci  keepAlive: true,
81cb0ef41Sopenharmony_ci  keepAliveInitialDelay: 1000
91cb0ef41Sopenharmony_ci}, common.mustCall((socket) => {
101cb0ef41Sopenharmony_ci  const setKeepAlive = socket._handle.setKeepAlive;
111cb0ef41Sopenharmony_ci  socket._handle.setKeepAlive = common.mustCall((enable, initialDelay) => {
121cb0ef41Sopenharmony_ci    assert.strictEqual(enable, true);
131cb0ef41Sopenharmony_ci    assert.match(String(initialDelay), /^2|3$/);
141cb0ef41Sopenharmony_ci    return setKeepAlive.call(socket._handle, enable, initialDelay);
151cb0ef41Sopenharmony_ci  }, 2);
161cb0ef41Sopenharmony_ci  socket.setKeepAlive(true, 1000);
171cb0ef41Sopenharmony_ci  socket.setKeepAlive(true, 2000);
181cb0ef41Sopenharmony_ci  socket.setKeepAlive(true, 3000);
191cb0ef41Sopenharmony_ci  socket.destroy();
201cb0ef41Sopenharmony_ci  server.close();
211cb0ef41Sopenharmony_ci})).listen(0, common.mustCall(() => {
221cb0ef41Sopenharmony_ci  net.connect(server.address().port);
231cb0ef41Sopenharmony_ci}));
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciconst onconnection = server._handle.onconnection;
261cb0ef41Sopenharmony_ciserver._handle.onconnection = common.mustCall((err, clientHandle) => {
271cb0ef41Sopenharmony_ci  const setKeepAlive = clientHandle.setKeepAlive;
281cb0ef41Sopenharmony_ci  clientHandle.setKeepAlive = common.mustCall((enable, initialDelayMsecs) => {
291cb0ef41Sopenharmony_ci    assert.strictEqual(enable, server.keepAlive);
301cb0ef41Sopenharmony_ci    assert.strictEqual(initialDelayMsecs, server.keepAliveInitialDelay);
311cb0ef41Sopenharmony_ci    setKeepAlive.call(clientHandle, enable, initialDelayMsecs);
321cb0ef41Sopenharmony_ci    clientHandle.setKeepAlive = setKeepAlive;
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci  onconnection.call(server._handle, err, clientHandle);
351cb0ef41Sopenharmony_ci});
36