diff --git a/Source/IO/FS/Async.NT.cpp b/Source/IO/FS/Async.NT.cpp index b8da6bf8..5efec78b 100644 --- a/Source/IO/FS/Async.NT.cpp +++ b/Source/IO/FS/Async.NT.cpp @@ -18,7 +18,7 @@ namespace Aurora::IO::FS { struct NtAsyncFileTransactionLoopSource : AuLoop::LSHandle { - NtAsyncFileTransactionLoopSource(AuSPtr that) : caller_(that), Loop::LSHandle(AuUInt(that->GetFileHandle()->handle)) + NtAsyncFileTransactionLoopSource(AuSPtr that) : caller_(that), Loop::LSHandle(AuUInt(that->event_)) {} virtual bool IsSignaled() override; @@ -273,6 +273,7 @@ namespace Aurora::IO::FS hold->lastAbstractStat_ = 0; hold->CompleteEx(dwNumberOfBytesTransfered); + hold->memoryHold_.reset(); } bool NtAsyncFileTransaction::IDontWannaUsePorts() @@ -379,14 +380,11 @@ namespace Aurora::IO::FS this->lastBytes = read; - auto memoryHold = this->memoryHold_; - if (this->sub_) { this->sub_->OnAsyncFileOpFinished(this->lastAbstractOffset_, read); } - this->memoryHold_.reset(); } void NtAsyncFileTransaction::Reset() @@ -411,7 +409,7 @@ namespace Aurora::IO::FS bool NtAsyncFileTransaction::Failed() { - return this->hasFailed && this->osErrorCode != ERROR_BROKEN_PIPE; + return this->hasFailed; } AuUInt NtAsyncFileTransaction::GetOSErrorCode() diff --git a/Source/IO/IOAdapterAsyncStream.cpp b/Source/IO/IOAdapterAsyncStream.cpp index fac3758d..1e4159eb 100644 --- a/Source/IO/IOAdapterAsyncStream.cpp +++ b/Source/IO/IOAdapterAsyncStream.cpp @@ -34,6 +34,7 @@ namespace Aurora::IO ~AsyncStreamMemory(); bool IsValid(); + bool owned {}; AuSPtr pin; AuUInt streamIndex {}; // todo shared @@ -116,12 +117,12 @@ namespace Aurora::IO AsyncStreamMemory::AsyncStreamMemory(AuUInt length) : AuMemoryViewWrite(AuMemory::ZAlloc(length), length) { - + this->owned = true; } AsyncStreamMemory::~AsyncStreamMemory() { - if (this->ptr) + if (this->ptr && this->owned) { AuMemory::Free(this->ptr); this->ptr = nullptr; diff --git a/Source/IO/IOPipeProcessor.cpp b/Source/IO/IOPipeProcessor.cpp index fe3b8ab0..b1cd9aaa 100644 --- a/Source/IO/IOPipeProcessor.cpp +++ b/Source/IO/IOPipeProcessor.cpp @@ -328,7 +328,7 @@ namespace Aurora::IO try { AuUInt canBuffer = this->buffer_.RemainingWrite(); - //canBuffer = AuMin(canBuffer, AuUInt((this->buffer_.length + this->buffer_.base) - this->buffer_.writePtr)); + canBuffer = AuMin(canBuffer, AuUInt((this->buffer_.length + this->buffer_.base) - this->buffer_.writePtr)); this->nextWriteAsync_ = AuMemoryViewWrite(this->buffer_.writePtr, canBuffer); @@ -373,7 +373,16 @@ namespace Aurora::IO do { AuUInt canRead = this->buffer_.RemainingBytes(); + if (!canRead) + { + break; + } + canRead = AuMin(canRead, (this->buffer_.length + this->buffer_.base) - this->buffer_.readPtr); + if (!canRead) + { + continue; + } try {