aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-12-27 02:53:34 +0100
committerKim Alvefur <zash@zash.se>2018-12-27 02:53:34 +0100
commit851f33034886b3d25d698497139cb51bf40ed506 (patch)
tree74bf7377496be25fbe9de65c67abdfb0a135248f /plugins
parent9a412b02e9ab54e2201986bae39e5c7c1d664d3d (diff)
downloadprosody-851f33034886b3d25d698497139cb51bf40ed506.tar.gz
prosody-851f33034886b3d25d698497139cb51bf40ed506.zip
mod_admin_telnet: Enable async processing using util.async
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_telnet.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua
index 5ba88b84..bb97a09b 100644
--- a/plugins/mod_admin_telnet.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -31,6 +31,7 @@ local cert_verify_identity = require "util.x509".verify_identity;
local envload = require "util.envload".envload;
local envloadfile = require "util.envload".envloadfile;
local has_pposix, pposix = pcall(require, "util.pposix");
+local async = require "util.async";
local commands = module:shared("commands")
local def_env = module:shared("env");
@@ -48,6 +49,21 @@ end
console = {};
+local runner_callbacks = {};
+
+function runner_callbacks:ready()
+ self.data.conn:resume();
+end
+
+function runner_callbacks:waiting()
+ self.data.conn:pause();
+end
+
+function runner_callbacks:error(err)
+ module:log("error", "Traceback[telnet]: %s", err);
+end
+
+
function console:new_session(conn)
local w = function(s) conn:write(s:gsub("\n", "\r\n")); end;
local session = { conn = conn;
@@ -63,6 +79,11 @@ function console:new_session(conn)
};
session.env = setmetatable({}, default_env_mt);
+ session.thread = async.runner(function (line)
+ console:process_line(session, line);
+ session.send(string.char(0));
+ end, runner_callbacks, session);
+
-- Load up environment with helper objects
for name, t in pairs(def_env) do
if type(t) == "table" then
@@ -151,8 +172,7 @@ function console_listener.onincoming(conn, data)
for line in data:gmatch("[^\n]*[\n\004]") do
if session.closed then return end
- console:process_line(session, line);
- session.send(string.char(0));
+ session.thread:run(line);
end
session.partial_data = data:match("[^\n]+$");
end