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:
+11
-6
@@ -209,15 +209,20 @@ TRANSLATIONS = \
|
||||
win32{
|
||||
DEPENDPATH += src/net/win32/ src/core/win32
|
||||
INCLUDEPATH += ../boost/ ../SDL/include ../SDL_mixer
|
||||
INCLUDEPATH += ../SDL/include/SDL ../SDL_mixer/include
|
||||
LIBPATH += ../boost/stage/lib
|
||||
debug {
|
||||
LIBPATH += Debug/lib ../SDL/VisualC/SDL/Debug ../SDL/VisualC/SDLmain/Debug ../SDL_mixer/VisualC/Debug
|
||||
}
|
||||
!debug {
|
||||
|
||||
release {
|
||||
LIBPATH += Release/lib ../SDL/VisualC/SDL/Release ../SDL/VisualC/SDLmain/Release ../SDL_mixer/VisualC/Release
|
||||
}
|
||||
LIBS += pokerth_lib.lib
|
||||
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
|
||||
!release {
|
||||
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
|
||||
}
|
||||
!win32{
|
||||
|
||||
+9
-6
@@ -96,14 +96,17 @@ win32{
|
||||
DEPENDPATH += src/net/win32/ src/core/win32
|
||||
INCLUDEPATH += ../boost/
|
||||
LIBPATH += ../boost/stage/lib
|
||||
debug {
|
||||
LIBPATH += Debug/lib
|
||||
}
|
||||
!debug {
|
||||
|
||||
release {
|
||||
LIBPATH += Release/lib
|
||||
}
|
||||
LIBS += pokerth_lib.lib
|
||||
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
|
||||
!release {
|
||||
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{
|
||||
DEPENDPATH += src/net/linux/ src/core/linux
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
//
|
||||
#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>
|
||||
|
||||
using namespace std;
|
||||
@@ -35,10 +45,10 @@ void SDLPlayer::initAudio() {
|
||||
|
||||
if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects"))
|
||||
{
|
||||
audio_rate = 44100;
|
||||
audio_format = AUDIO_S16; /* 16-bit stereo */
|
||||
audio_channels = 2;
|
||||
audio_buffers = 4096;
|
||||
int audio_rate = 44100;
|
||||
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
|
||||
int audio_channels = 2;
|
||||
int audio_buffers = 4096;
|
||||
sound = NULL;
|
||||
|
||||
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) {
|
||||
|
||||
@@ -14,23 +14,12 @@
|
||||
#ifndef 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 "configfile.h"
|
||||
#include "qthelper.h"
|
||||
|
||||
struct Mix_Chunk;
|
||||
|
||||
/**
|
||||
@author FThauer FHammer <webmaster@pokerth.net>
|
||||
*/
|
||||
@@ -49,12 +38,8 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
int audio_rate;
|
||||
Uint16 audio_format;
|
||||
int audio_channels;
|
||||
int audio_buffers;
|
||||
Mix_Chunk *sound;
|
||||
Uint8 *soundData;
|
||||
unsigned char *soundData;
|
||||
int currentChannel;
|
||||
|
||||
bool audioEnabled;
|
||||
|
||||
@@ -44,35 +44,3 @@ socket_set_port(unsigned port, int addrFamily, struct sockaddr *addr, int addrLe
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <wspiapi.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
@@ -37,6 +37,32 @@ socket_string_to_addr(const char *str, int addrFamily, struct sockaddr * addr, i
|
||||
bool
|
||||
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
@@ -35,10 +35,17 @@
|
||||
#define SOCKET_ERR_NOTCONN WSAENOTCONN
|
||||
#define SOCKET_ERR_NOTSOCK WSAENOTSOCK
|
||||
|
||||
typedef unsigned __int16 u_int16_t;
|
||||
typedef unsigned __int32 u_int32_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef __int32 int32_t;
|
||||
#ifdef __GNUC__ /* mingw provides stdint.h */
|
||||
#include <stdint.h>
|
||||
typedef uint16_t u_int16_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;
|
||||
|
||||
#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);
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
|
||||
@@ -28,9 +28,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef int (WSAAPI * getaddrinfow_ptr_t)(const wchar_t *nodename, const wchar_t* servname,
|
||||
const ADDRINFOW *hints, PADDRINFOW *res);
|
||||
typedef void (WSAAPI * freeaddrinfow_ptr_t)(PADDRINFOW ai);
|
||||
typedef int (WSAAPI * getaddrinfo_ptr_t) (const char *, const char* , const struct addrinfo *, struct addrinfo **);
|
||||
typedef void (WSAAPI * freeaddrinfo_ptr_t) (struct addrinfo*);
|
||||
|
||||
static wstring
|
||||
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)
|
||||
{
|
||||
bool retVal = false;
|
||||
bool useUnicodeCall = false;
|
||||
bool useGetaddrinfo = false;
|
||||
|
||||
if (str && *str != 0)
|
||||
{
|
||||
@@ -86,28 +85,25 @@ socket_resolve(const char *str, const char *port, int addrFamily, int sockType,
|
||||
|
||||
if (hWsock)
|
||||
{
|
||||
// Determine functions at runtime, because some windows systems do not
|
||||
// support the unicode version of getaddrinfo.
|
||||
getaddrinfow_ptr_t getaddrinfow_ptr = (getaddrinfow_ptr_t)::GetProcAddress(hWsock, "GetAddrInfoW");
|
||||
freeaddrinfow_ptr_t freeaddrinfow_ptr = (freeaddrinfow_ptr_t)::GetProcAddress(hWsock, "FreeAddrInfoW");
|
||||
// Determine functions at runtime, because windows systems < XP do not
|
||||
// support getaddrinfo.
|
||||
getaddrinfo_ptr_t getaddrinfo_ptr = (getaddrinfo_ptr_t)::GetProcAddress(hWsock, "getaddrinfo");
|
||||
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)
|
||||
wstring wstr(utf8ToWchar(str));
|
||||
wstring wport(utf8ToWchar(port));
|
||||
ADDRINFOW aiHints;
|
||||
ADDRINFOW *aiList = NULL;
|
||||
struct addrinfo aiHints;
|
||||
struct addrinfo *aiList = NULL;
|
||||
|
||||
memset(&aiHints, 0, sizeof(aiHints));
|
||||
aiHints.ai_family = addrFamily;
|
||||
aiHints.ai_socktype = sockType;
|
||||
aiHints.ai_protocol = protocol;
|
||||
|
||||
// resolve the name (unicode).
|
||||
bool success = (getaddrinfow_ptr(wstr.c_str(), wport.c_str(), &aiHints, &aiList) == 0);
|
||||
// Try to resolve the name.
|
||||
bool success = (getaddrinfo_ptr(str, port, &aiHints, &aiList) == 0);
|
||||
|
||||
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);
|
||||
retVal = true;
|
||||
}
|
||||
freeaddrinfow_ptr(aiList);
|
||||
freeaddrinfo_ptr(aiList);
|
||||
}
|
||||
}
|
||||
::FreeLibrary(hWsock);
|
||||
}
|
||||
// If we cannot use the unicode function (OS older than XP SP 2),
|
||||
// we call the "classic" getaddrinfo.
|
||||
if (!useUnicodeCall)
|
||||
retVal = internal_socket_resolve(str, port, addrFamily, sockType, protocol, addr, addrLen);
|
||||
// If we cannot use getaddrinfo (OS older than XP),
|
||||
// we call the "classic" gethostbyname.
|
||||
if (!useGetaddrinfo && protocol == AF_INET)
|
||||
{
|
||||
struct hostent *host = gethostbyname(str);
|
||||
if (host && host->h_addr_list)
|
||||
{
|
||||
memcpy(addr, host->h_addr_list, host->h_length);
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user