2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2011-11-03 20:34:23 +01:00
|
|
|
// socket.write was not resetting the timeout timer. See
|
|
|
|
// https://github.com/joyent/node/issues/2002
|
|
|
|
|
2012-02-20 13:22:12 +01:00
|
|
|
var common = require('../common');
|
2011-11-03 20:34:23 +01:00
|
|
|
var assert = require('assert');
|
|
|
|
var net = require('net');
|
|
|
|
|
|
|
|
var seconds = 5;
|
|
|
|
var gotTimeout = false;
|
|
|
|
var counter = 0;
|
|
|
|
|
|
|
|
var server = net.createServer(function(socket) {
|
|
|
|
socket.setTimeout((seconds / 2) * 1000, function() {
|
|
|
|
gotTimeout = true;
|
2012-01-17 19:43:34 +01:00
|
|
|
console.log('timeout!!');
|
|
|
|
socket.destroy();
|
2011-11-03 20:34:23 +01:00
|
|
|
process.exit(1);
|
2012-01-17 19:43:34 +01:00
|
|
|
});
|
2011-11-03 20:34:23 +01:00
|
|
|
|
2012-01-17 19:43:34 +01:00
|
|
|
var interval = setInterval(function() {
|
2011-11-03 20:34:23 +01:00
|
|
|
counter++;
|
|
|
|
|
|
|
|
if (counter == seconds) {
|
|
|
|
clearInterval(interval);
|
|
|
|
server.close();
|
|
|
|
socket.destroy();
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:43:34 +01:00
|
|
|
if (socket.writable) {
|
|
|
|
socket.write(Date.now() + '\n');
|
|
|
|
}
|
2011-11-03 20:34:23 +01:00
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-08-17 14:02:16 +02:00
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
var s = net.connect(common.PORT);
|
2011-11-03 20:34:23 +01:00
|
|
|
s.pipe(process.stdout);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(false, gotTimeout);
|
|
|
|
});
|