[vlc-devel] [PATCH] lua: fix polling
Pierre Ynard
linkfanel at yahoo.fr
Fri Mar 18 22:20:58 CET 2011
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.
Apparently lua doesn't support bitwise operators. Unless someone has a
smarter solution, I guess this should go in 1.1.8.
diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua
index 4601b25..321b71b 100644
--- a/share/lua/intf/modules/host.lua
+++ b/share/lua/intf/modules/host.lua
@@ -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
Regards,
--
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."
More information about the vlc-devel
mailing list