From 81d7c7027cfba06486b97dcead4259409213441c Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 16 Mar 2024 09:51:41 +0000 Subject: [PATCH] [*] Cont work on AuIOHandle cleanup --- Source/IO/AuIOHandle.cpp | 34 +++++++++++++++-------------- Source/IO/FS/Async.Linux.cpp | 2 +- Source/IO/FS/Async.NT.cpp | 2 +- Source/IO/FS/FS.cpp | 6 ++--- Source/IO/IPC/AuIPCPipe.NT.cpp | 2 +- Source/IO/IPC/AuIPCPipe.Unix.cpp | 2 +- Source/Processes/AuProcess.NT.cpp | 6 ++--- Source/Processes/AuProcess.Unix.cpp | 6 ++--- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Source/IO/AuIOHandle.cpp b/Source/IO/AuIOHandle.cpp index 5561e0aa..a5a17487 100644 --- a/Source/IO/AuIOHandle.cpp +++ b/Source/IO/AuIOHandle.cpp @@ -31,29 +31,31 @@ namespace Aurora::IO this->SharingStop(); } - if (this->uOSWriteHandle.has_value() && this->uOSReadHandle.has_value() && - this->uOSReadHandle.value() == this->uOSWriteHandle.value()) + if (this->uOSWriteHandle.HasValue() && this->uOSReadHandle.HasValue() && + this->uOSReadHandle.Value() == this->uOSWriteHandle.Value()) { - this->CloseHandle(this->uOSReadHandle.value()); + this->CloseHandle(this->uOSReadHandle.Value()); AuResetMember(this->uOSReadHandle); AuResetMember(this->uOSWriteHandle); } if (this->uOSReadHandle) { - this->CloseHandle(this->uOSReadHandle.value()); + this->CloseHandle(this->uOSReadHandle.Value()); AuResetMember(this->uOSReadHandle); } if (this->uOSWriteHandle) { - this->CloseHandle(this->uOSWriteHandle.value()); + this->CloseHandle(this->uOSWriteHandle.Value()); AuResetMember(this->uOSWriteHandle); } } bool AFileHandle::InitFromHandle(const AuSPtr &pHandle) { + SysCheckArgNotNull(pHandle, false); + auto pSrc = AuStaticCast(pHandle); auto pDest = this; @@ -115,7 +117,7 @@ namespace Aurora::IO if (optOSReadHandle) { - if (auto uOSReadHandle2 = this->DupHandle(optOSReadHandle.value(), false)) + if (auto uOSReadHandle2 = this->DupHandle(optOSReadHandle.Value(), false)) { this->uOSReadHandle = uOSReadHandle2; } @@ -127,13 +129,13 @@ namespace Aurora::IO if (optOSWriteHandle) { - if (auto uOSWriteHandle2 = this->DupHandle(optOSWriteHandle.value(), true)) + if (auto uOSWriteHandle2 = this->DupHandle(optOSWriteHandle.Value(), true)) { this->uOSWriteHandle = uOSWriteHandle2; } else { - this->CloseHandle(this->uOSReadHandle.value()); + this->CloseHandle(this->uOSReadHandle.Value()); AuResetMember(this->uOSReadHandle); return {}; } @@ -180,12 +182,12 @@ namespace Aurora::IO if (auto optFile = this->optIsFile) { - return optFile.value(); + return optFile.Value(); } if (auto optHandle = this->GetOSHandleSafe()) { - bIsFile = IsHandleFile(optHandle.value()); + bIsFile = IsHandleFile(optHandle.Value()); } else { @@ -203,12 +205,12 @@ namespace Aurora::IO if (auto optTTY = this->optIsTTY) { - return optTTY.value(); + return optTTY.Value(); } if (auto optHandle = this->GetOSHandleSafe()) { - bIsTTY = IsHandleTTY(optHandle.value()); + bIsTTY = IsHandleTTY(optHandle.Value()); } else { @@ -236,12 +238,12 @@ namespace Aurora::IO if (auto optPipe = this->optIsPipe) { - return optPipe.value(); + return optPipe.Value(); } if (auto optHandle = this->GetOSHandleSafe()) { - bIsPipe = IsHandlePipe(optHandle.value()); + bIsPipe = IsHandlePipe(optHandle.Value()); } else { @@ -278,7 +280,7 @@ namespace Aurora::IO AuUInt64 AFileHandle::GetOSReadHandle() const { - return this->uOSReadHandle.value(); + return this->uOSReadHandle.Value(); } AuOptionalEx AFileHandle::GetOSReadHandleSafe() const @@ -288,7 +290,7 @@ namespace Aurora::IO AuUInt64 AFileHandle::GetOSWriteHandle() const { - return this->uOSWriteHandle.value(); + return this->uOSWriteHandle.Value(); } AuOptionalEx AFileHandle::GetOSWriteHandleSafe() const diff --git a/Source/IO/FS/Async.Linux.cpp b/Source/IO/FS/Async.Linux.cpp index b5cedf9f..3b5f05e4 100644 --- a/Source/IO/FS/Async.Linux.cpp +++ b/Source/IO/FS/Async.Linux.cpp @@ -147,7 +147,7 @@ namespace Aurora::IO::FS if (!pFSReader) { - pFSReader = AuFS::OpenBlockingFileStreamFromHandle(this->pHandle_); + pFSReader = OpenBlockingFileStreamFromHandleShared(this->pHandle_); } if (!pFSReader) diff --git a/Source/IO/FS/Async.NT.cpp b/Source/IO/FS/Async.NT.cpp index 6164d9ef..6943dd24 100644 --- a/Source/IO/FS/Async.NT.cpp +++ b/Source/IO/FS/Async.NT.cpp @@ -84,7 +84,7 @@ namespace Aurora::IO::FS if (!pFSReader) { - pFSReader = AuFS::OpenBlockingFileStreamFromHandle(this->pHandle_); + pFSReader = OpenBlockingFileStreamFromHandleShared(this->pHandle_); } if (!pFSReader) diff --git a/Source/IO/FS/FS.cpp b/Source/IO/FS/FS.cpp index 24ae79e0..3f918ba8 100644 --- a/Source/IO/FS/FS.cpp +++ b/Source/IO/FS/FS.cpp @@ -388,7 +388,7 @@ namespace Aurora::IO::FS return false; } - auto pStream = FS::OpenBlockingFileStreamFromHandle(AuUnsafeRaiiToShared(handle.AsPointer())); + auto pStream = OpenBlockingFileStreamFromHandleShared(AuUnsafeRaiiToShared(handle.AsPointer())); if (!pStream) { return false; @@ -430,7 +430,7 @@ namespace Aurora::IO::FS return false; } - auto pStream = FS::OpenBlockingFileStreamFromHandle(AuUnsafeRaiiToShared(handle.AsPointer())); + auto pStream = OpenBlockingFileStreamFromHandleShared(AuUnsafeRaiiToShared(handle.AsPointer())); if (!pStream) { return false; @@ -468,7 +468,7 @@ namespace Aurora::IO::FS return false; } - auto pStream = FS::OpenBlockingFileStreamFromHandle(AuUnsafeRaiiToShared(handle.AsPointer())); + auto pStream = FS::OpenBlockingFileStreamFromHandleShared(AuUnsafeRaiiToShared(handle.AsPointer())); if (!pStream) { return false; diff --git a/Source/IO/IPC/AuIPCPipe.NT.cpp b/Source/IO/IPC/AuIPCPipe.NT.cpp index 163fa8af..16e1d045 100644 --- a/Source/IO/IPC/AuIPCPipe.NT.cpp +++ b/Source/IO/IPC/AuIPCPipe.NT.cpp @@ -118,7 +118,7 @@ namespace Aurora::IO::IPC AuStaticCast(this->fsHandle_)->bIsAsync = true; AuStaticCast(this->fsHandle_)->pIPCPipe = this; - this->fsBlockingStream_ = AuFS::OpenBlockingFileStreamFromHandle(this->fsHandle_); + this->fsBlockingStream_ = AuFS::OpenBlockingFileStreamFromHandleShared(this->fsHandle_); if (!this->fsBlockingStream_) { this->bDead = true; diff --git a/Source/IO/IPC/AuIPCPipe.Unix.cpp b/Source/IO/IPC/AuIPCPipe.Unix.cpp index 14f27ae4..212efb49 100644 --- a/Source/IO/IPC/AuIPCPipe.Unix.cpp +++ b/Source/IO/IPC/AuIPCPipe.Unix.cpp @@ -188,7 +188,7 @@ namespace Aurora::IO::IPC (void)this->fsHandle_->InitFromPairMove(fds2[0], fds2[1]); this->fsStream_->Init(this->fsHandle_); - this->fsBlockingStream_ = AuFS::OpenBlockingFileStreamFromHandle(this->fsHandle_); + this->fsBlockingStream_ = AuFS::OpenBlockingFileStreamFromHandleShared(this->fsHandle_); if (!this->fsBlockingStream_) { this->bDead = true; diff --git a/Source/Processes/AuProcess.NT.cpp b/Source/Processes/AuProcess.NT.cpp index f09808c0..89dda4ae 100644 --- a/Source/Processes/AuProcess.NT.cpp +++ b/Source/Processes/AuProcess.NT.cpp @@ -542,7 +542,7 @@ namespace Aurora::Processes { if (auto pThat = this->GetErrorStreamHandle()) { - if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat)) + if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandleShared(pThat)) { return { pThat2, pThat2->ToStreamReader() }; } @@ -552,7 +552,7 @@ namespace Aurora::Processes { if (auto pThat = this->GetOutputAndInputHandles()) { - if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat)) + if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandleShared(pThat)) { return { pThat2, pThat2->ToStreamReader() }; } @@ -566,7 +566,7 @@ namespace Aurora::Processes { if (auto pThat = this->GetErrorStreamHandle()) { - if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat)) + if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandleShared(pThat)) { return { pThat2, pThat2->ToStreamWriter() }; } diff --git a/Source/Processes/AuProcess.Unix.cpp b/Source/Processes/AuProcess.Unix.cpp index 7aa970d0..16b9da56 100644 --- a/Source/Processes/AuProcess.Unix.cpp +++ b/Source/Processes/AuProcess.Unix.cpp @@ -524,7 +524,7 @@ namespace Aurora::Processes { if (auto pThat = this->GetErrorStreamHandle()) { - if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat)) + if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandleShared(pThat)) { return { pThat2, pThat2->ToStreamReader() }; } @@ -534,7 +534,7 @@ namespace Aurora::Processes { if (auto pThat = this->GetOutputAndInputHandles()) { - if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat)) + if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandleShared(pThat)) { return { pThat2, pThat2->ToStreamReader() }; } @@ -548,7 +548,7 @@ namespace Aurora::Processes { if (auto pThat = this->GetErrorStreamHandle()) { - if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandle(pThat)) + if (auto pThat2 = AuFS::OpenBlockingFileStreamFromHandleShared(pThat)) { return { pThat2, pThat2->ToStreamWriter() }; }