Browse Source

fixed timers, whoops.

Fixes issue https://github.com/ry/node/issues/issue/481
v0.7.4-release
Michael W 14 years ago
committed by Ryan Dahl
parent
commit
5f3464cf4e
  1. 3
      lib/timers.js
  2. 41
      test/simple/test-net-can-reset-timeout.js

3
lib/timers.js

@ -43,7 +43,6 @@ function shift (list) {
function remove (item) {
item._idleNext._idlePrev = item._idlePrev;
item._idlePrev._idleNext = item._idleNext;
item._idleNext = null;
}
@ -209,7 +208,7 @@ exports.setTimeout = function (callback, after) {
exports.clearTimeout = function (timer) {
if (timer) {
if (timer && (timer.callback || timer._onTimeout)) {
timer.callback = timer._onTimeout = null;
exports.unenroll(timer);
if (timer instanceof Timer) timer.stop(); // for after === 0

41
test/simple/test-net-can-reset-timeout.js

@ -0,0 +1,41 @@
var net = require('net');
var common = require('../common');
var assert = require('assert');
var timeoutCount = 0;
var server = net.createServer(function(stream){
stream.setTimeout(100);
stream.on('timeout', function () {
console.log("timeout");
// try to reset the timeout.
stream.write("WHAT.");
// don't worry, the socket didn't *really* time out, we're just thinking
// it did.
timeoutCount += 1;
});
stream.on('end', function () {
console.log("server side end");
stream.end();
});
});
server.listen(common.PORT, function() {
var c = net.createConnection(common.PORT);
c.on('data', function () {
c.end();
});
c.on('end', function () {
console.log("client side end");
server.close();
});
});
process.on('exit', function () {
assert.equal(1, timeoutCount);
});
Loading…
Cancel
Save