mod_csi_simple: Set session state to 'flushing' while doing so
authorKim Alvefur <zash@zash.se>
Tue, 16 Feb 2021 23:09:51 +0100
changeset 11383 5c820553ef82
parent 11382 b790df8f9448
child 11384 9a1758c5aaa4
mod_csi_simple: Set session state to 'flushing' while doing so May be useful for 3rd party modules.
plugins/mod_csi_simple.lua
--- a/plugins/mod_csi_simple.lua	Mon Feb 15 22:30:28 2021 +0100
+++ b/plugins/mod_csi_simple.lua	Tue Feb 16 23:09:51 2021 +0100
@@ -127,6 +127,7 @@
 		flush_reasons[why or "important"]();
 		session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter);
 		session.conn:resume_writes();
+		session.state = "flushing";
 	else
 		session.log("debug", "Holding buffer (%s; queue size is %d)", why or "unimportant", session.csi_counter);
 		stanza = with_timestamp(stanza, jid.join(session.username, session.host))
@@ -188,7 +189,8 @@
 
 module:hook("c2s-ondrain", function (event)
 	local session = event.session;
-	if session.state == "inactive" and session.conn and session.conn.pause_writes then
+	if (session.state == "flushing" or session.state == "inactive") and session.conn and session.conn.pause_writes then
+		session.state = "inactive";
 		session.conn:pause_writes();
 		session.csi_measure_buffer_hold = measure_buffer_hold();
 		session.log("debug", "Buffer flushed, resuming inactive mode (queue size was %d)", session.csi_counter);