Skip to content

Commit

Permalink
rm idle_timeout on stream 'error' & Connection.setSecure()
Browse files Browse the repository at this point in the history
should fix Github issue #54
  • Loading branch information
astro committed Feb 20, 2012
1 parent eb0a9cb commit 4be6f38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/idle_timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ 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() {
var clear = function() {
if (timer)
clearTimeout(timer);
if ( oldWrite != stream.write) {
oldWrite = stream.write;
}
if (stream.write !== oldWrite)
stream.write = oldWrite;
delete stream.clearTimer;
};
stream.clearTimer = clear;
stream.addListener('data', updateTimer);
stream.addListener('close', cleanup);
stream.addListener('end', cleanup);
stream.addListener('error', clear);
stream.addListener('close', clear);
stream.addListener('end', clear);
};
3 changes: 3 additions & 0 deletions lib/xmpp/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ Connection.prototype.setSecure = function(credentials, isServer) {
// retain socket 'end' listeners because ssl layer doesn't support it
this.socket.removeAllListeners('drain');
this.socket.removeAllListeners('close');
// remove idle_timeout
if (this.socket.clearTimer)
this.socket.clearTimer();

var ct = starttls(this.socket, credentials || this.credentials, isServer, function() {
self.isSecure = true;
Expand Down

0 comments on commit 4be6f38

Please sign in to comment.