Fix MSVC and MinGW builds. Closes #1694.
git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@10370 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
c0d626d790
commit
c8e35d7a29
|
@ -32,6 +32,7 @@
|
|||
#else
|
||||
// Defines C99 types for C99 incompatible compilers (e.g. MSVC)
|
||||
#include <SDL_stdinc.h>
|
||||
#ifndef WZ_CC_MINGW
|
||||
# define INT8_MIN (-128)
|
||||
# define INT16_MIN (-32767-1)
|
||||
# define INT32_MIN (-2147483647-1)
|
||||
|
@ -41,9 +42,11 @@
|
|||
# define UINT8_MAX (255)
|
||||
# define UINT16_MAX (65535)
|
||||
# define UINT32_MAX (4294967295U)
|
||||
#endif
|
||||
#ifdef WZ_CC_MSVC
|
||||
# define PRIu32 "u"
|
||||
# define PRIu64 "I64u"
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
#endif // WZ_C99
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ SRC= \
|
|||
netjoin_stub.c \
|
||||
netlog.c \
|
||||
netplay.c \
|
||||
nettypes.c
|
||||
nettypes.c \
|
||||
netsocket.cpp
|
||||
|
||||
LIB=netplay
|
||||
|
||||
|
|
|
@ -160,6 +160,10 @@
|
|||
RelativePath=".\netplay.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\netsocket.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\nettypes.c"
|
||||
>
|
||||
|
@ -278,6 +282,10 @@
|
|||
RelativePath=".\netplay.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\netsocket.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\nettypes.h"
|
||||
>
|
||||
|
|
|
@ -63,7 +63,9 @@
|
|||
# include <unistd.h>
|
||||
typedef int SOCKET;
|
||||
static const SOCKET INVALID_SOCKET = -1;
|
||||
#elif defined(WZ_OS_WIN)
|
||||
#endif
|
||||
|
||||
#ifdef WZ_OS_WIN
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
# undef EAGAIN
|
||||
|
@ -82,7 +84,6 @@ static const SOCKET INVALID_SOCKET = -1;
|
|||
# define EISCONN WSAEISCONN
|
||||
# define ETIMEDOUT WSAETIMEDOUT
|
||||
# define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
typedef SSIZE_T ssize_t;
|
||||
# ifndef AI_V4MAPPED
|
||||
# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
|
||||
# endif
|
||||
|
@ -158,13 +159,16 @@ void setSockErr(int error)
|
|||
}
|
||||
|
||||
#if defined(WZ_OS_WIN)
|
||||
typedef int (WINAPI * GETADDRINFO_DLL_FUNC)(const char *node, const char *service,
|
||||
const struct addrinfo *hints,
|
||||
struct addrinfo **res);
|
||||
typedef int (WINAPI * FREEADDRINFO_DLL_FUNC)(struct addrinfo *res);
|
||||
|
||||
static HMODULE winsock2_dll = NULL;
|
||||
static unsigned int major_windows_version = 0;
|
||||
static int (WINAPI * getaddrinfo_dll_func)(const char *node, const char *service,
|
||||
const struct addrinfo *hints,
|
||||
struct addrinfo **res) = NULL;
|
||||
|
||||
static int (WINAPI * freeaddrinfo_dll_func)(struct addrinfo *res) = NULL;
|
||||
static GETADDRINFO_DLL_FUNC getaddrinfo_dll_func = NULL;
|
||||
static FREEADDRINFO_DLL_FUNC freeaddrinfo_dll_func = NULL;
|
||||
|
||||
# define getaddrinfo getaddrinfo_dll_dispatcher
|
||||
# define freeaddrinfo freeaddrinfo_dll_dispatcher
|
||||
|
@ -517,7 +521,7 @@ ssize_t readNoInt(Socket* sock, void* buf, size_t max_size)
|
|||
|
||||
do
|
||||
{
|
||||
received = recv(sock->fd[SOCK_CONNECTION], buf, max_size, 0);
|
||||
received = recv(sock->fd[SOCK_CONNECTION], (char*)buf, max_size, 0);
|
||||
} while (received == SOCKET_ERROR && getSockErr() == EINTR);
|
||||
|
||||
sock->ready = false;
|
||||
|
@ -1080,7 +1084,7 @@ Socket *socketListen(unsigned int port)
|
|||
#if defined(IPV6_V6ONLY)
|
||||
if (conn->fd[SOCK_IPV6_LISTEN] != INVALID_SOCKET)
|
||||
{
|
||||
if (setsockopt(conn->fd[SOCK_IPV6_LISTEN], IPPROTO_IPV6, IPV6_V6ONLY, &ipv6_v6only, sizeof(ipv6_v6only)) == SOCKET_ERROR)
|
||||
if (setsockopt(conn->fd[SOCK_IPV6_LISTEN], IPPROTO_IPV6, IPV6_V6ONLY, (char*)&ipv6_v6only, sizeof(ipv6_v6only)) == SOCKET_ERROR)
|
||||
{
|
||||
debug(LOG_INFO, "Failed to set IPv6 socket to perform IPv4 to IPv6 mapping. Falling back to using two sockets. Error: %s", strSockError(getSockErr()));
|
||||
}
|
||||
|
@ -1099,7 +1103,7 @@ Socket *socketListen(unsigned int port)
|
|||
|
||||
if (conn->fd[SOCK_IPV4_LISTEN] != INVALID_SOCKET)
|
||||
{
|
||||
if (setsockopt(conn->fd[SOCK_IPV4_LISTEN], SOL_SOCKET, SO_REUSEADDR, &so_reuseaddr, sizeof(so_reuseaddr)) == SOCKET_ERROR)
|
||||
if (setsockopt(conn->fd[SOCK_IPV4_LISTEN], SOL_SOCKET, SO_REUSEADDR, (char*)&so_reuseaddr, sizeof(so_reuseaddr)) == SOCKET_ERROR)
|
||||
{
|
||||
debug(LOG_WARNING, "Failed to set SO_REUSEADDR on IPv4 socket. Error: %s", strSockError(getSockErr()));
|
||||
}
|
||||
|
@ -1121,7 +1125,7 @@ Socket *socketListen(unsigned int port)
|
|||
|
||||
if (conn->fd[SOCK_IPV6_LISTEN] != INVALID_SOCKET)
|
||||
{
|
||||
if (setsockopt(conn->fd[SOCK_IPV6_LISTEN], SOL_SOCKET, SO_REUSEADDR, &so_reuseaddr, sizeof(so_reuseaddr)) == SOCKET_ERROR)
|
||||
if (setsockopt(conn->fd[SOCK_IPV6_LISTEN], SOL_SOCKET, SO_REUSEADDR, (char*)&so_reuseaddr, sizeof(so_reuseaddr)) == SOCKET_ERROR)
|
||||
{
|
||||
debug(LOG_INFO, "Failed to set SO_REUSEADDR on IPv6 socket. Error: %s", strSockError(getSockErr()));
|
||||
}
|
||||
|
@ -1248,14 +1252,14 @@ void SOCKETinit()
|
|||
if (WSAStartup(ver_required, &stuff) != 0)
|
||||
{
|
||||
debug(LOG_ERROR, "Failed to initialize Winsock: %s", strSockError(getSockErr()));
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
winsock2_dll = LoadLibraryA("ws2_32.dll");
|
||||
if (winsock2_dll)
|
||||
{
|
||||
getaddrinfo_dll_func = GetProcAddress(winsock2_dll, "getaddrinfo");
|
||||
freeaddrinfo_dll_func = GetProcAddress(winsock2_dll, "freeaddrinfo");
|
||||
getaddrinfo_dll_func = (GETADDRINFO_DLL_FUNC) GetProcAddress(winsock2_dll, "getaddrinfo");
|
||||
freeaddrinfo_dll_func = (FREEADDRINFO_DLL_FUNC) GetProcAddress(winsock2_dll, "freeaddrinfo");
|
||||
}
|
||||
|
||||
// Determine major Windows version
|
||||
|
|
|
@ -32,7 +32,9 @@ typedef struct Socket Socket;
|
|||
typedef struct SocketSet SocketSet;
|
||||
typedef struct addrinfo SocketAddress;
|
||||
|
||||
#ifndef WZ_OS_WIN
|
||||
static const int SOCKET_ERROR = -1;
|
||||
#endif
|
||||
|
||||
|
||||
// Init/shutdown.
|
||||
|
|
Loading…
Reference in New Issue