Commit 5d2aef66 authored by Pierre Ynard's avatar Pierre Ynard

lua: fix polling

poll() revents are flags, and the lua module tests for equality...
Obviously this has been working merely by accident given that a remote
host resetting a connection generates only POLLIN, and neither POLLHUP
nor POLLERR.

lua doesn't support bitwise operators so this is the simplest way.
(cherry picked from commit ce00244d121cfba2bbbc5065fcd3a6eb84bbba6c)
Signed-off-by: default avatarPierre Ynard <linkfanel@yahoo.fr>
parent 2038976c
......@@ -66,6 +66,10 @@ module("host",package.seeall)
status = { init = 0, read = 1, write = 2, password = 3 }
client_type = { net = 1, stdio = 2, fifo = 3 }
function is_flag_set(val, flag)
return (((val - (val % flag)) / flag) % 2 ~= 0)
end
function host()
-- private data
local clients = {}
......@@ -248,17 +252,20 @@ function host()
local rclients = {}
if ret > 0 then
for _, client in pairs(clients) do
if pollfds[client:fd()] == vlc.net.POLLOUT then
if is_flag_set(pollfds[client:fd()], vlc.net.POLLERR)
or is_flag_set(pollfds[client:fd()], vlc.net.POLLHUP)
or is_flag_set(pollfds[client:fd()], vlc.net.POLLNVAL) then
del_client(client)
elseif is_flag_set(pollfds[client:fd()], vlc.net.POLLOUT) then
table.insert(wclients,client)
end
if pollfds[client:fd()] == vlc.net.POLLIN then
elseif is_flag_set(pollfds[client:fd()], vlc.net.POLLIN) then
table.insert(rclients,client)
end
end
if listeners.tcp then
for _, listener in pairs(listeners.tcp.list) do
for _, fd in pairs({listener:fds()}) do
if pollfds[fd] == vlc.net.POLLIN then
if is_flag_set(pollfds[fd], vlc.net.POLLIN) then
local afd = listener:accept()
new_client( h, afd, afd, client_type.net )
break
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment