net: ignore socket.setTimeout(Infinity) (and NaN)

This commit is contained in:
Fedor Indutny 2012-07-16 21:41:26 +04:00
parent 3c998945aa
commit b0950cbea2
2 changed files with 20 additions and 14 deletions

View File

@ -160,7 +160,7 @@ Socket.prototype.listen = function() {
Socket.prototype.setTimeout = function(msecs, callback) {
if (msecs > 0) {
if (msecs > 0 && !isNaN(msecs) && isFinite(msecs)) {
timers.enroll(this, msecs);
timers.active(this);
if (callback) {

View File

@ -33,18 +33,24 @@ var server = net.createServer(function(c) {
});
server.listen(common.PORT);
var socket = net.createConnection(common.PORT, 'localhost');
var killers = [0, Infinity, NaN];
socket.setTimeout(T, function() {
socket.destroy();
server.close();
assert.ok(false);
var left = killers.length;
killers.forEach(function(killer) {
var socket = net.createConnection(common.PORT, 'localhost');
socket.setTimeout(T, function() {
socket.destroy();
if (--left === 0) server.close();
assert.ok(killer !== 0);
clearTimeout(timeout);
});
socket.setTimeout(killer);
var timeout = setTimeout(function() {
socket.destroy();
if (--left === 0) server.close();
assert.ok(killer === 0);
}, T * 2);
});
socket.setTimeout(0);
setTimeout(function() {
socket.destroy();
server.close();
assert.ok(true);
}, T * 2);