[*] Passive crinkling of today : Async.NT.cpp can now be aborted. Will port identical behavior to Linux.

This commit is contained in:
Reece Wilson 2022-06-24 20:33:55 +01:00
parent bf6f13095c
commit 250d3fd11e
2 changed files with 51 additions and 10 deletions

View File

@ -293,11 +293,23 @@ namespace Aurora::IO::FS
bool NtAsyncFileTransaction::StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) bool NtAsyncFileTransaction::StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &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()) if (!IDontWannaUsePorts())
{ {
return false; return false;
} }
if (!memoryView)
{
SysPushErrorArg();
return {};
}
this->latch_ = false; this->latch_ = false;
::ResetEvent(this->event_); ::ResetEvent(this->event_);
@ -316,11 +328,23 @@ namespace Aurora::IO::FS
bool NtAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) bool NtAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &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()) if (!IDontWannaUsePorts())
{ {
return false; return false;
} }
if (!memoryView)
{
SysPushErrorArg();
return {};
}
this->latch_ = false; this->latch_ = false;
::ResetEvent(this->event_); ::ResetEvent(this->event_);
@ -345,24 +369,38 @@ namespace Aurora::IO::FS
} }
auto memoryHold = this->memoryHold_; auto memoryHold = this->memoryHold_;
this->memoryHold_.reset();
if (this->sub_) if (this->sub_)
{ {
this->sub_->OnAsyncFileOpFinished(this->lastAbstractOffset_, read); this->sub_->OnAsyncFileOpFinished(this->lastAbstractOffset_, read);
} }
this->memoryHold_.reset();
} }
void NtAsyncFileTransaction::Reset() void NtAsyncFileTransaction::Reset()
{ {
::ResetEvent(this->event_); if (this->memoryHold_)
this->hasFailed = false; {
this->lastAbstractStat_ = 0; // do not use latch 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() bool NtAsyncFileTransaction::Failed()
{ {
return this->hasFailed && GetOSErrorCode() != ERROR_BROKEN_PIPE; return this->hasFailed && this->osErrorCode != ERROR_BROKEN_PIPE;
} }
AuUInt NtAsyncFileTransaction::GetOSErrorCode() AuUInt NtAsyncFileTransaction::GetOSErrorCode()
@ -374,6 +412,12 @@ namespace Aurora::IO::FS
{ {
DWORD read {}; DWORD read {};
if (this->isIrredeemable_)
{
::ResetEvent(this->event_);
return true;
}
if (GetOSErrorCode() == ERROR_BROKEN_PIPE) if (GetOSErrorCode() == ERROR_BROKEN_PIPE)
{ {
if (!completeRoutine) if (!completeRoutine)
@ -396,11 +440,6 @@ namespace Aurora::IO::FS
return false; return false;
} }
//if (this->latch_)
//{
// return false;
//}
if ((this->hasFailed) || if ((this->hasFailed) ||
::GetOverlappedResult(this->handle_->handle, &this->overlap_, &read, false)) ::GetOverlappedResult(this->handle_->handle, &this->overlap_, &read, false))
{ {

View File

@ -52,6 +52,8 @@ namespace Aurora::IO::FS
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override; bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override; bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
bool isIrredeemable_ {};
bool Complete() override; bool Complete() override;
bool CompleteEx(bool completeRoutine); bool CompleteEx(bool completeRoutine);