Commit 8c341408 authored by Hannes Domani's avatar Hannes Domani Committed by Jean-Baptiste Kempf

lua: reactivate vlclua_net_poll() on windows

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
(cherry picked from commit a916d7be15713e577eacb88a18e6e6990e5213d2)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent b7740617
......@@ -312,7 +312,6 @@ static int vlclua_net_recv( lua_State *L )
return 1;
}
#ifndef _WIN32
/*****************************************************************************
*
*****************************************************************************/
......@@ -380,6 +379,7 @@ static int vlclua_fd_open( lua_State *L )
}
*/
#ifndef _WIN32
static int vlclua_fd_write( lua_State *L )
{
int fd = vlclua_fd_get( L, luaL_checkint( L, 1 ) );
......@@ -492,8 +492,8 @@ static const luaL_Reg vlclua_net_intf_reg[] = {
{ "close", vlclua_net_close },
{ "send", vlclua_net_send },
{ "recv", vlclua_net_recv },
#ifndef _WIN32
{ "poll", vlclua_net_poll },
#ifndef _WIN32
{ "read", vlclua_fd_read },
{ "write", vlclua_fd_write },
#endif
......@@ -521,11 +521,40 @@ static void luaopen_net_intf( lua_State *L )
lua_setfield( L, -2, "net" );
}
#ifdef _WIN32
static int vlc_socket_pair( int fds[2] )
{
struct sockaddr_in inaddr;
struct sockaddr addr;
SOCKET lst = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
memset( &inaddr, 0, sizeof( inaddr ) );
memset( &addr, 0, sizeof( addr ) );
inaddr.sin_family = AF_INET;
inaddr.sin_addr.s_addr = htonl( INADDR_LOOPBACK );
inaddr.sin_port = 0;
int yes = 1;
setsockopt( lst, SOL_SOCKET, SO_REUSEADDR, (char*)&yes, sizeof( yes ) );
bind( lst, (struct sockaddr *)&inaddr, sizeof( inaddr ) );
listen( lst, 1 );
int len = sizeof( inaddr );
getsockname( lst, &addr, &len );
fds[0] = socket( AF_INET, SOCK_STREAM, 0 );
connect( fds[0], &addr, len );
fds[1] = accept( lst, 0, 0 );
closesocket( lst );
return 0;
}
#endif
int vlclua_fd_init( lua_State *L, vlclua_dtable_t *dt )
{
#ifndef _WIN32
if( vlc_pipe( dt->fd ) )
return -1;
#else
if( vlc_socket_pair( dt->fd ) )
return -1;
#endif
dt->fdv = NULL;
dt->fdc = 0;
......@@ -539,6 +568,9 @@ void vlclua_fd_interrupt( vlclua_dtable_t *dt )
#ifndef _WIN32
close( dt->fd[1] );
dt->fd[1] = -1;
#else
closesocket( dt->fd[0] );
dt->fd[0] = -1;
#endif
}
......@@ -553,5 +585,8 @@ void vlclua_fd_cleanup( vlclua_dtable_t *dt )
if( dt->fd[1] != -1 )
close( dt->fd[1] );
close( dt->fd[0] );
#else
if( dt->fd[0] != -1 )
closesocket( dt->fd[0] );
#endif
}
......@@ -171,9 +171,7 @@ typedef struct
{
int *fdv;
unsigned fdc;
#ifndef _WIN32
int fd[2];
#endif
} vlclua_dtable_t;
int vlclua_fd_init( lua_State *, vlclua_dtable_t * );
......
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