2015-02-18 12:02:01 -06:00
|
|
|
'use strict';
|
2016-05-29 03:06:56 -04:00
|
|
|
require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2015-02-18 12:02:01 -06:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let serverConnection;
|
|
|
|
let clientConnection;
|
|
|
|
const echoServer = net.createServer(function(connection) {
|
2015-02-18 12:02:01 -06:00
|
|
|
serverConnection = connection;
|
2015-11-03 11:10:16 -05:00
|
|
|
setTimeout(function() {
|
2019-01-21 01:22:27 +01:00
|
|
|
// Make sure both connections are still open
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(serverConnection.readyState, 'open');
|
|
|
|
assert.strictEqual(clientConnection.readyState, 'open');
|
2015-11-03 11:10:16 -05:00
|
|
|
serverConnection.end();
|
|
|
|
clientConnection.end();
|
|
|
|
echoServer.close();
|
|
|
|
}, 600);
|
2015-02-18 12:02:01 -06:00
|
|
|
connection.setTimeout(0);
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(typeof connection.setKeepAlive, 'function');
|
2015-02-18 12:02:01 -06:00
|
|
|
connection.on('end', function() {
|
|
|
|
connection.end();
|
|
|
|
});
|
|
|
|
});
|
2016-05-29 03:06:56 -04:00
|
|
|
echoServer.listen(0);
|
2015-02-18 12:02:01 -06:00
|
|
|
|
|
|
|
echoServer.on('listening', function() {
|
2015-11-03 11:10:16 -05:00
|
|
|
clientConnection = new net.Socket();
|
2019-03-07 01:03:53 +01:00
|
|
|
// Send a keepalive packet after 1000 ms
|
2015-02-18 12:02:01 -06:00
|
|
|
// and make sure it persists
|
2017-01-08 13:19:00 +00:00
|
|
|
const s = clientConnection.setKeepAlive(true, 400);
|
2015-05-23 07:48:13 +02:00
|
|
|
assert.ok(s instanceof net.Socket);
|
2016-05-29 03:06:56 -04:00
|
|
|
clientConnection.connect(this.address().port);
|
2015-02-18 12:02:01 -06:00
|
|
|
clientConnection.setTimeout(0);
|
|
|
|
});
|