[vlc-commits] LUA: hide EINTR from scripts and remove the timeout feature
Rémi Denis-Courmont
git at videolan.org
Sun Jan 23 16:49:22 CET 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jan 23 17:40:50 2011 +0200| [314c242ab041d515c1b2f1a82ee1a3fe4fe715a5] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=314c242ab041d515c1b2f1a82ee1a3fe4fe715a5
---
modules/misc/lua/libs/net.c | 7 +++++--
share/lua/README.txt | 2 +-
share/lua/intf/modules/host.lua | 2 +-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/modules/misc/lua/libs/net.c b/modules/misc/lua/libs/net.c
index ea635ee..c4696b3 100644
--- a/modules/misc/lua/libs/net.c
+++ b/modules/misc/lua/libs/net.c
@@ -201,7 +201,6 @@ static int vlclua_net_recv( lua_State *L )
static int vlclua_net_poll( lua_State *L )
{
luaL_checktype( L, 1, LUA_TTABLE );
- double f_timeout = luaL_optnumber( L, 2, -1. );
int i_fds = 0;
lua_pushnil( L );
@@ -223,7 +222,11 @@ static int vlclua_net_poll( lua_State *L )
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++ )
{
lua_pushinteger( L, p_fds[i].fd );
diff --git a/share/lua/README.txt b/share/lua/README.txt
index edc917a..3fa5cdb 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -199,7 +199,7 @@ net.connect_tcp( host, port ): open a connection to the given host:port (TCP).
net.close( fd ): Close file descriptor.
net.send( fd, string, [length] ): Send data on 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
modifies the input table to { fd = revents }. See "man poll".
net.POLLIN/POLLPRI/POLLOUT/POLLRDHUP/POLLERR/POLLHUP/POLLNVAL: poll event flags
diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua
index 65eb993..7d0c404 100644
--- a/share/lua/intf/modules/host.lua
+++ b/share/lua/intf/modules/host.lua
@@ -244,7 +244,7 @@ function host()
end
end
- local ret = vlc.net.poll( pollfds, timeout or -1 )
+ local ret = vlc.net.poll( pollfds )
local wclients = {}
local rclients = {}
if ret > 0 then
More information about the vlc-commits
mailing list