# HG changeset patch # User Kim Alvefur # Date 1588975104 -7200 # Node ID 16bcbd5748016b02f017d25dacaf55b0e71460a6 # Parent 8a0a923e1cedeff21500a7d5d4cbf51b71f00e3b mod_c2s: Run stream open and close events in async thread, fixes #1103 Enables async processing during stream opening and closing. diff -r 8a0a923e1ced -r 16bcbd574801 plugins/mod_c2s.lua --- a/plugins/mod_c2s.lua Fri May 08 23:55:51 2020 +0200 +++ b/plugins/mod_c2s.lua Fri May 08 23:58:24 2020 +0200 @@ -55,6 +55,11 @@ local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; function stream_callbacks.streamopened(session, attr) + -- run _streamopened in async context + session.thread:run({ stream = "opened", attr = attr }); +end + +function stream_callbacks._streamopened(session, attr) local send = session.send; if not attr.to then session:close{ condition = "improper-addressing", @@ -121,7 +126,12 @@ end end -function stream_callbacks.streamclosed(session) +function stream_callbacks.streamclosed(session, attr) + -- run _streamclosed in async context + session.thread:run({ stream = "closed", attr = attr }); +end + +function stream_callbacks._streamclosed(session) session.log("debug", "Received "); session:close(false); end @@ -280,7 +290,13 @@ end session.thread = runner(function (stanza) - core_process_stanza(session, stanza); + if st.is_stanza(stanza) then + core_process_stanza(session, stanza); + elseif stanza.stream == "opened" then + stream_callbacks._streamopened(session, stanza.attr); + elseif stanza.stream == "closed" then + stream_callbacks._streamclosed(session, stanza.attr); + end end, runner_callbacks, session); local filter = session.filter;