From 392f6627847be597456705157cd0e8372e09400e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 1 Jan 2011 17:11:13 +0000 Subject: implemente max cleints at tcp_listen git-svn-id: https://svn.spreadspace.org/gcsd/trunk@94 ac14a137-c7f1-4531-abe0-07747231d213 --- TODO | 1 - src/modules/tcp_listen.lua | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3