summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2011-01-01 20:01:26 +0000
committerChristian Pointner <equinox@spreadspace.org>2011-01-01 20:01:26 +0000
commita4159a516c0fecd3701da2c12265873ca7dabcd8 (patch)
tree754682d275bf68769c0ed4ab2126784368eb7f3f
parentimplemente max cleints at tcp_listen (diff)
tcp_listen can act as out module now
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@95 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r--TODO2
-rw-r--r--src/main_loop.lua4
-rw-r--r--src/modules/tcp_listen.lua24
3 files changed, 24 insertions, 6 deletions
diff --git a/TODO b/TODO
index 33e9d70..2cb4a2a 100644
--- a/TODO
+++ b/TODO
@@ -15,8 +15,6 @@ Modules:
- PTY
- FIFO (named pipe)
- SSL
- * tcp_listen
- - make it an INOUT module (only single client allowed when runtype == OUT!?)
* tcp_connect
- reconnect after connection loss
- try all resolved remote addressess (also at reconnect)
diff --git a/src/main_loop.lua b/src/main_loop.lua
index 318edfd..f80cf00 100644
--- a/src/main_loop.lua
+++ b/src/main_loop.lua
@@ -37,7 +37,7 @@ function get_readables()
table.insert(readables, fd)
end
end
- for _, fd in ipairs(module_list.output.get_read_handles()) do
+ for _, fd in ipairs(module_list.output:get_read_handles()) do
table.insert(readables, fd)
end
for _, client in ipairs(client_list.clients) do
@@ -56,7 +56,7 @@ function get_writeables()
table.insert(writeables, fd)
end
end
- for _, fd in ipairs(module_list.output.get_write_handles()) do
+ for _, fd in ipairs(module_list.output:get_write_handles()) do
table.insert(writeables, fd)
end
for _, client in ipairs(client_list.clients) do
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