Software /
code /
prosody
Comparison
plugins/mod_csi_simple.lua @ 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 |
parent | 9917:45b5528b128a |
child | 9919:d602a495409b |
comparison
equal
deleted
inserted
replaced
9917:45b5528b128a | 9918:6e9dcec259d0 |
---|---|
73 local function flush_buffer(data, session) | 73 local function flush_buffer(data, session) |
74 session.conn:resume_writes(); | 74 session.conn:resume_writes(); |
75 return data; | 75 return data; |
76 end | 76 end |
77 | 77 |
78 module:hook("csi-client-inactive", function (event) | 78 function enable_optimizations(session) |
79 local session = event.origin; | |
80 if session.conn and session.conn and session.conn.pause_writes then | 79 if session.conn and session.conn and session.conn.pause_writes then |
81 session.conn:pause_writes(); | 80 session.conn:pause_writes(); |
82 filters.add_filter(session, "stanzas/out", manage_buffer); | 81 filters.add_filter(session, "stanzas/out", manage_buffer); |
83 filters.add_filter(session, "bytes/in", flush_buffer); | 82 filters.add_filter(session, "bytes/in", flush_buffer); |
84 else | 83 else |
85 session.log("warn", "Session connection does not support write pausing"); | 84 session.log("warn", "Session connection does not support write pausing"); |
86 end | 85 end |
87 end); | 86 end |
88 | 87 |
89 module:hook("csi-client-active", function (event) | 88 function disble_optimizations(session) |
90 local session = event.origin; | |
91 if session.conn and session.conn and session.conn.resume_writes then | 89 if session.conn and session.conn and session.conn.resume_writes then |
92 filters.remove_filter(session, "stanzas/out", manage_buffer); | 90 filters.remove_filter(session, "stanzas/out", manage_buffer); |
93 filters.remove_filter(session, "bytes/in", flush_buffer); | 91 filters.remove_filter(session, "bytes/in", flush_buffer); |
94 session.conn:resume_writes(); | 92 session.conn:resume_writes(); |
95 end | 93 end |
94 end | |
95 | |
96 module:hook("csi-client-inactive", function (event) | |
97 local session = event.origin; | |
98 enable_optimizations(session); | |
99 end); | |
100 | |
101 module:hook("csi-client-active", function (event) | |
102 local session = event.origin; | |
103 disble_optimizations(session); | |
96 end); | 104 end); |
97 | 105 |
98 | 106 |
99 module:hook("c2s-ondrain", function (event) | 107 module:hook("c2s-ondrain", function (event) |
100 local session = event.session; | 108 local session = event.session; |