Commit ce00244d 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.
parent 30be997d
...@@ -66,6 +66,10 @@ module("host",package.seeall) ...@@ -66,6 +66,10 @@ module("host",package.seeall)
status = { init = 0, read = 1, write = 2, password = 3 } status = { init = 0, read = 1, write = 2, password = 3 }
client_type = { net = 1, stdio = 2, fifo = 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() function host()
-- private data -- private data
local clients = {} local clients = {}
...@@ -248,17 +252,20 @@ function host() ...@@ -248,17 +252,20 @@ function host()
local rclients = {} local rclients = {}
if ret > 0 then if ret > 0 then
for _, client in pairs(clients) do 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) table.insert(wclients,client)
end elseif is_flag_set(pollfds[client:fd()], vlc.net.POLLIN) then
if pollfds[client:fd()] == vlc.net.POLLIN then
table.insert(rclients,client) table.insert(rclients,client)
end end
end end
if listeners.tcp then if listeners.tcp then
for _, listener in pairs(listeners.tcp.list) do for _, listener in pairs(listeners.tcp.list) do
for _, fd in pairs({listener:fds()}) 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() local afd = listener:accept()
new_client( h, afd, afd, client_type.net ) new_client( h, afd, afd, client_type.net )
break 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