From 19c6d9d2bcbc660d62ba7d6c616ec75309fdf809 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Tue, 1 Mar 2011 21:26:07 +0000 Subject: [PATCH] Fix for win32 sockets. --- .../wrapper/VST/juce_VST_Wrapper.cpp | 4 ++-- juce_amalgamated.cpp | 18 +++++++++++------- src/io/network/juce_Socket.cpp | 17 ++++++++++------- src/native/windows/juce_win32_NativeIncludes.h | 1 + 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp index 4eda300bd9..6dc9624402 100644 --- a/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp +++ b/extras/audio plugins/wrapper/VST/juce_VST_Wrapper.cpp @@ -307,8 +307,8 @@ public: speakerOut (kSpeakerArrEmpty), numInChans (JucePlugin_MaxNumInputChannels), numOutChans (JucePlugin_MaxNumOutputChannels), - isProcessing (false) - hasShutdown (false) + isProcessing (false), + hasShutdown (false), firstProcessCallback (true), shouldDeleteEditor (false), hostWindow (0) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 5cd0c7d047..d768d87168 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -519,6 +519,7 @@ #include #include #include +#include #include #include #include @@ -9187,34 +9188,37 @@ namespace SocketHelpers zerostruct (hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = isDatagram ? SOCK_DGRAM : SOCK_STREAM; + hints.ai_flags = AI_NUMERICSERV; - struct addrinfo* result = 0; - if (getaddrinfo (hostName.toUTF8(), 0, &hints, &result) != 0 || result == 0) + struct addrinfo* info = 0; + if (getaddrinfo (hostName.toUTF8(), String (portNumber).toUTF8(), &hints, &info) != 0 || info == 0) return false; if (handle < 0) - handle = (int) socket (result->ai_family, result->ai_socktype, 0); + handle = (int) socket (info->ai_family, info->ai_socktype, 0); if (handle < 0) { - freeaddrinfo (result); + freeaddrinfo (info); return false; } if (isDatagram) { struct sockaddr* s = new struct sockaddr(); - *s = *(result->ai_addr); + *s = *(info->ai_addr); *serverAddress = s; - freeaddrinfo (result); + freeaddrinfo (info); return true; } - freeaddrinfo (result); + freeaddrinfo (info); setSocketBlockingState (handle, false); + const int result = ::connect (handle, info->ai_addr, info->ai_addrlen); + if (result < 0) { #if JUCE_WINDOWS diff --git a/src/io/network/juce_Socket.cpp b/src/io/network/juce_Socket.cpp index ca56a953bf..0c61986b0d 100644 --- a/src/io/network/juce_Socket.cpp +++ b/src/io/network/juce_Socket.cpp @@ -258,34 +258,37 @@ namespace SocketHelpers zerostruct (hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = isDatagram ? SOCK_DGRAM : SOCK_STREAM; + hints.ai_flags = AI_NUMERICSERV; - struct addrinfo* result = 0; - if (getaddrinfo (hostName.toUTF8(), 0, &hints, &result) != 0 || result == 0) + struct addrinfo* info = 0; + if (getaddrinfo (hostName.toUTF8(), String (portNumber).toUTF8(), &hints, &info) != 0 || info == 0) return false; if (handle < 0) - handle = (int) socket (result->ai_family, result->ai_socktype, 0); + handle = (int) socket (info->ai_family, info->ai_socktype, 0); if (handle < 0) { - freeaddrinfo (result); + freeaddrinfo (info); return false; } if (isDatagram) { struct sockaddr* s = new struct sockaddr(); - *s = *(result->ai_addr); + *s = *(info->ai_addr); *serverAddress = s; - freeaddrinfo (result); + freeaddrinfo (info); return true; } - freeaddrinfo (result); + freeaddrinfo (info); setSocketBlockingState (handle, false); + const int result = ::connect (handle, info->ai_addr, info->ai_addrlen); + if (result < 0) { #if JUCE_WINDOWS diff --git a/src/native/windows/juce_win32_NativeIncludes.h b/src/native/windows/juce_win32_NativeIncludes.h index 697b2ad9f7..b86489f64d 100644 --- a/src/native/windows/juce_win32_NativeIncludes.h +++ b/src/native/windows/juce_win32_NativeIncludes.h @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include