Changeset

6528:f0687c313cf1

mod_bosh: Use util.async
author Kim Alvefur <zash@zash.se>
date Sun, 07 Dec 2014 17:56:25 +0100
parents 6526:873538f0b18c
children 6529:a2dadaa9137f
files plugins/mod_bosh.lua
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_bosh.lua	Sat Nov 22 11:51:54 2014 +0100
+++ b/plugins/mod_bosh.lua	Sun Dec 07 17:56:25 2014 +0100
@@ -22,6 +22,7 @@
 local math_min = math.min;
 local xpcall, tostring, type = xpcall, tostring, type;
 local traceback = debug.traceback;
+local runner = require"util.async".runner;
 
 local xmlns_streams = "http://etherx.jabber.org/streams";
 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
@@ -228,6 +229,8 @@
 	sm_destroy_session(session);
 end
 
+local runner_callbacks = { };
+
 -- Handle the <body> tag in the request payload.
 function stream_callbacks.streamopened(context, attr)
 	local request, response = context.request, context.response;
@@ -260,6 +263,10 @@
 		};
 		sessions[sid] = session;
 
+		session.thread = runner(function (stanza)
+			session:dispatch_stanza(stanza);
+		end, runner_callbacks, session);
+
 		local filter = initialize_filters(session);
 
 		session.log("debug", "BOSH session created for request from %s", session.ip);
@@ -355,6 +362,11 @@
 end
 
 local function handleerr(err) log("error", "Traceback[bosh]: %s", traceback(tostring(err), 2)); end
+
+function runner_callbacks:error(err)
+	return handleerr(err);
+end
+
 function stream_callbacks.handlestanza(context, stanza)
 	if context.ignore then return; end
 	log("debug", "BOSH stanza received: %s\n", stanza:top_tag());
@@ -364,9 +376,7 @@
 			stanza.attr.xmlns = nil;
 		end
 		stanza = session.filter("stanzas/in", stanza);
-		if stanza then
-			return xpcall(function () return core_process_stanza(session, stanza) end, handleerr);
-		end
+		session.thread:run(stanza);
 	end
 end