Permalink
Browse files

Merge remote-tracking branch 'hpychan/master'

  • Loading branch information...
2 parents 1b15abf + 4b8e480 commit f5dcfc7b650d4a68fca9b2ce943a0598edbf3a04 @astro astro committed Aug 15, 2011
Showing with 10 additions and 5 deletions.
  1. +10 −5 lib/idle_timeout.js
View
@@ -15,15 +15,20 @@ exports.attach = function(stream, timeout) {
clearTimeout(timer);
timer = setTimeout(emitTimeout, timeout);
};
-
+
var oldWrite = stream.write;
stream.write = function() {
updateTimer();
oldWrite.apply(this, arguments);
};
+ var cleanup = function() {
+ if (timer)
+ clearTimeout(timer);
+ if ( oldWrite != stream.write) {
+ oldWrite = stream.write;
+ }
+ };
stream.addListener('data', updateTimer);
- stream.addListener('close', function() {
- if (timer)
- clearTimeout(timer);
- });
+ stream.addListener('close', cleanup);
+ stream.addListener('end', cleanup);
};

0 comments on commit f5dcfc7

Please sign in to comment.