Changeset

9918:6e9dcec259d0

mod_csi_simple: Separate out functions to enable/disable optimizations This allows reusing this logic outside the events. Letting the functions be module globals makes it easier to access from eg the telnet console.
author Kim Alvefur <zash@zash.se>
date Sun, 24 Mar 2019 20:41:25 +0100
parents 9917:45b5528b128a
children 9919:d602a495409b
files plugins/mod_csi_simple.lua
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_csi_simple.lua	Sun Mar 24 20:22:01 2019 +0100
+++ b/plugins/mod_csi_simple.lua	Sun Mar 24 20:41:25 2019 +0100
@@ -75,8 +75,7 @@
 	return data;
 end
 
-module:hook("csi-client-inactive", function (event)
-	local session = event.origin;
+function enable_optimizations(session)
 	if session.conn and session.conn and session.conn.pause_writes then
 		session.conn:pause_writes();
 		filters.add_filter(session, "stanzas/out", manage_buffer);
@@ -84,15 +83,24 @@
 	else
 		session.log("warn", "Session connection does not support write pausing");
 	end
-end);
+end
 
-module:hook("csi-client-active", function (event)
-	local session = event.origin;
+function disble_optimizations(session)
 	if session.conn and session.conn and session.conn.resume_writes then
 		filters.remove_filter(session, "stanzas/out", manage_buffer);
 		filters.remove_filter(session, "bytes/in", flush_buffer);
 		session.conn:resume_writes();
 	end
+end
+
+module:hook("csi-client-inactive", function (event)
+	local session = event.origin;
+	enable_optimizations(session);
+end);
+
+module:hook("csi-client-active", function (event)
+	local session = event.origin;
+	disble_optimizations(session);
 end);