Fix compilation on Windows < Vista
This commit is contained in:
parent
4039d16df0
commit
3d21401569
|
|
@ -118,8 +118,14 @@ namespace Nz::PlatformImpl
|
|||
static SetThreadDescriptionFunc SetThreadDescription = reinterpret_cast<SetThreadDescriptionFunc>(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "SetThreadDescription"));
|
||||
if (SetThreadDescription)
|
||||
SetThreadDescription(threadHandle, ToWideString(threadName).data());
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
else
|
||||
RaiseThreadNameException(::GetThreadId(threadHandle), threadName);
|
||||
#else
|
||||
NazaraUnused(threadHandle);
|
||||
NazaraUnused(threadName);
|
||||
#endif
|
||||
|
||||
#else
|
||||
::pthread_setname_np(threadHandle, threadName);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -51,11 +51,11 @@ namespace Nz
|
|||
|
||||
Time GetElapsedMillisecondsImpl()
|
||||
{
|
||||
#ifdef NAZARA_UTILS_WINDOWS_NT6
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
return Time::Milliseconds(GetTickCount64());
|
||||
#else
|
||||
#else
|
||||
return Time::Milliseconds(GetTickCount());
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
|||
{
|
||||
namespace Detail
|
||||
{
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
using addrinfoImpl = addrinfoW;
|
||||
|
||||
int GetAddressInfo(const std::string& hostname, const std::string& service, const addrinfoImpl* hints, addrinfoImpl** results)
|
||||
|
|
@ -59,7 +59,7 @@ namespace Nz
|
|||
{
|
||||
return FromWideString(str);
|
||||
}
|
||||
#else
|
||||
#else
|
||||
using addrinfoImpl = addrinfo;
|
||||
|
||||
int GetAddressInfo(const std::string& hostname, const std::string& service, const addrinfoImpl* hints, addrinfoImpl** results)
|
||||
|
|
@ -94,7 +94,7 @@ namespace Nz
|
|||
{
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
IpAddress IpAddressImpl::FromAddrinfo(const addrinfo* info)
|
||||
|
|
@ -119,7 +119,7 @@ namespace Nz
|
|||
return IpAddress::Invalid;
|
||||
}
|
||||
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
IpAddress IpAddressImpl::FromAddrinfo(const addrinfoW* info)
|
||||
{
|
||||
switch (info->ai_family)
|
||||
|
|
@ -141,7 +141,7 @@ namespace Nz
|
|||
|
||||
return IpAddress::Invalid;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
IpAddress IpAddressImpl::FromSockAddr(const sockaddr* address)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ namespace Nz
|
|||
~IpAddressImpl() = delete;
|
||||
|
||||
static IpAddress FromAddrinfo(const addrinfo* info);
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
static IpAddress FromAddrinfo(const addrinfoW* info);
|
||||
#endif
|
||||
#endif
|
||||
static IpAddress FromSockAddr(const sockaddr* address);
|
||||
static IpAddress FromSockAddr(const sockaddr_in* addressv4);
|
||||
static IpAddress FromSockAddr(const sockaddr_in6* addressv6);
|
||||
|
|
|
|||
|
|
@ -449,12 +449,28 @@ namespace Nz
|
|||
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)
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
WSAPOLLFD descriptor;
|
||||
descriptor.events = POLLWRNORM;
|
||||
descriptor.fd = handle;
|
||||
descriptor.revents = 0;
|
||||
|
||||
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 (error)
|
||||
|
|
@ -464,18 +480,30 @@ namespace Nz
|
|||
}
|
||||
else if (ret > 0)
|
||||
{
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
if (descriptor.revents & (POLLERR | POLLHUP))
|
||||
#else
|
||||
if (FD_ISSET(handle, &errSet))
|
||||
#endif
|
||||
{
|
||||
if (error)
|
||||
*error = GetLastError(handle);
|
||||
|
||||
return SocketState::NotConnected;
|
||||
}
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
else if (descriptor.revents & POLLWRNORM)
|
||||
#else
|
||||
else if (FD_ISSET(handle, &writeSet))
|
||||
#endif
|
||||
return SocketState::Connected;
|
||||
else
|
||||
{
|
||||
#if NAZARA_UTILS_WINDOWS_NT6
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue