]> git.sesse.net Git - vlc/commitdiff
lua: reactivate vlclua_net_poll() on windows
authorHannes Domani <ssbssa@yahoo.de>
Sun, 17 Aug 2014 12:38:54 +0000 (14:38 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 25 Aug 2014 21:25:17 +0000 (23:25 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/lua/libs/net.c
modules/lua/vlc.h

index 913db5b999b0700c89b95c35038dd9b03bf96841..4d6e87b3da939a112f97e879446c38ff2b556487 100644 (file)
@@ -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
 }
index be8b0eee5d2d4f28a60b9028b9818995a9792039..efd94f164bd6340166d822d6724040d5244cbdad 100644 (file)
@@ -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 * );