[vlc-devel] commit: Remove timeout parameter from lua listner:accept(). ( Antoine Cellerier )

git version control git at videolan.org
Sat Jan 9 11:50:57 CET 2010


vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Sat Jan  9 11:41:09 2010 +0100| [5f5d77942050184425bee5a60433a08a402b192e] | committer: Antoine Cellerier 

Remove timeout parameter from lua listner:accept().

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

 modules/misc/lua/libs/net.c     |   30 +-----------------------------
 share/lua/README.txt            |    9 +++++----
 share/lua/intf/modules/host.lua |    2 +-
 3 files changed, 7 insertions(+), 34 deletions(-)

diff --git a/modules/misc/lua/libs/net.c b/modules/misc/lua/libs/net.c
index 17d8912..f577211 100644
--- a/modules/misc/lua/libs/net.c
+++ b/modules/misc/lua/libs/net.c
@@ -139,35 +139,7 @@ static int vlclua_net_accept( lua_State *L )
 {
     vlc_object_t *p_this = vlclua_get_this( L );
     int **ppi_fd = (int**)luaL_checkudata( L, 1, "net_listen" );
-    int *pi_fd = *ppi_fd;
-    int i_timeout = luaL_optint( L, 2, -1 ); /* block is default */
-
-    /* Implement net_Accept with timeout */
-    int i_fd = -1;
-
-    unsigned int i_count = 1;
-    while( pi_fd[i_count] != -1 )
-        i_count++;
-
-    struct pollfd ufd[i_count+1];
-    unsigned int i;
-    for( i = 0; i < i_count; i++ )
-    {
-        ufd[i].fd = pi_fd[i];
-        ufd[i].events = POLLIN;
-    }
-
-    if( poll( ufd, i_count, i_timeout ) > 0 )
-    {
-        for( i = 0; i < i_count; i++ )
-        {
-            if( !ufd[i].revents ) continue;
-            i_fd = net_AcceptSingle( p_this, ufd[i].fd );
-            if( i_fd == -1 ) continue;
-            memmove( pi_fd + i, pi_fd + i + 1, i_count - (i + 1) );
-            pi_fd[i_count - 1] = ufd[i].fd;
-        }
-    }
+    int i_fd = net_Accept( p_this, *ppi_fd );
 
     lua_pushinteger( L, i_fd );
     return 1;
diff --git a/share/lua/README.txt b/share/lua/README.txt
index bcafa1b..1257d4e 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -112,12 +112,13 @@ net.url_parse( url, [option delimiter] ): Parse URL. Returns a table with
   fields "protocol", "username", "password", "host", "port", path" and
   "option".
 net.listen_tcp( host, port ): Listen to TCP connections. This returns an
-  object with an accept and an fds method. The accept takes an optional timeout
-  argument (in milliseconds). The fds method returns a list of fds you can call
-  select on before using the accept method. For example:
+  object with an accept and an fds method. accept is blocking (Poll on the
+  fds with the net.POLLIN flag if you want to be non blockin).
+  The fds method returns a list of fds you can call select on before using
+  the accept method. For example:
 local l = vlc.net.listen_tcp( "localhost", 1234 )
 while true do
-  local fd = l:accept( 500 )
+  local fd = l:accept()
   if fd >= 0 do
     net.send( fd, "blabla" )
     net.close( fd )
diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua
index 5f3da6c..baa7c84 100644
--- a/share/lua/intf/modules/host.lua
+++ b/share/lua/intf/modules/host.lua
@@ -258,7 +258,7 @@ function host()
                 for _, listener in pairs(listeners.tcp.list) do
                     for _, fd in pairs({listener:fds()}) do
                         if pollfds[fd] == vlc.net.POLLIN then
-                            local afd = listener:accept(0)
+                            local afd = listener:accept()
                             new_client( h, afd, afd, client_type.net )
                             break
                         end




More information about the vlc-devel mailing list