Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
fixed timers, whoops.
Browse files Browse the repository at this point in the history
  • Loading branch information
gcr authored and ry committed Dec 1, 2010
1 parent 355936d commit 5f3464c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function shift (list) {
function remove (item) {
item._idleNext._idlePrev = item._idlePrev;
item._idlePrev._idleNext = item._idleNext;
item._idleNext = null;
}


Expand Down Expand Up @@ -209,7 +208,7 @@ exports.setTimeout = function (callback, after) {


exports.clearTimeout = function (timer) {
if (timer) {
if (timer && (timer.callback || timer._onTimeout)) {

This comment has been minimized.

Copy link
@gcr
timer.callback = timer._onTimeout = null;
exports.unenroll(timer);
if (timer instanceof Timer) timer.stop(); // for after === 0
Expand Down
41 changes: 41 additions & 0 deletions test/simple/test-net-can-reset-timeout.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 5f3464c

Please sign in to comment.