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,7 +51,7 @@ 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());

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;
} }
} }