[Pkg-javascript-commits] [ltx] 111/469: IdleTimeout
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:01:10 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit ae72ca8d26502347bb56118cce30375e9644f87f
Author: Astro <astro at spaceboyz.net>
Date: Wed Sep 8 02:51:16 2010 +0200
IdleTimeout
Because stream.setTimeout() only accounts for incoming data.
---
lib/idle_timeout.js | 25 +++++++++++++++++++++++++
lib/xmpp/router.js | 3 ++-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/lib/idle_timeout.js b/lib/idle_timeout.js
new file mode 100644
index 0000000..2e6399b
--- /dev/null
+++ b/lib/idle_timeout.js
@@ -0,0 +1,25 @@
+/**
+ * Emulates stream.setTimeout() behaviour, but respects outgoing data
+ * too.
+ *
+ * @param {Number} timeout Milliseconds
+ */
+exports.attach = function(stream, timeout) {
+ var timer;
+ var emitTimeout = function() {
+ timer = undefined;
+ stream.emit('timeout');
+ };
+ var updateTimer = function() {
+ if (timer)
+ clearTimeout(timer);
+ timer = setTimeout(emitTimeout, timeout);
+ };
+
+ var oldWrite = stream.write;
+ stream.write = function() {
+ updateTimer();
+ oldWrite.apply(this, arguments);
+ };
+ stream.addListener('data', updateTimer);
+};
diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 8d42b2b..f0dda40 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -3,6 +3,7 @@ var Server = require('./server');
var JID = require('./jid');
var xml = require('./xml');
var StreamShaper = require('./../stream_shaper');
+var IdleTimeout = require('./../idle_timeout');
var StringPrep = require('node-stringprep').StringPrep;
var nameprep = new StringPrep('nameprep');
@@ -416,7 +417,7 @@ Router.prototype.setupStream = function(stream) {
stream.maxStanzaSize = this.maxStanzaSize;
StreamShaper.attach(stream, this.rateLimit);
stream.setKeepAlive(true, this.keepAlive);
- stream.setTimeout(this.streamTimeout);
+ IdleTimeout.attach(stream, this.streamTimeout);
stream.addListener('timeout', function() {
stream.error('connection-timeout');
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list