[vlc-commits] Lua: net.send() fixes
Rémi Denis-Courmont
git at videolan.org
Thu Jun 20 18:39:43 CEST 2013
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun 20 19:37:48 2013 +0300| [d7afc0c8e153a5af59018bfbad1e58796ff36f26] | committer: Rémi Denis-Courmont
Lua: net.send() fixes
- Deal with network errors.
- Do not drop bytes in case of congestion (non-blockig mode...).
- Abort immediately if VLC is terminating.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d7afc0c8e153a5af59018bfbad1e58796ff36f26
---
modules/lua/libs/net.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/modules/lua/libs/net.c b/modules/lua/libs/net.c
index 0f6b393..9e99ed0 100644
--- a/modules/lua/libs/net.c
+++ b/modules/lua/libs/net.c
@@ -167,12 +167,34 @@ static int vlclua_net_close( lua_State *L )
static int vlclua_net_send( lua_State *L )
{
+ intf_thread_t *intf = (intf_thread_t *)vlclua_get_this( L );
+ intf_sys_t *sys = intf->p_sys;
+
int i_fd = luaL_checkint( L, 1 );
- size_t i_len;
- const char *psz_buffer = luaL_checklstring( L, 2, &i_len );
- i_len = luaL_optint( L, 3, i_len );
- i_len = send( i_fd, psz_buffer, i_len, 0 );
- lua_pushinteger( L, i_len );
+ size_t size, len = 0;
+ const char *psz_buffer = luaL_checklstring( L, 2, &size );
+ size = luaL_optint( L, 3, size );
+
+ struct pollfd ufd[2];
+ ufd[0].fd = sys->fd[0];
+ ufd[0].events = POLLIN;
+ ufd[1].fd = i_fd;
+ ufd[1].events = POLLOUT;
+
+ while( len < size )
+ {
+ while( poll( ufd, 2, -1 ) == -1 && errno == EINTR );
+
+ if( ufd[0].revents )
+ return luaL_error( L, "Interrupted." );
+
+ ssize_t val = send( i_fd, psz_buffer + len, size - len, 0 );
+ if( val <= 0 )
+ break;
+ len += val;
+ }
+
+ lua_pushinteger( L, len );
return 1;
}
More information about the vlc-commits
mailing list