Software /
code /
prosody-modules
Diff
mod_smacks/mod_smacks.lua @ 200:64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 08 Jul 2010 14:00:05 +0100 |
parent | 160:9a7671720dec |
child | 201:bc24f58a0d39 |
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua Thu Jul 08 13:46:04 2010 +0800 +++ b/mod_smacks/mod_smacks.lua Thu Jul 08 14:00:05 2010 +0100 @@ -7,6 +7,8 @@ local sm_attr = { xmlns = xmlns_sm }; +local max_unacked_stanzas = 0; + module:add_event_hook("stream-features", function (session, features) features:tag("sm", sm_attr):tag("optional"):up():up(); @@ -34,7 +36,8 @@ queue[queue_length] = st.reply(stanza); end local ok, err = _send(stanza); - if ok then + if ok and queue_length > max_unacked_stanzas and not session.awaiting_ack then + session.awaiting_ack = true; return _send(st.stanza("r", { xmlns = xmlns_sm })); end return ok, err; @@ -56,7 +59,7 @@ module:hook_stanza(xmlns_sm, "a", function (origin, stanza) if not origin.smacks then return; end - + origin.awaiting_ack = nil; -- Remove handled stanzas from outgoing_stanza_queue local handled_stanza_count = tonumber(stanza.attr.h)+1; for i=1,handled_stanza_count do