[vlc-commits] Remove select timeout.

Antoine Cellerier git at videolan.org
Sat Feb 11 12:50:35 CET 2012


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Sat Feb 11 11:57:11 2012 +0100| [ea6dc345a8cad5a1ff26dab8385776e68793b429] | committer: Antoine Cellerier

Remove select timeout.

console and socket mode are now exclusive on windows.

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

 modules/lua/libs/net.c          |    3 +-
 share/lua/README.txt            |    2 +-
 share/lua/intf/modules/host.lua |   98 ++++++++++++++++++--------------------
 3 files changed, 48 insertions(+), 55 deletions(-)

diff --git a/modules/lua/libs/net.c b/modules/lua/libs/net.c
index ddb21fa..ea61245 100644
--- a/modules/lua/libs/net.c
+++ b/modules/lua/libs/net.c
@@ -215,11 +215,10 @@ static int vlclua_net_poll( lua_State *L )
         lua_pop( L, 1 );
         i++;
     }
-    int i_timeout = luaL_optint( L, 2, -1 );
 
     int i_ret;
     do
-        i_ret = poll( p_fds, i_fds, i_timeout );
+        i_ret = poll( p_fds, i_fds, -1 );
     while( i_ret == -1 );
 
     for( i = 0; i < i_fds; i++ )
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 6cdf620..eeac084 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -191,7 +191,7 @@ net.connect_tcp( host, port ): open a connection to the given host:port (TCP).
 net.close( fd ): Close file descriptor.
 net.send( fd, string, [length] ): Send data on fd.
 net.recv( fd, [max length] ): Receive data from fd.
-net.poll( { fd = events }, [timeout in ms] ): Implement poll function.
+net.poll( { fd = events } ): Implement poll function.
   Returns the numbers of file descriptors with a non 0 revent. The function
   modifies the input table to { fd = revents }. See "man poll".
 net.POLLIN/POLLPRI/POLLOUT/POLLRDHUP/POLLERR/POLLHUP/POLLNVAL: poll event flags
diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua
index 9b08bff..aeadc02 100644
--- a/share/lua/intf/modules/host.lua
+++ b/share/lua/intf/modules/host.lua
@@ -122,11 +122,7 @@ function host()
 
     local function read_console( client, len )
         -- Read stdin from a windows console (beware: select/poll doesn't work!)
-		if vlc.win.console_wait(0) then
-			return vlc.win.console_read()
-        else
-			return 0
-		end
+        return vlc.win.console_read()
     end
 
     local function del_client( client )
@@ -208,6 +204,9 @@ function host()
                          and listeners.tcp[host][port] then
             error("Already listening on tcp host `"..host..":"..tostring(port).."'")
         end
+        if listeners.stdio and vlc.win then
+            error("Cannot listen on console and sockets concurrently on Windows")
+        end
         if not listeners.tcp then
             listeners.tcp = {}
         end
@@ -230,6 +229,9 @@ function host()
         if listeners.stdio then
             error("Already listening on stdio")
         end
+        if listeners.tcp and vlc.win then
+            error("Cannot listen on console and sockets concurrently on Windows")
+        end
         new_client( h, 0, 1, client_type.stdio )
         listeners.stdio = true
     end
@@ -250,63 +252,56 @@ function host()
         end
     end
 
-    local function _accept_and_select( h, timeout )
-        local function filter_client( fds, status, event )
-            for _, client in pairs(clients) do
-                if client.status == status then
-                    fds[client:fd()] = event
-                end
-            end
-        end
-
-        local pollfds = {}
-        filter_client( pollfds, status.read, vlc.net.POLLIN )
-        filter_client( pollfds, status.password, vlc.net.POLLIN )
-        filter_client( pollfds, status.write, vlc.net.POLLOUT )
-        if listeners.tcp then
-            for _, listener in pairs(listeners.tcp.list) do
-                for _, fd in pairs({listener.data:fds()}) do
-                    pollfds[fd] = vlc.net.POLLIN
-                end
-            end
-        end
-
-        local timeout = -1
-        if vlc.win and listeners.stdio then
-            timeout = 50
-        end
-        local ret = 0
-        if not vlc.win or listeners.tcp then
-            ret = vlc.net.poll( pollfds, timeout )
-        end
+    local function _accept_and_select( h )
         local wclients = {}
         local rclients = {}
-        if ret > 0 then
-            for _, client in pairs(clients) do
-                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)
-                elseif is_flag_set(pollfds[client:fd()], vlc.net.POLLIN) then
-                    table.insert(rclients, client)
+        if not (vlc.win and listeners.stdio) then
+            local function filter_client( fds, status, event )
+                for _, client in pairs(clients) do
+                    if client.status == status then
+                        fds[client:fd()] = event
+                    end
                 end
             end
+
+            local pollfds = {}
+            filter_client( pollfds, status.read, vlc.net.POLLIN )
+            filter_client( pollfds, status.password, vlc.net.POLLIN )
+            filter_client( pollfds, status.write, vlc.net.POLLOUT )
             if listeners.tcp then
                 for _, listener in pairs(listeners.tcp.list) do
                     for _, fd in pairs({listener.data:fds()}) do
-                        if is_flag_set(pollfds[fd], vlc.net.POLLIN) then
-                            local afd = listener.data:accept()
-                            new_client( h, afd, afd, listener.type )
-                            break
-                        end
+                        pollfds[fd] = vlc.net.POLLIN
                     end
                 end
             end
-        end
 
-        if vlc.win and listeners.stdio then
+            local ret = vlc.net.poll( pollfds )
+            if ret > 0 then
+                for _, client in pairs(clients) do
+                    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)
+                    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.data:fds()}) do
+                            if is_flag_set(pollfds[fd], vlc.net.POLLIN) then
+                                local afd = listener.data:accept()
+                                new_client( h, afd, afd, listener.type )
+                                break
+                            end
+                        end
+                    end
+                end
+            end
+        else
             for _, client in pairs(clients) do
                 if client.type == client_type.stdio then
                     if client.status == status.read or client.status == status.password then
@@ -319,7 +314,6 @@ function host()
                 end
             end
         end
-
         return wclients, rclients
     end
 



More information about the vlc-commits mailing list