[vlc-commits] lua: reactivate vlclua_net_poll() on windows

Hannes Domani git at videolan.org
Mon Aug 25 23:53:41 CEST 2014


vlc | branch: master | Hannes Domani <ssbssa at yahoo.de> | Sun Aug 17 14:38:54 2014 +0200| [a916d7be15713e577eacb88a18e6e6990e5213d2] | committer: Jean-Baptiste Kempf

lua: reactivate vlclua_net_poll() on windows

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a916d7be15713e577eacb88a18e6e6990e5213d2
---

 modules/lua/libs/net.c |   39 +++++++++++++++++++++++++++++++++++++--
 modules/lua/vlc.h      |    2 --
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/modules/lua/libs/net.c b/modules/lua/libs/net.c
index 913db5b..4d6e87b 100644
--- a/modules/lua/libs/net.c
+++ b/modules/lua/libs/net.c
@@ -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
 }
diff --git a/modules/lua/vlc.h b/modules/lua/vlc.h
index be8b0ee..efd94f1 100644
--- a/modules/lua/vlc.h
+++ b/modules/lua/vlc.h
@@ -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 * );



More information about the vlc-commits mailing list