[*] Fix busted nt timeouts under loopsource waits

This commit is contained in:
Reece Wilson 2023-12-23 08:03:59 +00:00
parent cdfb35d5a8
commit 1576f56d19

View File

@ -21,14 +21,37 @@ namespace Aurora::IO::Loop
{
one = 0;
DWORD ret;
DWORD ret { WAIT_IO_COMPLETION };
AuUInt64 uEndTimeSteady = timeout ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) :
0;
do
{
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handles.at(0)), timeout, true);
AuUInt32 uRemMS { INFINITE };
ret = WaitForSingleObjectEx(reinterpret_cast<HANDLE>(handles.at(0)), uRemMS, true);
if (timeout &&
ret != WAIT_IO_COMPLETION &&
ret != WAIT_OBJECT_0)
{
auto uNow = AuTime::SteadyClockNS();
if (uNow >= uEndTimeSteady)
{
break;
}
uRemMS = AuNSToMS<AuUInt64>(uEndTimeSteady);
if (!uRemMS)
{
break;
}
}
}
while (ret == WAIT_IO_COMPLETION);
return ret == WAIT_OBJECT_0;
return ret == WAIT_OBJECT_0;
}
else
{
@ -42,15 +65,45 @@ namespace Aurora::IO::Loop
return false;
}
}
auto idx = WaitForMultipleObjectsEx(ntHandles.size(), ntHandles.data(), false, timeout, true);
if (idx < WAIT_OBJECT_0)
{
return false;
}
one = handles[idx];
return true;
DWORD ret { WAIT_IO_COMPLETION };
AuUInt64 uEndTimeSteady = timeout ?
AuTime::SteadyClockNS() + AuMSToNS<AuUInt64>(timeout) : 0;
do
{
AuUInt32 uRemMS { INFINITE };
ret = WaitForMultipleObjectsEx(ntHandles.size(), ntHandles.data(), false, uRemMS, true);
if (ret < WAIT_OBJECT_0)
{
continue;
}
if (ret < ntHandles.size())
{
one = handles[ret];
return true;
}
if (timeout)
{
auto uNow = AuTime::SteadyClockNS();
if (uNow >= uEndTimeSteady)
{
break;
}
uRemMS = AuNSToMS<AuUInt64>(uEndTimeSteady);
if (!uRemMS)
{
break;
}
}
}
while (ret == WAIT_IO_COMPLETION);
return false;
}
}