From: Sam Hocevar Date: Mon, 12 Nov 2001 22:42:56 +0000 (+0000) Subject: * Fixed the vlcs communication issue by initializing WinSock at X-Git-Tag: 0.2.91~3 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=cdf126129d9ea4f4842d7837439fb0cea517692b;p=vlc * Fixed the vlcs communication issue by initializing WinSock at startup (thanks Meuuh for the tip). --- diff --git a/Makefile b/Makefile index b2ccf4831c..857d5f72a2 100644 --- 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 index 0000000000..c6ccb6a64f --- /dev/null +++ b/include/win32_specific.h @@ -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 + * + * 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 ); + diff --git a/src/input/input.c b/src/input/input.c index 867f61a8ad..8c9ceabbcd 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -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 * @@ -52,7 +52,9 @@ # include /* hostent ... */ # include # include -# include +# ifdef HAVE_ARPA_INET_H +# include /* 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 ) { diff --git a/src/interface/main.c b/src/interface/main.c index da8a13d112..004aed3e01 100644 --- a/src/interface/main.c +++ b/src/interface/main.c @@ -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 * Samuel Hocevar @@ -92,6 +92,10 @@ # 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 diff --git a/src/misc/netutils.c b/src/misc/netutils.c index 2ccbff0621..5b1281e5a9 100644 --- a/src/misc/netutils.c +++ b/src/misc/netutils.c @@ -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 * Benoit Steiner @@ -38,23 +38,24 @@ #endif #ifdef HAVE_UNISTD_H -#include /* gethostname() */ +# include /* gethostname() */ #elif defined( _MSC_VER ) && defined( _WIN32 ) -#include +# include #endif #if !defined( _MSC_VER ) #include /* gettimeofday */ #endif -#if !defined( WIN32 ) -#include /* gethostbyname() */ -#include /* BSD: struct in_addr */ -#include /* BSD: struct sockaddr */ -#endif - -#ifdef HAVE_ARPA_INET_H -#include /* inet_ntoa(), inet_aton() */ +#ifdef WIN32 +# include +#elif !defined( SYS_BEOS ) && !defined( SYS_NTO ) +# include /* hostent ... */ +# include /* BSD: struct sockaddr */ +# include /* BSD: struct in_addr */ +# ifdef HAVE_ARPA_INET_H +# include /* 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 index 0000000000..01421585fc --- /dev/null +++ b/src/misc/win32_specific.c @@ -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 + * + * 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 /* strdup() */ +#include /* free() */ + +#include + +#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(); +} +