[*] Linux IPC reliability: finally got around to closing #48

This commit is contained in:
Reece Wilson 2023-09-16 23:30:10 +01:00
parent f2339bb0a9
commit a4f6db7ec9
2 changed files with 43 additions and 4 deletions

View File

@ -60,7 +60,40 @@ namespace Aurora::IO::IPC
void IPCPipeImpl::DrainOtherFd()
{
// TODO (Reece): urgent
#if defined(FIONREAD)
int available {};
if (::ioctl(fds[1], FIONREAD, &available) < 0)
{
return;
}
if (!available)
{
return;
}
AuByteBuffer temp(available);
SysAssert(temp);
AuUInt uCounter {};
while (this->ReadEx({temp, uCounter}, true, false))
{
temp.writePtr = temp.readPtr = temp.base;
}
#else
AuByteBuffer temp(4096 * 10);
SysAssert(temp);
AuUInt uCounter {};
while (this->ReadEx({temp, uCounter}, true, false))
{
temp.writePtr = temp.readPtr = temp.base;
}
#endif
}
AuUInt IPCPipeImpl::GetPreemptFd()
@ -77,8 +110,7 @@ namespace Aurora::IO::IPC
#if defined(FIONREAD)
int available {};
int res = ::ioctl(fds[0], FIONREAD, &available) ;
if (res< 0)
if (::ioctl(fds[0], FIONREAD, &available) < 0)
{
return false;
}
@ -162,7 +194,12 @@ namespace Aurora::IO::IPC
bool IPCPipeImpl::Read(const Memory::MemoryViewStreamWrite &write, bool nonblock)
{
auto handle = fds[0];
return this->ReadEx(write, nonblock, true);
}
bool IPCPipeImpl::ReadEx(const Memory::MemoryViewStreamWrite &write, bool nonblock, bool bSide)
{
auto handle = bSide ? fds[0] : fds[1];
auto control = ::fcntl(handle, F_GETFL);
auto ref = control;

View File

@ -62,6 +62,8 @@ namespace Aurora::IO::IPC
virtual bool Write(const Memory::MemoryViewStreamRead &read) override;
virtual AuString ExportToString() override;
bool ReadEx(const Memory::MemoryViewStreamWrite &write, bool nonblock, bool bSide);
bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override;