]> git.sesse.net Git - vlc/commitdiff
* Fixed the vlcs communication issue by initializing WinSock at
authorSam Hocevar <sam@videolan.org>
Mon, 12 Nov 2001 22:42:56 +0000 (22:42 +0000)
committerSam Hocevar <sam@videolan.org>
Mon, 12 Nov 2001 22:42:56 +0000 (22:42 +0000)
    startup (thanks Meuuh for the tip).

Makefile
include/win32_specific.h [new file with mode: 0644]
src/input/input.c
src/interface/main.c
src/misc/netutils.c
src/misc/win32_specific.c [new file with mode: 0644]

index b2ccf4831cb3d2ec509f97cb0ce42054f51f411d..857d5f72a2adfd13f450c5df5f7f3b1fcb514e7b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -133,6 +133,7 @@ C_OBJ +=    src/misc/darwin_specific.o
 endif
 
 ifneq (,$(findstring mingw32,$(SYS)))
+C_OBJ +=       src/misc/win32_specific.o
 RESOURCE_OBJ :=        share/vlc_win32_rc.o
 endif
 
diff --git a/include/win32_specific.h b/include/win32_specific.h
new file mode 100644 (file)
index 0000000..c6ccb6a
--- /dev/null
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * win32_specific.h: Win32 specific features 
+ *****************************************************************************
+ * Copyright (C) 2001 VideoLAN
+ * $Id: win32_specific.h,v 1.1 2001/11/12 22:42:56 sam Exp $
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Prototypes
+ *****************************************************************************/
+void    system_Init ( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] );
+void    system_End  ( void );
+
index 867f61a8ad8ac81ccc2dea0ec9c9b9464b16090a..8c9ceabbcd8f82424a3b6b382acce17fca16ec35 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: input.c,v 1.153 2001/11/12 04:12:37 sam Exp $
+ * $Id: input.c,v 1.154 2001/11/12 22:42:56 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -52,7 +52,9 @@
 #   include <netdb.h>                                         /* hostent ... */
 #   include <sys/socket.h>
 #   include <netinet/in.h>
-#   include <arpa/inet.h>
+#   ifdef HAVE_ARPA_INET_H
+#       include <arpa/inet.h>                    /* inet_ntoa(), inet_aton() */
+#   endif
 #endif
 
 #ifdef HAVE_SYS_TIMES_H
@@ -728,22 +730,6 @@ static void NetworkOpen( input_thread_t * p_input )
     struct sockaddr_in  sock;
     unsigned int        i_mc_group;
 
-#ifdef WIN32
-    WSADATA Data;
-    int i_err;
-#endif
-    
-#ifdef WIN32
-    /* WinSock Library Init. */
-    i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
-
-    if( i_err )
-    {
-        intf_ErrMsg( "input: can't initiate WinSocks, error %i", i_err );
-        return ;
-    }
-#endif
-    
     /* Get the remote server */
     if( p_input->p_source != NULL )
     {
@@ -993,10 +979,6 @@ static void NetworkClose( input_thread_t * p_input )
     intf_WarnMsg( 2, "input: closing network target `%s'", p_input->p_source );
 
     close( p_input->i_handle );
-
-#ifdef WIN32 
-    WSACleanup();
-#endif
 }
 
 /*****************************************************************************
@@ -1012,22 +994,6 @@ static void HTTPOpen( input_thread_t * p_input )
     struct sockaddr_in  sock;
     char                psz_buffer[256];
 
-#ifdef WIN32
-    WSADATA Data;
-    int i_err;
-#endif
-    
-#ifdef WIN32
-    /* WinSock Library Init. */
-    i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
-
-    if( i_err )
-    {
-        intf_ErrMsg( "input: can't initiate WinSocks, error %i", i_err );
-        return ;
-    }
-#endif
-    
     /* Get the remote server */
     if( p_input->p_source != NULL )
     {
index da8a13d11245821660b85cc91761247da9fbe437..004aed3e01822157e25f92463c20a2a9b591b66a 100644 (file)
@@ -4,7 +4,7 @@
  * and spawn threads.
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: main.c,v 1.123 2001/11/12 20:16:33 sam Exp $
+ * $Id: main.c,v 1.124 2001/11/12 22:42:56 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
 #   include "darwin_specific.h"
 #endif
 
+#ifdef WIN32
+#   include "win32_specific.h"
+#endif
+
 #include "netutils.h"                                 /* network_ChannelJoin */
 
 #include "main.h"
@@ -288,7 +292,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
     /*
      * System specific initialization code
      */
-#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
     system_Init( &i_argc, ppsz_argv, ppsz_env );
 
 #elif defined( WIN32 )
@@ -440,7 +444,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
     /*
      * System specific cleaning code
      */
-#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
     system_End();
 #endif
 
index 2ccbff06213968e8e4c1dd6e1a10d141f212fd6f..5b1281e5a9d702a9baabe9429e0d1897b0ecac58 100644 (file)
@@ -2,7 +2,7 @@
  * netutils.c: various network functions
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: netutils.c,v 1.42 2001/11/12 20:16:33 sam Exp $
+ * $Id: netutils.c,v 1.43 2001/11/12 22:42:56 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Benoit Steiner <benny@via.ecp.fr>
 #endif
 
 #ifdef HAVE_UNISTD_H
-#include <unistd.h>                                         /* gethostname() */
+#   include <unistd.h>                                      /* gethostname() */
 #elif defined( _MSC_VER ) && defined( _WIN32 )
-#include <io.h>
+#   include <io.h>
 #endif
 
 #if !defined( _MSC_VER )
 #include <sys/time.h>                                        /* gettimeofday */
 #endif
 
-#if !defined( WIN32 )
-#include <netdb.h>                                        /* gethostbyname() */
-#include <netinet/in.h>                               /* BSD: struct in_addr */
-#include <sys/socket.h>                              /* BSD: struct sockaddr */
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>                           /* inet_ntoa(), inet_aton() */
+#ifdef WIN32
+#   include <winsock2.h>
+#elif !defined( SYS_BEOS ) && !defined( SYS_NTO )
+#   include <netdb.h>                                         /* hostent ... */
+#   include <sys/socket.h>                           /* BSD: struct sockaddr */
+#   include <netinet/in.h>                            /* BSD: struct in_addr */
+#   ifdef HAVE_ARPA_INET_H
+#       include <arpa/inet.h>                    /* inet_ntoa(), inet_aton() */
+#   endif
 #endif
 
 #ifdef SYS_LINUX
@@ -287,6 +288,12 @@ int network_ChannelJoin( int i_channel )
 
     /* Initializing the socket */
     i_fd = socket( AF_INET, SOCK_DGRAM, 0 );
+    if( i_fd < 0 )
+    {
+        intf_ErrMsg( "network error: unable to create vlcs socket (%s)",
+                     strerror( errno ) );
+        return -1;
+    }
 
     /* Getting information about the channel server */
     psz_vlcs = main_GetPszVariable( INPUT_CHANNEL_SERVER_VAR,
@@ -294,7 +301,8 @@ int network_ChannelJoin( int i_channel )
     i_port = main_GetIntVariable( INPUT_CHANNEL_PORT_VAR,
                                   INPUT_CHANNEL_PORT_DEFAULT );
 
-    intf_WarnMsg( 6, "network: vlcs '%s', port %d", psz_vlcs, i_port );
+    intf_WarnMsg( 5, "network: socket %i, vlcs '%s', port %d",
+                     i_fd, psz_vlcs, i_port );
 
     memset( &sa_client, 0x00, sizeof(struct sockaddr_in) );
     memset( &sa_server, 0x00, sizeof(struct sockaddr_in) );
@@ -310,11 +318,11 @@ int network_ChannelJoin( int i_channel )
 #endif
 
     /* Bind the socket */
-    i_dummy = bind( i_fd, (struct sockaddr *)(&sa_client),
-                          sizeof(struct sockaddr) );
-    if ( i_dummy )
+    if( bind( i_fd, (struct sockaddr*)(&sa_client), sizeof(sa_client) ) )
     {
-        intf_ErrMsg( "network: unable to bind vlcs socket: %i", i_dummy );
+        intf_ErrMsg( "network: unable to bind vlcs socket (%s)",
+                     strerror( errno ) );
+        close( i_fd );
         return -1;
     }
 
@@ -322,6 +330,7 @@ int network_ChannelJoin( int i_channel )
     if( GetMacAddress( i_fd, psz_mac ) )
     {
         intf_ErrMsg( "network error: failed getting MAC address" );
+        close( i_fd );
         return -1;
     }
 
@@ -347,9 +356,8 @@ int network_ChannelJoin( int i_channel )
     delay.tv_usec = 0;
     FD_ZERO( &fds );
     FD_SET( i_fd, &fds );
-    i_dummy = select( i_fd + 1, &fds, NULL, NULL, &delay );
 
-    switch( i_dummy )
+    switch( select( i_fd + 1, &fds, NULL, NULL, &delay ) )
     {
         case 0:
             intf_ErrMsg( "network error: no answer from vlcs" );
@@ -396,7 +404,7 @@ int network_ChannelJoin( int i_channel )
 
 #else
     intf_ErrMsg( "network error: channels not supported on this platform" );
-    return NULL;
+    return -1; 
 
 #endif
 }
diff --git a/src/misc/win32_specific.c b/src/misc/win32_specific.c
new file mode 100644 (file)
index 0000000..0142158
--- /dev/null
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * win32_specific.c: Win32 specific features 
+ *****************************************************************************
+ * Copyright (C) 2001 VideoLAN
+ * $Id: win32_specific.c,v 1.1 2001/11/12 22:42:56 sam Exp $
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include "defs.h"
+
+#include <string.h>                                              /* strdup() */
+#include <stdlib.h>                                                /* free() */
+
+#include <winsock2.h>
+
+#include "common.h"
+#include "threads.h"
+#include "mtime.h"
+
+#include "win32_specific.h"
+
+/*****************************************************************************
+ * system_Init: initialize winsock.
+ *****************************************************************************/
+void system_Init( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
+{
+    WSADATA Data;
+    int i_err;
+
+    /* WinSock Library Init. */
+    i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
+
+    if( i_err )
+    {
+        fprintf( stderr, "error: can't initiate WinSocks, error %i", i_err );
+    }
+}
+
+/*****************************************************************************
+ * system_End: terminate winsock.
+ *****************************************************************************/
+void system_End( void )
+{
+    WSACleanup();
+}
+