mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
762 B
31 lines
762 B
'use strict';
|
|
// This example sets a timeout then immediately attempts to disable the timeout
|
|
// https://github.com/joyent/node/pull/2245
|
|
|
|
const common = require('../common');
|
|
const net = require('net');
|
|
const assert = require('assert');
|
|
|
|
const T = 100;
|
|
|
|
const server = net.createServer(common.mustCall((c) => {
|
|
c.write('hello');
|
|
}));
|
|
|
|
server.listen(0, function() {
|
|
const socket = net.createConnection(this.address().port, 'localhost');
|
|
|
|
const s = socket.setTimeout(T, () => {
|
|
common.fail('Socket timeout event is not expected to fire');
|
|
});
|
|
assert.ok(s instanceof net.Socket);
|
|
|
|
socket.on('data', common.mustCall(() => {
|
|
setTimeout(function() {
|
|
socket.destroy();
|
|
server.close();
|
|
}, T * 2);
|
|
}));
|
|
|
|
socket.setTimeout(0);
|
|
});
|
|
|