From bfd40f6361f82119177e8d3d3defb66f123e74eb Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 4 May 2011 21:09:27 +0000 Subject: improved client handling at mode-tcpserver diff --git a/mode-tcpserver.lua b/mode-tcpserver.lua index 671ba09..fa76574 100644 --- a/mode-tcpserver.lua +++ b/mode-tcpserver.lua @@ -36,7 +36,7 @@ end local clients = {} function add_client(hdl) - -- print("new client(" .. hdl:getfd() .. ") from " .. hdl:getpeername()) + log.printf(log.DEBUG, "new client(" .. hdl:getfd() .. ") from " .. hdl:getpeername()) local client = {} if current_mode then client.buffer = current_mode .. "\n" @@ -51,20 +51,25 @@ end function remove_client(c) local idx = 0 - for idx, client in ipairs(clients) do + local found = false + for i, client in ipairs(clients) do if client == c then + found = true + idx = i break end end - -- print("removing client(" .. c.hdl:getfd() .. ")") - c.hdl:close() - table.remove(clients, idx) + if found then + log.printf(log.DEBUG, "removing client(" .. c.hdl:getfd() .. ")") + c.hdl:close() + table.remove(clients, idx) + end end function cleanup_clients() for _, client in ipairs(clients) do - client:close() + client.hdl:close() end end -- cgit v0.10.2