mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
24dd92e77f
This makes `net.Sockets` use actual Timeout objects in a `[kTimeout]` symbol property, rather than making the socket itself a timer and appending properties to it directly. This should make the code generally easier to understand, and might also prevent some deopts from properties being changes on the socket itself. Also moves the Timeout constructor into an internal module. PR-URL: https://github.com/nodejs/node/pull/17704 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
// Flags: --expose_internals
|
|
|
|
'use strict';
|
|
const common = require('../common');
|
|
const { kTimeout, TIMEOUT_MAX } = require('internal/timers');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const tls = require('tls');
|
|
const net = require('net');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const options = {
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
|
};
|
|
|
|
const server = tls.createServer(options, common.mustCall((c) => {
|
|
setImmediate(() => {
|
|
c.write('hello', () => {
|
|
setImmediate(() => {
|
|
c.destroy();
|
|
server.close();
|
|
});
|
|
});
|
|
});
|
|
}));
|
|
|
|
let socket;
|
|
let lastIdleStart;
|
|
|
|
server.listen(0, () => {
|
|
socket = net.connect(server.address().port, function() {
|
|
const s = socket.setTimeout(TIMEOUT_MAX, function() {
|
|
throw new Error('timeout');
|
|
});
|
|
assert.ok(s instanceof net.Socket);
|
|
|
|
assert.notStrictEqual(socket[kTimeout]._idleTimeout, -1);
|
|
lastIdleStart = socket[kTimeout]._idleStart;
|
|
|
|
const tsocket = tls.connect({
|
|
socket: socket,
|
|
rejectUnauthorized: false
|
|
});
|
|
tsocket.resume();
|
|
});
|
|
});
|
|
|
|
process.on('exit', () => {
|
|
assert.strictEqual(socket[kTimeout]._idleTimeout, -1);
|
|
assert(lastIdleStart < socket[kTimeout]._idleStart);
|
|
});
|