Changes for mingw32 compatibility. Gave up using GetAddrInfoW. getaddrinfo is dynamically bound, gethostbyname is used if it is not available.

VC compilation is broken.

Make sure to use the dynamic boost-thread lib with mingw, as thread specific pointers are used!
This commit is contained in:
lotodore
2007-09-01 14:04:41 +00:00
parent 26397dee94
commit 1f6a10e2d1
9 changed files with 100 additions and 99 deletions
+11 -6
View File
@@ -209,15 +209,20 @@ TRANSLATIONS = \
win32{ win32{
DEPENDPATH += src/net/win32/ src/core/win32 DEPENDPATH += src/net/win32/ src/core/win32
INCLUDEPATH += ../boost/ ../SDL/include ../SDL_mixer INCLUDEPATH += ../boost/ ../SDL/include ../SDL_mixer
INCLUDEPATH += ../SDL/include/SDL ../SDL_mixer/include
LIBPATH += ../boost/stage/lib LIBPATH += ../boost/stage/lib
debug {
LIBPATH += Debug/lib ../SDL/VisualC/SDL/Debug ../SDL/VisualC/SDLmain/Debug ../SDL_mixer/VisualC/Debug release {
}
!debug {
LIBPATH += Release/lib ../SDL/VisualC/SDL/Release ../SDL/VisualC/SDLmain/Release ../SDL_mixer/VisualC/Release LIBPATH += Release/lib ../SDL/VisualC/SDL/Release ../SDL/VisualC/SDLmain/Release ../SDL_mixer/VisualC/Release
} }
LIBS += pokerth_lib.lib !release {
LIBS += gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ole32.lib uuid.lib user32.lib msimg32.lib shell32.lib kernel32.lib ws2_32.lib advapi32.lib sdl.lib sdlmain.lib sdl_mixer.lib LIBPATH += Debug/lib ../SDL/VisualC/SDL/Debug ../SDL/VisualC/SDLmain/Debug ../SDL_mixer/VisualC/Debug
}
LIBPATH += ../SDL/lib ../SDL_mixer/lib
LIBS += -lpokerth_lib
LIBS += -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lole32 -luuid -luser32 -lmsimg32 -lshell32 -lkernel32 -lws2_32 -ladvapi32 -lsdl -lsdlmain -lsdl_mixer
LIBS += -lboost_thread-mgw34-mt-1_34_1
RC_FILE = pokerth.rc RC_FILE = pokerth.rc
} }
!win32{ !win32{
+9 -6
View File
@@ -96,14 +96,17 @@ win32{
DEPENDPATH += src/net/win32/ src/core/win32 DEPENDPATH += src/net/win32/ src/core/win32
INCLUDEPATH += ../boost/ INCLUDEPATH += ../boost/
LIBPATH += ../boost/stage/lib LIBPATH += ../boost/stage/lib
debug {
LIBPATH += Debug/lib release {
}
!debug {
LIBPATH += Release/lib LIBPATH += Release/lib
} }
LIBS += pokerth_lib.lib !release {
LIBS += gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ole32.lib uuid.lib user32.lib msimg32.lib shell32.lib kernel32.lib ws2_32.lib advapi32.lib LIBPATH += Debug/lib
}
LIBS += -lpokerth_lib
LIBS += -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lole32 -luuid -luser32 -lmsimg32 -lshell32 -lkernel32 -lws2_32 -ladvapi32
LIBS += -lboost_thread-mgw34-mt-1_34_1
} }
!win32{ !win32{
DEPENDPATH += src/net/linux/ src/core/linux DEPENDPATH += src/net/linux/ src/core/linux
+14 -4
View File
@@ -11,6 +11,16 @@
// //
#include "sdlplayer.h" #include "sdlplayer.h"
// Include SDL here and not in headers to prevent
// conflicts with QT includes.
#if (defined _WIN32) || (defined __APPLE__)
#include <SDL.h>
#include <SDL_mixer.h>
#else
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#endif
#include <iostream> #include <iostream>
using namespace std; using namespace std;
@@ -35,10 +45,10 @@ void SDLPlayer::initAudio() {
if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects"))
{ {
audio_rate = 44100; int audio_rate = 44100;
audio_format = AUDIO_S16; /* 16-bit stereo */ Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
audio_channels = 2; int audio_channels = 2;
audio_buffers = 4096; int audio_buffers = 4096;
sound = NULL; sound = NULL;
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) { if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) {
+3 -18
View File
@@ -14,23 +14,12 @@
#ifndef SDLPLAYER_H #ifndef SDLPLAYER_H
#define SDLPLAYER_H #define SDLPLAYER_H
#ifdef _WIN32
#include <SDL.h>
#include <SDL_mixer.h>
#else
#ifdef __APPLE__
#include <SDL.h>
#include <SDL_mixer.h>
#else
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#endif
#endif
#include <string> #include <string>
#include "configfile.h" #include "configfile.h"
#include "qthelper.h" #include "qthelper.h"
struct Mix_Chunk;
/** /**
@author FThauer FHammer <webmaster@pokerth.net> @author FThauer FHammer <webmaster@pokerth.net>
*/ */
@@ -49,12 +38,8 @@ public:
private: private:
int audio_rate;
Uint16 audio_format;
int audio_channels;
int audio_buffers;
Mix_Chunk *sound; Mix_Chunk *sound;
Uint8 *soundData; unsigned char *soundData;
int currentChannel; int currentChannel;
bool audioEnabled; bool audioEnabled;
-32
View File
@@ -44,35 +44,3 @@ socket_set_port(unsigned port, int addrFamily, struct sockaddr *addr, int addrLe
return retVal; return retVal;
} }
bool
internal_socket_resolve(const char *str, const char *port, int addrFamily, int sockType, int protocol, struct sockaddr *addr, int addrLen)
{
bool retVal = false;
if (str && *str != 0)
{
struct addrinfo aiHints;
struct addrinfo *aiList = NULL;
memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = addrFamily;
aiHints.ai_socktype = sockType;
aiHints.ai_protocol = protocol;
// Try to resolve the name.
// Will (hopefully) use UTF-8 if called on Linux.
bool success = (getaddrinfo(str, port, &aiHints, &aiList) == 0);
if (success && aiList)
{
if ((int)aiList->ai_addrlen <= addrLen)
{
memcpy(addr, aiList->ai_addr, aiList->ai_addrlen);
retVal = true;
}
freeaddrinfo(aiList);
}
}
return retVal;
}
-1
View File
@@ -23,7 +23,6 @@
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <wspiapi.h>
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
+27 -1
View File
@@ -37,6 +37,32 @@ socket_string_to_addr(const char *str, int addrFamily, struct sockaddr * addr, i
bool bool
socket_resolve(const char *str, const char *port, int addrFamily, int sockType, int protocol, struct sockaddr *addr, int addrLen) socket_resolve(const char *str, const char *port, int addrFamily, int sockType, int protocol, struct sockaddr *addr, int addrLen)
{ {
return internal_socket_resolve(str, port, addrFamily, sockType, protocol, addr, addrLen); bool retVal = false;
if (str && *str != 0)
{
struct addrinfo aiHints;
struct addrinfo *aiList = NULL;
memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = addrFamily;
aiHints.ai_socktype = sockType;
aiHints.ai_protocol = protocol;
// Try to resolve the name.
// Will (hopefully) use UTF-8 if called on Linux.
bool success = (getaddrinfo(str, port, &aiHints, &aiList) == 0);
if (success && aiList)
{
if ((int)aiList->ai_addrlen <= addrLen)
{
memcpy(addr, aiList->ai_addr, aiList->ai_addrlen);
retVal = true;
}
freeaddrinfo(aiList);
}
}
return retVal;
} }
+11 -9
View File
@@ -35,10 +35,17 @@
#define SOCKET_ERR_NOTCONN WSAENOTCONN #define SOCKET_ERR_NOTCONN WSAENOTCONN
#define SOCKET_ERR_NOTSOCK WSAENOTSOCK #define SOCKET_ERR_NOTSOCK WSAENOTSOCK
typedef unsigned __int16 u_int16_t; #ifdef __GNUC__ /* mingw provides stdint.h */
typedef unsigned __int32 u_int32_t; #include <stdint.h>
typedef __int16 int16_t; typedef uint16_t u_int16_t;
typedef __int32 int32_t; typedef uint32_t u_int32_t;
#else
typedef unsigned __int16 u_int16_t;
typedef unsigned __int32 u_int32_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
#endif
typedef unsigned char u_char; typedef unsigned char u_char;
#else #else
@@ -87,10 +94,5 @@ bool socket_resolve(const char *str, const char *port, int addrFamily, int sockT
*/ */
bool socket_set_port(unsigned port, int addrFamily, struct sockaddr *addr, int addrLen); bool socket_set_port(unsigned port, int addrFamily, struct sockaddr *addr, int addrLen);
/**
* Internal function (common for all OSs).
*/
bool internal_socket_resolve(const char *str, const char *port, int addrFamily, int sockType, int protocol, struct sockaddr *addr, int addrLen);
#endif #endif
+25 -22
View File
@@ -28,9 +28,8 @@
using namespace std; using namespace std;
typedef int (WSAAPI * getaddrinfow_ptr_t)(const wchar_t *nodename, const wchar_t* servname, typedef int (WSAAPI * getaddrinfo_ptr_t) (const char *, const char* , const struct addrinfo *, struct addrinfo **);
const ADDRINFOW *hints, PADDRINFOW *res); typedef void (WSAAPI * freeaddrinfo_ptr_t) (struct addrinfo*);
typedef void (WSAAPI * freeaddrinfow_ptr_t)(PADDRINFOW ai);
static wstring static wstring
utf8ToWchar(const char *str) utf8ToWchar(const char *str)
@@ -78,7 +77,7 @@ bool
socket_resolve(const char *str, const char *port, int addrFamily, int sockType, int protocol, struct sockaddr *addr, int addrLen) socket_resolve(const char *str, const char *port, int addrFamily, int sockType, int protocol, struct sockaddr *addr, int addrLen)
{ {
bool retVal = false; bool retVal = false;
bool useUnicodeCall = false; bool useGetaddrinfo = false;
if (str && *str != 0) if (str && *str != 0)
{ {
@@ -86,28 +85,25 @@ socket_resolve(const char *str, const char *port, int addrFamily, int sockType,
if (hWsock) if (hWsock)
{ {
// Determine functions at runtime, because some windows systems do not // Determine functions at runtime, because windows systems < XP do not
// support the unicode version of getaddrinfo. // support getaddrinfo.
getaddrinfow_ptr_t getaddrinfow_ptr = (getaddrinfow_ptr_t)::GetProcAddress(hWsock, "GetAddrInfoW"); getaddrinfo_ptr_t getaddrinfo_ptr = (getaddrinfo_ptr_t)::GetProcAddress(hWsock, "getaddrinfo");
freeaddrinfow_ptr_t freeaddrinfow_ptr = (freeaddrinfow_ptr_t)::GetProcAddress(hWsock, "FreeAddrInfoW"); freeaddrinfo_ptr_t freeaddrinfo_ptr = (freeaddrinfo_ptr_t)::GetProcAddress(hWsock, "freeaddrinfo");
if (getaddrinfow_ptr && freeaddrinfow_ptr) if (getaddrinfo_ptr && freeaddrinfo_ptr)
{ {
useUnicodeCall = true; useGetaddrinfo = true;
// convert str from UTF-8 to UTF-16 (Win32 byte order) struct addrinfo aiHints;
wstring wstr(utf8ToWchar(str)); struct addrinfo *aiList = NULL;
wstring wport(utf8ToWchar(port));
ADDRINFOW aiHints;
ADDRINFOW *aiList = NULL;
memset(&aiHints, 0, sizeof(aiHints)); memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = addrFamily; aiHints.ai_family = addrFamily;
aiHints.ai_socktype = sockType; aiHints.ai_socktype = sockType;
aiHints.ai_protocol = protocol; aiHints.ai_protocol = protocol;
// resolve the name (unicode). // Try to resolve the name.
bool success = (getaddrinfow_ptr(wstr.c_str(), wport.c_str(), &aiHints, &aiList) == 0); bool success = (getaddrinfo_ptr(str, port, &aiHints, &aiList) == 0);
if (success && aiList) if (success && aiList)
{ {
@@ -116,15 +112,22 @@ socket_resolve(const char *str, const char *port, int addrFamily, int sockType,
memcpy(addr, aiList->ai_addr, aiList->ai_addrlen); memcpy(addr, aiList->ai_addr, aiList->ai_addrlen);
retVal = true; retVal = true;
} }
freeaddrinfow_ptr(aiList); freeaddrinfo_ptr(aiList);
} }
} }
::FreeLibrary(hWsock); ::FreeLibrary(hWsock);
} }
// If we cannot use the unicode function (OS older than XP SP 2), // If we cannot use getaddrinfo (OS older than XP),
// we call the "classic" getaddrinfo. // we call the "classic" gethostbyname.
if (!useUnicodeCall) if (!useGetaddrinfo && protocol == AF_INET)
retVal = internal_socket_resolve(str, port, addrFamily, sockType, protocol, addr, addrLen); {
struct hostent *host = gethostbyname(str);
if (host && host->h_addr_list)
{
memcpy(addr, host->h_addr_list, host->h_length);
retVal = true;
}
}
} }
return retVal; return retVal;
} }