[vlc-commits] lua: fix polling

Pierre Ynard git at videolan.org
Mon Mar 21 01:18:40 CET 2011


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Mon Mar 21 01:16:21 2011 +0100| [ce00244d121cfba2bbbc5065fcd3a6eb84bbba6c] | 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ce00244d121cfba2bbbc5065fcd3a6eb84bbba6c
---

 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