mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 22:07:57 +00:00

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>
31 lines
895 B
JavaScript
31 lines
895 B
JavaScript
// Flags: --expose-internals
|
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const { kTimeout } = require('internal/timers');
|
|
|
|
const server = http.createServer((req, res) => {
|
|
// This space is intentionally left blank.
|
|
});
|
|
|
|
server.listen(0, common.localhostIPv4, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
const req = http.get(`http://${common.localhostIPv4}:${port}`);
|
|
|
|
req.setTimeout(1);
|
|
req.on('socket', common.mustCall((socket) => {
|
|
assert.strictEqual(socket[kTimeout], null);
|
|
socket.on('connect', common.mustCall(() => {
|
|
assert.strictEqual(socket[kTimeout]._idleTimeout, 1);
|
|
}));
|
|
}));
|
|
req.on('timeout', common.mustCall(() => req.abort()));
|
|
req.on('error', common.mustCall((err) => {
|
|
assert.strictEqual('socket hang up', err.message);
|
|
server.close();
|
|
}));
|
|
}));
|