[vlc-commits] lua: fix polling
Pierre Ynard
git at videolan.org
Mon Mar 21 01:23:12 CET 2011
vlc/vlc-1.1 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Mon Mar 21 01:16:21 2011 +0100| [5d2aef6696b8eae6ec4e18dba18f1221fbdce9fa] | committer: 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: Pierre Ynard <linkfanel at yahoo.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=5d2aef6696b8eae6ec4e18dba18f1221fbdce9fa
---
share/lua/intf/modules/host.lua | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
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
More information about the vlc-commits
mailing list