Mercurial > prosody-modules
comparison mod_csi_battery_saver/mod_csi_battery_saver.lua @ 3109:75930e4c2478
mod_csi_battery_saver: flush queue on smacks resume instead of smacks hibernation
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Fri, 08 Jun 2018 17:39:43 +0200 |
parents | dfac28504e86 |
children | 1c8612d8db55 |
comparison
equal
deleted
inserted
replaced
3108:cfcb020bcd1d | 3109:75930e4c2478 |
---|---|
194 session.log("debug", "mod_csi_battery_saver(%s): Client is active, resuming direct delivery", id); | 194 session.log("debug", "mod_csi_battery_saver(%s): Client is active, resuming direct delivery", id); |
195 session.pump:resume(); | 195 session.pump:resume(); |
196 end | 196 end |
197 end); | 197 end); |
198 | 198 |
199 -- clean up this session on hibernation start | 199 -- clean up this session on hibernation end |
200 module:hook("smacks-hibernation-start", function (event) | |
201 local session = event.origin; | |
202 if session.pump then | |
203 session.log("debug", "mod_csi_battery_saver(%s): Hibernation started, flushing buffer and afterwards disabling for this session", id); | |
204 session.pump:flush(); | |
205 session.send = session._pump_orig_send; | |
206 session.pump = nil; | |
207 session._pump_orig_send = nil; | |
208 end | |
209 end); | |
210 | |
211 -- clean up this session on hibernation end as well | |
212 -- but don't change resumed.send(), it is already overwritten with session.send() by the smacks module | 200 -- but don't change resumed.send(), it is already overwritten with session.send() by the smacks module |
213 module:hook("smacks-hibernation-end", function (event) | 201 module:hook("smacks-hibernation-end", function (event) |
214 local session = event.resumed; | 202 local session = event.resumed; |
215 if session.pump then | 203 if session.pump then |
216 session.log("debug", "mod_csi_battery_saver(%s): Hibernation ended without being started, flushing buffer and afterwards disabling for this session", id); | 204 session.log("debug", "mod_csi_battery_saver(%s): Hibernation ended, flushing buffer and afterwards disabling for this session", id); |
217 session.pump:flush(session.send); -- use the fresh session.send() introduced by the smacks resume | 205 session.pump:flush(session.send); -- use the fresh session.send() introduced by the smacks resume |
218 -- don't reset session.send() because this is not the send previously overwritten by this module, but a fresh one | 206 -- don't reset session.send() because this is not the send previously overwritten by this module, but a fresh one |
219 -- session.send = session._pump_orig_send; | 207 -- session.send = session._pump_orig_send; |
220 session.pump = nil; | 208 session.pump = nil; |
221 session._pump_orig_send = nil; | 209 session._pump_orig_send = nil; |
222 end | 210 end |
223 end); | 211 end, 1000); -- high priority to prevent message reordering on resumption (we want to flush our buffers *first*) |
224 | 212 |
225 function module.unload() | 213 function module.unload() |
226 module:log("info", "%s: Unloading module, flushing all buffers", id); | 214 module:log("info", "%s: Unloading module, flushing all buffers", id); |
227 local host_sessions = prosody.hosts[module.host].sessions; | 215 local host_sessions = prosody.hosts[module.host].sessions; |
228 for _, user in pairs(host_sessions) do | 216 for _, user in pairs(host_sessions) do |