summaryrefslogtreecommitdiff
path: root/mode-tcpserver.lua
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-05-04 21:09:27 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-05-04 21:09:27 (GMT)
commitbfd40f6361f82119177e8d3d3defb66f123e74eb (patch)
tree8609a486e97821d56ba66f7bc5137ae422758120 /mode-tcpserver.lua
parent0b45d1f97687ccd7cdcc82fa53530b6dacd6a4b8 (diff)
improved client handling at mode-tcpserver
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