From 9a846a6d2f08374b2c63b1de216480779bae9302 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 9 Mar 2024 01:08:56 +0000 Subject: [PATCH] [*] Update IAsyncFileStream::NewTransaction --- Source/IO/FS/Async.Linux.cpp | 4 +++- Source/IO/FS/Async.NT.cpp | 23 ++++++++++++++++++++++- Source/IO/FS/Async.NT.hpp | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Source/IO/FS/Async.Linux.cpp b/Source/IO/FS/Async.Linux.cpp index dd01b784..b5cedf9f 100644 --- a/Source/IO/FS/Async.Linux.cpp +++ b/Source/IO/FS/Async.Linux.cpp @@ -139,7 +139,9 @@ namespace Aurora::IO::FS AuSPtr LinuxAsyncFileStream::NewTransaction() { - if (!AuStaticCast(this->pHandle_)->bDirectIO) + if (!this->pProcessBlock_ && + !AuStaticCast(this->pHandle_)->bDirectIO && + !AuStaticCast(this->pHandle_)->pIPCPipe) { auto &pFSReader = this->pCache_; diff --git a/Source/IO/FS/Async.NT.cpp b/Source/IO/FS/Async.NT.cpp index 4c12c909..6164d9ef 100644 --- a/Source/IO/FS/Async.NT.cpp +++ b/Source/IO/FS/Async.NT.cpp @@ -78,10 +78,31 @@ namespace Aurora::IO::FS AuSPtr NtAsyncFileStream::NewTransaction() { + if (!this->pHandle_->IsAsync()) + { + auto &pFSReader = this->pCache_; + + if (!pFSReader) + { + pFSReader = AuFS::OpenBlockingFileStreamFromHandle(this->pHandle_); + } + + if (!pFSReader) + { + SysPushErrorNested(); + return {}; + } + + auto pStreamReader = AuSharedPointerFromShared(pFSReader->ToStreamSeekingReader(), pFSReader); + auto pStreamWriter = AuSharedPointerFromShared(pFSReader->ToStreamSeekingWriter(), pFSReader); + return Adapters::NewAsyncTransactionFromStreamSeekingPair(pStreamReader, pStreamWriter, {}); + } + auto shared = AuMakeShared(); SysCheckNotNullMemory(shared, {}); - if (!shared->InitWeak(this->pHandle_)) + //if (!shared->InitWeak(this->pHandle_)) + if (!shared->Init(this->pHandle_)) { return {}; } diff --git a/Source/IO/FS/Async.NT.hpp b/Source/IO/FS/Async.NT.hpp index 4e3e8358..7f778c0f 100644 --- a/Source/IO/FS/Async.NT.hpp +++ b/Source/IO/FS/Async.NT.hpp @@ -28,6 +28,7 @@ namespace Aurora::IO::FS private: AuSPtr pHandle_; + AuSPtr pCache_; }; struct NtAsyncFileTransaction :