Changeset

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 3108:cfcb020bcd1d
children 3110:06e07b483805
files mod_csi_battery_saver/mod_csi_battery_saver.lua
diffstat 1 files changed, 3 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mod_csi_battery_saver/mod_csi_battery_saver.lua	Fri Jun 08 17:39:07 2018 +0200
+++ b/mod_csi_battery_saver/mod_csi_battery_saver.lua	Fri Jun 08 17:39:43 2018 +0200
@@ -196,31 +196,19 @@
 	end
 end);
 
--- clean up this session on hibernation start
-module:hook("smacks-hibernation-start", function (event)
-	local session = event.origin;
-	if session.pump then
-		session.log("debug", "mod_csi_battery_saver(%s): Hibernation started, flushing buffer and afterwards disabling for this session", id);
-		session.pump:flush();
-		session.send = session._pump_orig_send;
-		session.pump = nil;
-		session._pump_orig_send = nil;
-	end
-end);
-
--- clean up this session on hibernation end as well
+-- clean up this session on hibernation end
 -- but don't change resumed.send(), it is already overwritten with session.send() by the smacks module
 module:hook("smacks-hibernation-end", function (event)
 	local session = event.resumed;
 	if session.pump then
-		session.log("debug", "mod_csi_battery_saver(%s): Hibernation ended without being started, flushing buffer and afterwards disabling for this session", id);
+		session.log("debug", "mod_csi_battery_saver(%s): Hibernation ended, flushing buffer and afterwards disabling for this session", id);
 		session.pump:flush(session.send);		-- use the fresh session.send() introduced by the smacks resume
 		-- don't reset session.send() because this is not the send previously overwritten by this module, but a fresh one
 		-- session.send = session._pump_orig_send;
 		session.pump = nil;
 		session._pump_orig_send = nil;
 	end
-end);
+end, 1000);		-- high priority to prevent message reordering on resumption (we want to flush our buffers *first*)
 
 function module.unload()
 	module:log("info", "%s: Unloading module, flushing all buffers", id);