2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2011-12-02 03:27:35 -05:00
|
|
|
// This example sets a timeout then immediately attempts to disable the timeout
|
|
|
|
// https://github.com/joyent/node/pull/2245
|
|
|
|
|
2016-01-21 10:41:30 -08:00
|
|
|
const common = require('../common');
|
|
|
|
const net = require('net');
|
|
|
|
const assert = require('assert');
|
2011-12-02 03:27:35 -05:00
|
|
|
|
2016-01-21 10:41:30 -08:00
|
|
|
const T = 100;
|
2011-12-02 03:27:35 -05:00
|
|
|
|
2016-01-21 10:41:30 -08:00
|
|
|
const server = net.createServer(function(c) {
|
2011-12-02 03:27:35 -05:00
|
|
|
c.write('hello');
|
|
|
|
});
|
|
|
|
server.listen(common.PORT);
|
|
|
|
|
2016-01-21 10:41:30 -08:00
|
|
|
const socket = net.createConnection(common.PORT, 'localhost');
|
2012-07-16 21:41:26 +04:00
|
|
|
|
2016-01-21 10:41:30 -08:00
|
|
|
const s = socket.setTimeout(T, function() {
|
|
|
|
common.fail('Socket timeout event is not expected to fire');
|
|
|
|
});
|
|
|
|
assert.ok(s instanceof net.Socket);
|
2012-07-16 21:41:26 +04:00
|
|
|
|
2016-01-21 10:41:30 -08:00
|
|
|
socket.setTimeout(0);
|
2012-07-16 21:41:26 +04:00
|
|
|
|
2016-01-21 10:41:30 -08:00
|
|
|
setTimeout(function() {
|
|
|
|
socket.destroy();
|
|
|
|
server.close();
|
|
|
|
}, T * 2);
|
2012-07-16 21:41:26 +04:00
|
|
|
|