Comparison

plugins/mod_csi_simple.lua @ 9923:e83dfcdeab59

mod_csi_simple: Include queue size in debug messages
author Kim Alvefur <zash@zash.se>
date Mon, 25 Mar 2019 15:20:28 +0100
parent 9922:06bf5ccd859f
child 10025:4498f601516d
comparison
equal deleted inserted replaced
9922:06bf5ccd859f 9923:e83dfcdeab59
60 end 60 end
61 61
62 local function manage_buffer(stanza, session) 62 local function manage_buffer(stanza, session)
63 local ctr = session.csi_counter or 0; 63 local ctr = session.csi_counter or 0;
64 if ctr >= queue_size then 64 if ctr >= queue_size then
65 session.log("debug", "Queue size limit hit, flushing buffer"); 65 session.log("debug", "Queue size limit hit, flushing buffer (queue size is %d)", session.csi_counter);
66 session.conn:resume_writes(); 66 session.conn:resume_writes();
67 elseif module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then 67 elseif module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then
68 session.log("debug", "Important stanza, flushing buffer"); 68 session.log("debug", "Important stanza, flushing buffer (queue size is %d)", session.csi_counter);
69 session.conn:resume_writes(); 69 session.conn:resume_writes();
70 else 70 else
71 stanza = with_timestamp(stanza, jid.join(session.username, session.host)) 71 stanza = with_timestamp(stanza, jid.join(session.username, session.host))
72 end 72 end
73 session.csi_counter = ctr + 1; 73 session.csi_counter = ctr + 1;
74 return stanza; 74 return stanza;
75 end 75 end
76 76
77 local function flush_buffer(data, session) 77 local function flush_buffer(data, session)
78 session.log("debug", "Client sent something, flushing buffer once"); 78 session.log("debug", "Client sent something, flushing buffer once (queue size is %d)", session.csi_counter);
79 session.conn:resume_writes(); 79 session.conn:resume_writes();
80 return data; 80 return data;
81 end 81 end
82 82
83 function enable_optimizations(session) 83 function enable_optimizations(session)
110 110
111 111
112 module:hook("c2s-ondrain", function (event) 112 module:hook("c2s-ondrain", function (event)
113 local session = event.session; 113 local session = event.session;
114 if session.state == "inactive" and session.conn and session.conn and session.conn.pause_writes then 114 if session.state == "inactive" and session.conn and session.conn and session.conn.pause_writes then
115 session.conn:pause_writes();
116 session.log("debug", "Buffer flushed, resuming inactive mode (queue size was %d)", session.csi_counter);
115 session.csi_counter = 0; 117 session.csi_counter = 0;
116 session.conn:pause_writes();
117 session.log("debug", "Buffer flushed, resuming inactive mode");
118 end 118 end
119 end); 119 end);
120 120
121 function module.load() 121 function module.load()
122 for _, user_session in pairs(prosody.hosts[module.host].sessions) do 122 for _, user_session in pairs(prosody.hosts[module.host].sessions) do