summaryrefslogtreecommitdiff
path: root/src/modules/tcp_listen.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/tcp_listen.lua')
-rw-r--r--src/modules/tcp_listen.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/modules/tcp_listen.lua b/src/modules/tcp_listen.lua
index 47a97cd..f6d3854 100644
--- a/src/modules/tcp_listen.lua
+++ b/src/modules/tcp_listen.lua
@@ -32,7 +32,7 @@
-- tcp_listen module class
local tcp_listen = {}
-tcp_listen.properties = { type=defines.IN_MODULE, name="tcp-listen", max_instances=-1 }
+tcp_listen.properties = { type=defines.INOUT_MODULE, name="tcp-listen", max_instances=-1 }
tcp_listen.defaults = { port = "1234" }
tcp_listen.next_id = 0
@@ -49,7 +49,14 @@ function tcp_listen:new(config, runtype)
inst.name = config.name
end
if(not config.port) then config.port = self.defaults.port end
- config.max_clients = tonumber(config.max_clients)
+ if(runtype == defines.OUT_MODULE) then
+ if(config.max_clients) then
+ log.printf(log.WARNING, "%s: module running as output, ignoring max_clients parameter", inst.name)
+ end
+ config.max_clients = 1
+ else
+ config.max_clients = tonumber(config.max_clients)
+ end
inst.client_cnt = 0
local lst, err = tcp.server(config.addr, config.port, config.resolv_type)
@@ -57,6 +64,7 @@ function tcp_listen:new(config, runtype)
return nil
end
+ inst.outclient = nil
inst.listeners = lst
for _, l in ipairs(inst.listeners) do
log.printf(log.NOTICE, "%s: listening on %s", inst.name, tcp.endtostring(l.local_end))
@@ -136,9 +144,14 @@ function tcp_listen:new(config, runtype)
function client:cleanup()
inst.client_cnt = inst.client_cnt - 1
rawio.close(client_handle.fd)
+ inst.outhandle = nil
end
client_handle.client_instance = client
client_list:register(client)
+ if(inst.config.runtype == defines.OUT_MODULE) then
+ inst.outhandle = client_handle
+ end
+
return defines.OK
end
function l:write() return defines.OK end
@@ -156,6 +169,13 @@ function tcp_listen:new(config, runtype)
function inst:get_write_handles()
return {}
end
+ function inst:start_command(command)
+ if(inst.outhandle) then
+ inst.outhandle.out_buffer = command
+ else
+ command_queue:command_sent()
+ end
+ end
setmetatable(inst, {})
getmetatable(inst).__gc = function() inst:cleanup() end