summaryrefslogtreecommitdiff
path: root/mode-tcpserver.lua
diff options
context:
space:
mode:
Diffstat (limited to 'mode-tcpserver.lua')
-rw-r--r--mode-tcpserver.lua17
1 files changed, 11 insertions, 6 deletions
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