Commit 9b65c09f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

LUA: hide EINTR from scripts and remove the timeout feature

Timeout makes it too easy to write crappy code.
It's also much easier to handle EINTR without timeout.

This fixes a minor bug: revents was undefined if poll() failed.
(cherry picked from commit 314c242ab041d515c1b2f1a82ee1a3fe4fe715a5)
parent c2b8728e
...@@ -196,7 +196,6 @@ static int vlclua_net_recv( lua_State *L ) ...@@ -196,7 +196,6 @@ static int vlclua_net_recv( lua_State *L )
static int vlclua_net_poll( lua_State *L ) static int vlclua_net_poll( lua_State *L )
{ {
luaL_checktype( L, 1, LUA_TTABLE ); luaL_checktype( L, 1, LUA_TTABLE );
double f_timeout = luaL_optnumber( L, 2, -1. );
int i_fds = 0; int i_fds = 0;
lua_pushnil( L ); lua_pushnil( L );
...@@ -218,7 +217,11 @@ static int vlclua_net_poll( lua_State *L ) ...@@ -218,7 +217,11 @@ static int vlclua_net_poll( lua_State *L )
i++; i++;
} }
int i_ret = poll( p_fds, i_fds, f_timeout < 0. ? -1 : (int)(f_timeout*1000) ); int i_ret;
do
i_ret = poll( p_fds, i_fds, -1 );
while( i_ret == -1 );
for( i = 0; i < i_fds; i++ ) for( i = 0; i < i_fds; i++ )
{ {
lua_pushinteger( L, p_fds[i].fd ); lua_pushinteger( L, p_fds[i].fd );
......
...@@ -195,7 +195,7 @@ net.connect_tcp( host, port ): open a connection to the given host:port (TCP). ...@@ -195,7 +195,7 @@ net.connect_tcp( host, port ): open a connection to the given host:port (TCP).
net.close( fd ): Close file descriptor. net.close( fd ): Close file descriptor.
net.send( fd, string, [length] ): Send data on fd. net.send( fd, string, [length] ): Send data on fd.
net.recv( fd, [max length] ): Receive data from fd. net.recv( fd, [max length] ): Receive data from fd.
net.poll( { fd = events }, [timeout in seconds] ): Implement poll function. net.poll( { fd = events } ): Implement poll function.
Returns the numbers of file descriptors with a non 0 revent. The function Returns the numbers of file descriptors with a non 0 revent. The function
modifies the input table to { fd = revents }. See "man poll". modifies the input table to { fd = revents }. See "man poll".
net.POLLIN/POLLPRI/POLLOUT/POLLRDHUP/POLLERR/POLLHUP/POLLNVAL: poll event flags net.POLLIN/POLLPRI/POLLOUT/POLLRDHUP/POLLERR/POLLHUP/POLLNVAL: poll event flags
......
...@@ -244,7 +244,7 @@ function host() ...@@ -244,7 +244,7 @@ function host()
end end
end end
local ret = vlc.net.poll( pollfds, timeout or -1 ) local ret = vlc.net.poll( pollfds )
local wclients = {} local wclients = {}
local rclients = {} local rclients = {}
if ret > 0 then if ret > 0 then
......
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