From 250d3fd11e44cc33e283cb49076036c7a8419e81 Mon Sep 17 00:00:00 2001 From: Reece Date: Fri, 24 Jun 2022 20:33:55 +0100 Subject: [PATCH] [*] Passive crinkling of today : Async.NT.cpp can now be aborted. Will port identical behavior to Linux. --- Source/IO/FS/Async.NT.cpp | 59 ++++++++++++++++++++++++++++++++------- Source/IO/FS/Async.NT.hpp | 2 ++ 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/Source/IO/FS/Async.NT.cpp b/Source/IO/FS/Async.NT.cpp index 3f04cb0f..07939cd0 100644 --- a/Source/IO/FS/Async.NT.cpp +++ b/Source/IO/FS/Async.NT.cpp @@ -293,11 +293,23 @@ namespace Aurora::IO::FS bool NtAsyncFileTransaction::StartRead(AuUInt64 offset, const AuSPtr &memoryView) { + if (this->isIrredeemable_) + { + SysPushErrorIO("Transaction was signaled to be destroyed to reset mid synchronizable operation. You can no longer use this stream object"); + return false; + } + if (!IDontWannaUsePorts()) { return false; } + if (!memoryView) + { + SysPushErrorArg(); + return {}; + } + this->latch_ = false; ::ResetEvent(this->event_); @@ -316,11 +328,23 @@ namespace Aurora::IO::FS bool NtAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuSPtr &memoryView) { + if (this->isIrredeemable_) + { + SysPushErrorIO("Transaction was signaled to be destroyed to reset mid synchronizable operation. You can no longer use this stream object"); + return false; + } + if (!IDontWannaUsePorts()) { return false; } + if (!memoryView) + { + SysPushErrorArg(); + return {}; + } + this->latch_ = false; ::ResetEvent(this->event_); @@ -345,24 +369,38 @@ namespace Aurora::IO::FS } auto memoryHold = this->memoryHold_; - this->memoryHold_.reset(); if (this->sub_) { this->sub_->OnAsyncFileOpFinished(this->lastAbstractOffset_, read); } + + this->memoryHold_.reset(); } void NtAsyncFileTransaction::Reset() { - ::ResetEvent(this->event_); - this->hasFailed = false; - this->lastAbstractStat_ = 0; // do not use latch + if (this->memoryHold_) + { + this->isIrredeemable_ = true; + this->hasFailed = true; + ::CancelIoEx(this->handle_->handle, &this->overlap_); + ::SetEvent(this->event_); + this->osErrorCode = ERROR_ABANDONED_WAIT_0; + } + else + { + ::ResetEvent(this->event_); + this->hasFailed = false; + } + + this->memoryHold_.reset(); + this->lastAbstractStat_ = 0; } bool NtAsyncFileTransaction::Failed() { - return this->hasFailed && GetOSErrorCode() != ERROR_BROKEN_PIPE; + return this->hasFailed && this->osErrorCode != ERROR_BROKEN_PIPE; } AuUInt NtAsyncFileTransaction::GetOSErrorCode() @@ -374,6 +412,12 @@ namespace Aurora::IO::FS { DWORD read {}; + if (this->isIrredeemable_) + { + ::ResetEvent(this->event_); + return true; + } + if (GetOSErrorCode() == ERROR_BROKEN_PIPE) { if (!completeRoutine) @@ -396,11 +440,6 @@ namespace Aurora::IO::FS return false; } - //if (this->latch_) - //{ - // return false; - //} - if ((this->hasFailed) || ::GetOverlappedResult(this->handle_->handle, &this->overlap_, &read, false)) { diff --git a/Source/IO/FS/Async.NT.hpp b/Source/IO/FS/Async.NT.hpp index cdfd596a..286ad528 100644 --- a/Source/IO/FS/Async.NT.hpp +++ b/Source/IO/FS/Async.NT.hpp @@ -52,6 +52,8 @@ namespace Aurora::IO::FS bool StartRead(AuUInt64 offset, const AuSPtr &memoryView) override; bool StartWrite(AuUInt64 offset, const AuSPtr &memoryView) override; + bool isIrredeemable_ {}; + bool Complete() override; bool CompleteEx(bool completeRoutine);