Fix compilation on Windows < Vista

This commit is contained in:
SirLynix 2023-12-28 13:25:33 +01:00
parent 4039d16df0
commit 3d21401569
5 changed files with 44 additions and 10 deletions

View File

@ -118,8 +118,14 @@ namespace Nz::PlatformImpl
static SetThreadDescriptionFunc SetThreadDescription = reinterpret_cast<SetThreadDescriptionFunc>(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "SetThreadDescription")); static SetThreadDescriptionFunc SetThreadDescription = reinterpret_cast<SetThreadDescriptionFunc>(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "SetThreadDescription"));
if (SetThreadDescription) if (SetThreadDescription)
SetThreadDescription(threadHandle, ToWideString(threadName).data()); SetThreadDescription(threadHandle, ToWideString(threadName).data());
#if NAZARA_UTILS_WINDOWS_NT6
else else
RaiseThreadNameException(::GetThreadId(threadHandle), threadName); RaiseThreadNameException(::GetThreadId(threadHandle), threadName);
#else
NazaraUnused(threadHandle);
NazaraUnused(threadName);
#endif
#else #else
::pthread_setname_np(threadHandle, threadName); ::pthread_setname_np(threadHandle, threadName);
#endif #endif

View File

@ -51,11 +51,11 @@ namespace Nz
Time GetElapsedMillisecondsImpl() Time GetElapsedMillisecondsImpl()
{ {
#ifdef NAZARA_UTILS_WINDOWS_NT6 #if NAZARA_UTILS_WINDOWS_NT6
return Time::Milliseconds(GetTickCount64()); return Time::Milliseconds(GetTickCount64());
#else #else
return Time::Milliseconds(GetTickCount()); return Time::Milliseconds(GetTickCount());
#endif #endif
} }
} }

View File

@ -24,7 +24,7 @@ namespace Nz
{ {
namespace Detail namespace Detail
{ {
#if NAZARA_UTILS_WINDOWS_NT6 #if NAZARA_UTILS_WINDOWS_NT6
using addrinfoImpl = addrinfoW; using addrinfoImpl = addrinfoW;
int GetAddressInfo(const std::string& hostname, const std::string& service, const addrinfoImpl* hints, addrinfoImpl** results) int GetAddressInfo(const std::string& hostname, const std::string& service, const addrinfoImpl* hints, addrinfoImpl** results)
@ -59,7 +59,7 @@ namespace Nz
{ {
return FromWideString(str); return FromWideString(str);
} }
#else #else
using addrinfoImpl = addrinfo; using addrinfoImpl = addrinfo;
int GetAddressInfo(const std::string& hostname, const std::string& service, const addrinfoImpl* hints, addrinfoImpl** results) int GetAddressInfo(const std::string& hostname, const std::string& service, const addrinfoImpl* hints, addrinfoImpl** results)
@ -94,7 +94,7 @@ namespace Nz
{ {
return str; return str;
} }
#endif #endif
} }
IpAddress IpAddressImpl::FromAddrinfo(const addrinfo* info) IpAddress IpAddressImpl::FromAddrinfo(const addrinfo* info)
@ -119,7 +119,7 @@ namespace Nz
return IpAddress::Invalid; return IpAddress::Invalid;
} }
#if NAZARA_UTILS_WINDOWS_NT6 #if NAZARA_UTILS_WINDOWS_NT6
IpAddress IpAddressImpl::FromAddrinfo(const addrinfoW* info) IpAddress IpAddressImpl::FromAddrinfo(const addrinfoW* info)
{ {
switch (info->ai_family) switch (info->ai_family)
@ -141,7 +141,7 @@ namespace Nz
return IpAddress::Invalid; return IpAddress::Invalid;
} }
#endif #endif
IpAddress IpAddressImpl::FromSockAddr(const sockaddr* address) IpAddress IpAddressImpl::FromSockAddr(const sockaddr* address)
{ {

View File

@ -23,9 +23,9 @@ namespace Nz
~IpAddressImpl() = delete; ~IpAddressImpl() = delete;
static IpAddress FromAddrinfo(const addrinfo* info); static IpAddress FromAddrinfo(const addrinfo* info);
#if NAZARA_UTILS_WINDOWS_NT6 #if NAZARA_UTILS_WINDOWS_NT6
static IpAddress FromAddrinfo(const addrinfoW* info); static IpAddress FromAddrinfo(const addrinfoW* info);
#endif #endif
static IpAddress FromSockAddr(const sockaddr* address); static IpAddress FromSockAddr(const sockaddr* address);
static IpAddress FromSockAddr(const sockaddr_in* addressv4); static IpAddress FromSockAddr(const sockaddr_in* addressv4);
static IpAddress FromSockAddr(const sockaddr_in6* addressv6); static IpAddress FromSockAddr(const sockaddr_in6* addressv6);

View File

@ -449,12 +449,28 @@ namespace Nz
SocketState SocketImpl::PollConnection(SocketHandle handle, const IpAddress& /*address*/, UInt64 msTimeout, SocketError* error) SocketState SocketImpl::PollConnection(SocketHandle handle, const IpAddress& /*address*/, UInt64 msTimeout, SocketError* error)
{ {
// Wait until socket is available for writing or an error occurs (ie when connection succeeds or fails) // Wait until socket is available for writing or an error occurs (ie when connection succeeds or fails)
#if NAZARA_UTILS_WINDOWS_NT6
WSAPOLLFD descriptor; WSAPOLLFD descriptor;
descriptor.events = POLLWRNORM; descriptor.events = POLLWRNORM;
descriptor.fd = handle; descriptor.fd = handle;
descriptor.revents = 0; descriptor.revents = 0;
int ret = WSAPoll(&descriptor, 1, (msTimeout != std::numeric_limits<UInt64>::max()) ? INT(msTimeout) : INT(-1)); int ret = WSAPoll(&descriptor, 1, (msTimeout != std::numeric_limits<UInt64>::max()) ? INT(msTimeout) : INT(-1));
#else
fd_set writeSet;
FD_ZERO(&writeSet);
FD_SET(handle, &writeSet);
fd_set errSet;
FD_ZERO(&errSet);
FD_SET(handle, &errSet);
timeval tv;
tv.tv_sec = static_cast<long>(msTimeout / 1000ULL);
tv.tv_usec = static_cast<long>((msTimeout % 1000ULL) * 1000ULL);
int ret = ::select(0xDEADBEEF, nullptr, &writeSet, &errSet, (msTimeout >= 0) ? &tv : nullptr); //< The first argument is ignored on Windows
#endif
if (ret == SOCKET_ERROR) if (ret == SOCKET_ERROR)
{ {
if (error) if (error)
@ -464,18 +480,30 @@ namespace Nz
} }
else if (ret > 0) else if (ret > 0)
{ {
#if NAZARA_UTILS_WINDOWS_NT6
if (descriptor.revents & (POLLERR | POLLHUP)) if (descriptor.revents & (POLLERR | POLLHUP))
#else
if (FD_ISSET(handle, &errSet))
#endif
{ {
if (error) if (error)
*error = GetLastError(handle); *error = GetLastError(handle);
return SocketState::NotConnected; return SocketState::NotConnected;
} }
#if NAZARA_UTILS_WINDOWS_NT6
else if (descriptor.revents & POLLWRNORM) else if (descriptor.revents & POLLWRNORM)
#else
else if (FD_ISSET(handle, &writeSet))
#endif
return SocketState::Connected; return SocketState::Connected;
else else
{ {
#if NAZARA_UTILS_WINDOWS_NT6
NazaraWarningFmt("Socket {0} was returned by poll without POLLOUT nor error events (events: {1:#x})", handle, descriptor.revents); NazaraWarningFmt("Socket {0} was returned by poll without POLLOUT nor error events (events: {1:#x})", handle, descriptor.revents);
#else
NazaraWarningFmt("Socket {0} was returned by select but is not part of the write nor exception set", handle);
#endif
return SocketState::NotConnected; return SocketState::NotConnected;
} }
} }