[+] Linux: missing io cancellations out of parity with Windows

This commit is contained in:
Reece Wilson 2023-12-24 05:41:03 +00:00
parent a2c8f036e0
commit 06f54968cd
4 changed files with 66 additions and 2 deletions

View File

@ -340,6 +340,8 @@ namespace Aurora::IO::FS
void LinuxAsyncFileTransaction::Reset()
{
(void)this->LIOS_Cancel();
if (this->loopSource_)
{
this->loopSource_->Reset();

View File

@ -264,6 +264,8 @@ namespace Aurora::IO::Net
this->bIsIrredeemable = true;
this->bHasFailed = true;
this->dwOsErrorCode = 0;
(void)this->LIOS_Cancel();
}
else
{

View File

@ -21,6 +21,7 @@
namespace Aurora::IO::UNIX
{
static bool LinuxOverlappedSubmit(int fd, int op, AuUInt offset, ASubmittable *context, AuLoop::ILSEvent *optEvent);
static bool LinuxOverlappedCancel(ASubmittable *context);
static void IoTlsRedo();
@ -50,8 +51,6 @@ namespace Aurora::IO::UNIX
pinSelf = this->pin_;
pinMem = this->memPin_;
LIOS_Reset();
if (AuExchange(this->bIsReadPending, false))
{
// Psyche - it was just the poll half of a blocking read
@ -73,6 +72,8 @@ namespace Aurora::IO::UNIX
return;
}
LIOS_Reset();
try
{
LIOS_Process(read, failure, err, mark);
@ -83,6 +84,11 @@ namespace Aurora::IO::UNIX
}
}
bool ASubmittable::LIOS_Cancel()
{
return LinuxOverlappedCancel(this);
}
bool LIOS_PopOne()
{
return false;
@ -374,6 +380,59 @@ namespace Aurora::IO::UNIX
return AuTryInsert(io->submitPendingArray, &submit);
}
static bool LinuxOverlappedCancel(ASubmittable *context)
{
AuSPtr<void> pinSelf, pinMem;
io_event result;
pinSelf = context->pin_;
pinMem = context->memPin_;
if (!pinSelf)
{
return true;
}
auto io = GetTls();
if (!io)
{
return false;
}
iocb &submit = context->GetIOCB();
if (io_cancel(io->context, &submit, &result) != 0)
{
if (errno == EAGAIN) // The iocb specified was not canceled
{
return false;
}
else // some other garbage state
{
context->LIOS_Reset();
return true;
}
}
auto iErrNo = 0;
bool bError {};
AuUInt bytesTransacted {};
if (result.res < 0)
{
iErrNo = 0 - result.res;
bError = true;
}
else
{
bytesTransacted = result.res;
}
context->LIOS_Reset();
context->LIOS_SendProcess(bytesTransacted, bError, iErrNo);
return true;
}
static bool LinuxOverlappedReadWait(int fd, AuUInt offset, ASubmittable *context, AuLoop::ILSEvent *optEvent)
{
auto io = GetTls();

View File

@ -22,6 +22,7 @@ namespace Aurora::IO::UNIX
void LIOS_SendProcess(AuUInt32 read, bool failure, int err, bool mark = false);
void LIOS_Init(const AuSPtr<void> &pin);
void LIOS_Reset();
bool LIOS_Cancel();
bool HasState();
void SetMemory(const AuSPtr<AuMemoryViewRead> &view);