From: Antoine Cellerier Date: Sat, 9 Jan 2010 10:41:09 +0000 (+0100) Subject: Remove timeout parameter from lua listner:accept(). X-Git-Tag: 1.1.0-ff~1334 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=5f5d77942050184425bee5a60433a08a402b192e;p=vlc Remove timeout parameter from lua listner:accept(). --- diff --git a/modules/misc/lua/libs/net.c b/modules/misc/lua/libs/net.c index 17d8912dfa..f577211e98 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 bcafa1b8b9..1257d4eb03 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 5f3da6c39c..baa7c84376 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