summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2011-01-01 17:11:13 +0000
committerChristian Pointner <equinox@spreadspace.org>2011-01-01 17:11:13 +0000
commit392f6627847be597456705157cd0e8372e09400e (patch)
tree807ed09f54c97ae17af5684e1711fff9199dbeaa
parentimplemented process_respons at modules (diff)
implemente max cleints at tcp_listen
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@94 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r--TODO1
-rw-r--r--src/modules/tcp_listen.lua10
2 files changed, 10 insertions, 1 deletions
diff --git a/TODO b/TODO
index 0b6206f..33e9d70 100644
--- a/TODO
+++ b/TODO
@@ -16,7 +16,6 @@ Modules:
- FIFO (named pipe)
- SSL
* tcp_listen
- - max clients
- make it an INOUT module (only single client allowed when runtype == OUT!?)
* tcp_connect
- reconnect after connection loss
diff --git a/src/modules/tcp_listen.lua b/src/modules/tcp_listen.lua
index e423718..47a97cd 100644
--- a/src/modules/tcp_listen.lua
+++ b/src/modules/tcp_listen.lua
@@ -49,6 +49,8 @@ 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)
+ inst.client_cnt = 0
local lst, err = tcp.server(config.addr, config.port, config.resolv_type)
if(not lst) then
@@ -66,6 +68,13 @@ function tcp_listen:new(config, runtype)
return defines.KILL_MODULE
end
+ if(config.max_clients and inst.client_cnt >= config.max_clients) then
+ log.printf(log.INFO, "maximum number of clients reached: %d", config.max_clients)
+ rawio.close(new_client)
+ return defines.OK
+ end
+ inst.client_cnt = inst.client_cnt + 1
+
local client_handle = {}
client_handle.fd = new_client
client_handle.client_instance = nil
@@ -125,6 +134,7 @@ function tcp_listen:new(config, runtype)
end
end
function client:cleanup()
+ inst.client_cnt = inst.client_cnt - 1
rawio.close(client_handle.fd)
end
client_handle.client_instance = client