]> git.sesse.net Git - vlc/commitdiff
Remove timeout parameter from lua listner:accept().
authorAntoine Cellerier <dionoea@videolan.org>
Sat, 9 Jan 2010 10:41:09 +0000 (11:41 +0100)
committerAntoine Cellerier <dionoea@videolan.org>
Sat, 9 Jan 2010 10:48:42 +0000 (11:48 +0100)
modules/misc/lua/libs/net.c
share/lua/README.txt
share/lua/intf/modules/host.lua

index 17d8912dfa974bc005d8c10cff048b185ae0282c..f577211e988be32810b592bf63558c697f215321 100644 (file)
@@ -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;
index bcafa1b8b93dfc65a2e616e99efcbd64a4936e25..1257d4eb030ea00a049e2e4916d0b6471f7d353f 100644 (file)
@@ -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 )
index 5f3da6c39cd7612161202c863dd418470c6df002..baa7c843761f658301a70c61658d2422b77fee9d 100644 (file)
@@ -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