11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst net = require('net');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cilet serverConnection;
71cb0ef41Sopenharmony_cilet clientConnection;
81cb0ef41Sopenharmony_ciconst echoServer = net.createServer(function(connection) {
91cb0ef41Sopenharmony_ci  serverConnection = connection;
101cb0ef41Sopenharmony_ci  setTimeout(function() {
111cb0ef41Sopenharmony_ci    // Make sure both connections are still open
121cb0ef41Sopenharmony_ci    assert.strictEqual(serverConnection.readyState, 'open');
131cb0ef41Sopenharmony_ci    assert.strictEqual(clientConnection.readyState, 'open');
141cb0ef41Sopenharmony_ci    serverConnection.end();
151cb0ef41Sopenharmony_ci    clientConnection.end();
161cb0ef41Sopenharmony_ci    echoServer.close();
171cb0ef41Sopenharmony_ci  }, 600);
181cb0ef41Sopenharmony_ci  connection.setTimeout(0);
191cb0ef41Sopenharmony_ci  assert.strictEqual(typeof connection.setKeepAlive, 'function');
201cb0ef41Sopenharmony_ci  connection.on('end', function() {
211cb0ef41Sopenharmony_ci    connection.end();
221cb0ef41Sopenharmony_ci  });
231cb0ef41Sopenharmony_ci});
241cb0ef41Sopenharmony_ciechoServer.listen(0);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciechoServer.on('listening', function() {
271cb0ef41Sopenharmony_ci  clientConnection = new net.Socket();
281cb0ef41Sopenharmony_ci  // Send a keepalive packet after 1000 ms
291cb0ef41Sopenharmony_ci  // and make sure it persists
301cb0ef41Sopenharmony_ci  const s = clientConnection.setKeepAlive(true, 400);
311cb0ef41Sopenharmony_ci  assert.ok(s instanceof net.Socket);
321cb0ef41Sopenharmony_ci  clientConnection.connect(this.address().port);
331cb0ef41Sopenharmony_ci  clientConnection.setTimeout(0);
341cb0ef41Sopenharmony_ci});
35