Commit 5f5d7794 authored by Antoine Cellerier's avatar Antoine Cellerier

Remove timeout parameter from lua listner:accept().

parent 7ef39293
......@@ -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;
......
......@@ -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 )
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment