From 4d454287b80f595a17fd5ea37968360c35219990 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 21 Oct 2023 10:39:47 +0100 Subject: [PATCH] [+] IPCPipeWriter [+] IPCPipeReader --- Source/IO/IPC/AuIPCPipe.NT.cpp | 13 ++++---- Source/IO/IPC/AuIPCPipe.NT.hpp | 7 +++-- Source/IO/IPC/AuIPCPipe.Unix.cpp | 11 +++---- Source/IO/IPC/AuIPCPipe.Unix.hpp | 7 +++-- Source/IO/IPC/AuIPCPipeReader.cpp | 52 +++++++++++++++++++++++++++++++ Source/IO/IPC/AuIPCPipeReader.hpp | 22 +++++++++++++ Source/IO/IPC/AuIPCPipeWriter.cpp | 52 +++++++++++++++++++++++++++++++ Source/IO/IPC/AuIPCPipeWriter.hpp | 23 ++++++++++++++ 8 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 Source/IO/IPC/AuIPCPipeReader.cpp create mode 100644 Source/IO/IPC/AuIPCPipeReader.hpp create mode 100644 Source/IO/IPC/AuIPCPipeWriter.cpp create mode 100644 Source/IO/IPC/AuIPCPipeWriter.hpp diff --git a/Source/IO/IPC/AuIPCPipe.NT.cpp b/Source/IO/IPC/AuIPCPipe.NT.cpp index fa0cf6ad..eee43f67 100644 --- a/Source/IO/IPC/AuIPCPipe.NT.cpp +++ b/Source/IO/IPC/AuIPCPipe.NT.cpp @@ -84,7 +84,11 @@ namespace Aurora::IO::IPC } IPCPipeImpl::IPCPipeImpl(HANDLE clientHandle, HANDLE serverHandle, const IPCHandle &handle) : - serverHandle_(serverHandle), clientHandle_(clientHandle), ipcHandle_(handle) + serverHandle_(serverHandle), + clientHandle_(clientHandle), + ipcHandle_(handle), + pipeReader_(this), + pipeWriter_(this) { if (serverHandle != INVALID_HANDLE_VALUE) { @@ -104,9 +108,6 @@ namespace Aurora::IO::IPC this->fsBlockingStream_ = AuFS::OpenBlockingFileStreamFromHandle(this->fsHandle_); SysAssert(this->fsBlockingStream_); - this->fsStreamReader_ = AuMakeSharedPanic(this->fsBlockingStream_); - this->fsStreamWriter_ = AuMakeSharedPanic(this->fsBlockingStream_); - this->fsStream_->Init(this->fsHandle_); TryConnect(); @@ -347,12 +348,12 @@ namespace Aurora::IO::IPC AuSPtr IPCPipeImpl::ToStreamReader() { - return this->fsStreamReader_; + return AuSPtr(this->SharedFromThis(), &this->pipeReader_); } AuSPtr IPCPipeImpl::ToStreamWriter() { - return this->fsStreamWriter_; + return AuSPtr(this->SharedFromThis(), &this->pipeWriter_); } AUKN_SYM AuSPtr NewPipeEx(AuUInt32 uBytesLength) diff --git a/Source/IO/IPC/AuIPCPipe.NT.hpp b/Source/IO/IPC/AuIPCPipe.NT.hpp index b7833304..df5977fc 100644 --- a/Source/IO/IPC/AuIPCPipe.NT.hpp +++ b/Source/IO/IPC/AuIPCPipe.NT.hpp @@ -12,6 +12,9 @@ #include #include +#include "AuIPCPipeWriter.hpp" +#include "AuIPCPipeReader.hpp" + namespace Aurora::IO::FS { struct NtAsyncFileStream; @@ -67,7 +70,7 @@ namespace Aurora::IO::IPC AuSPtr lshasConnection_; bool bFirstTime {true}; AuSPtr fsBlockingStream_; - AuSPtr fsStreamReader_; - AuSPtr fsStreamWriter_; + IPCPipeReader pipeReader_; + IPCPipeWriter pipeWriter_; }; } \ No newline at end of file diff --git a/Source/IO/IPC/AuIPCPipe.Unix.cpp b/Source/IO/IPC/AuIPCPipe.Unix.cpp index 576834d9..000a38da 100644 --- a/Source/IO/IPC/AuIPCPipe.Unix.cpp +++ b/Source/IO/IPC/AuIPCPipe.Unix.cpp @@ -149,7 +149,9 @@ namespace Aurora::IO::IPC IPCPipeImpl::IPCPipeImpl(int (fds2)[2], int (fds3)[2], IPCToken readEnd, IPCToken writeEnd, AuSPtr event, AuSPtr mutex) : fds {fds2[0], fds2[1]}, secondary {fds3[0], fds3[1]}, readEnd_(readEnd), writeEnd_(writeEnd), event_(event), mutex_(mutex), - eventPreempt_(false, false, true) + eventPreempt_(false, false, true, + pipeReader_(this), + pipeWriter_(this) { this->handles = {fds[0], eventPreempt_.GetHandle()}; @@ -173,9 +175,6 @@ namespace Aurora::IO::IPC this->fsBlockingStream_ = AuFS::OpenBlockingFileStreamFromHandle(this->fsHandle_); SysAssert(this->fsBlockingStream_); - - this->fsStreamReader_ = AuMakeSharedPanic(this->fsBlockingStream_); - this->fsStreamWriter_ = AuMakeSharedPanic(this->fsBlockingStream_); } AuSPtr IPCPipeImpl::AsReadChannelIsOpen() @@ -377,12 +376,12 @@ namespace Aurora::IO::IPC AuSPtr IPCPipeImpl::ToStreamReader() { - return this->fsStreamReader_; + return AuSPtr(this->SharedFromThis(), &this->pipeReader_); } AuSPtr IPCPipeImpl::ToStreamWriter() { - return this->fsStreamWriter_; + return AuSPtr(this->SharedFromThis(), &this->pipeWriter_); } AUKN_SYM AuSPtr NewPipeEx(AuUInt32 uPipeLength) diff --git a/Source/IO/IPC/AuIPCPipe.Unix.hpp b/Source/IO/IPC/AuIPCPipe.Unix.hpp index 0b4f8a7a..06525ba4 100644 --- a/Source/IO/IPC/AuIPCPipe.Unix.hpp +++ b/Source/IO/IPC/AuIPCPipe.Unix.hpp @@ -20,6 +20,9 @@ #include "AuIPCMemory.Unix.hpp" // required for handle +#include "AuIPCPipeWriter.hpp" +#include "AuIPCPipeReader.hpp" + namespace Aurora::IO::IPC { struct IPCPipeImpl : IPCPipe, Loop::LSHandle, AuEnableSharedFromThis @@ -110,8 +113,8 @@ namespace Aurora::IO::IPC bool bHasDied {}; AuSPtr fsBlockingStream_; - AuSPtr fsStreamReader_; - AuSPtr fsStreamWriter_; + IPCPipeReader pipeReader_; + IPCPipeWriter pipeWriter_; void FinishFinalize(); }; diff --git a/Source/IO/IPC/AuIPCPipeReader.cpp b/Source/IO/IPC/AuIPCPipeReader.cpp new file mode 100644 index 00000000..381d4609 --- /dev/null +++ b/Source/IO/IPC/AuIPCPipeReader.cpp @@ -0,0 +1,52 @@ +/*** + Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: AuIPCPipeReader.cpp + Date: 2023-10-21 + Author: Reece +***/ +#include +#include "IPC.hpp" +#include "AuIPCHandle.hpp" +#include "AuIPCPipeReader.hpp" + +namespace Aurora::IO::IPC +{ + IPCPipeReader::IPCPipeReader(IPCPipe *pPipe) : + pParent(pPipe) + { + + } + + EStreamError IPCPipeReader::IsOpen() + { + if (this->pParent->AsReadChannelHasData()->IsSignaled()) + { + return EStreamError::eErrorNone; + } + + auto pOpenChannel = this->pParent->AsReadChannelIsOpen(); + if (!pOpenChannel && + pOpenChannel->IsSignaled()) + { + return EStreamError::eErrorNone; + } + + return EStreamError::eErrorStreamNotOpen; + } + + EStreamError IPCPipeReader::Read(const Memory::MemoryViewStreamWrite ¶meters) + { + if (this->pParent->Read(parameters, true)) + { + return EStreamError::eErrorNone; + } + + return EStreamError::eErrorStreamInterrupted; + } + + void IPCPipeReader::Close() + { + + } +} \ No newline at end of file diff --git a/Source/IO/IPC/AuIPCPipeReader.hpp b/Source/IO/IPC/AuIPCPipeReader.hpp new file mode 100644 index 00000000..ad0f2420 --- /dev/null +++ b/Source/IO/IPC/AuIPCPipeReader.hpp @@ -0,0 +1,22 @@ +/*** + Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: AuIPCPipeReader.hpp + Date: 2023-10-21 + Author: Reece +***/ +#pragma once + +namespace Aurora::IO::IPC +{ + struct IPCPipeReader : IStreamReader + { + IPCPipeReader(IPCPipe *pPipe); + + EStreamError IsOpen() override; + EStreamError Read(const Memory::MemoryViewStreamWrite ¶meters) override; + void Close() override; + + IPCPipe *pParent; + }; +} \ No newline at end of file diff --git a/Source/IO/IPC/AuIPCPipeWriter.cpp b/Source/IO/IPC/AuIPCPipeWriter.cpp new file mode 100644 index 00000000..77dff44b --- /dev/null +++ b/Source/IO/IPC/AuIPCPipeWriter.cpp @@ -0,0 +1,52 @@ +/*** + Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: AuIPCPipeWriter.cpp + Date: 2023-10-21 + Author: Reece +***/ +#include +#include "IPC.hpp" +#include "AuIPCHandle.hpp" +#include "AuIPCPipeWriter.hpp" + +namespace Aurora::IO::IPC +{ + IPCPipeWriter::IPCPipeWriter(IPCPipe *pPipe) : + pParent(pPipe) + { + + } + + EStreamError IPCPipeWriter::IsOpen() + { + auto pOpenChannel = this->pParent->AsReadChannelIsOpen(); + if (!pOpenChannel && + pOpenChannel->IsSignaled()) + { + return EStreamError::eErrorNone; + } + + return EStreamError::eErrorStreamNotOpen; + } + + EStreamError IPCPipeWriter::Write(const Memory::MemoryViewStreamRead ¶meters) + { + if (this->pParent->Write(parameters)) + { + return EStreamError::eErrorNone; + } + + return EStreamError::eErrorStreamInterrupted; + } + + void IPCPipeWriter::Flush() + { + + } + + void IPCPipeWriter::Close() + { + + } +} \ No newline at end of file diff --git a/Source/IO/IPC/AuIPCPipeWriter.hpp b/Source/IO/IPC/AuIPCPipeWriter.hpp new file mode 100644 index 00000000..15b2f4aa --- /dev/null +++ b/Source/IO/IPC/AuIPCPipeWriter.hpp @@ -0,0 +1,23 @@ +/*** + Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: AuIPCPipeWriter.hpp + Date: 2023-10-21 + Author: Reece +***/ +#pragma once + +namespace Aurora::IO::IPC +{ + struct IPCPipeWriter : IStreamWriter + { + IPCPipeWriter(IPCPipe *pPipe); + + EStreamError IsOpen() override; + EStreamError Write(const Memory::MemoryViewStreamRead ¶meters) override; + void Close() override; + void Flush() override; + + IPCPipe *pParent; + }; +} \ No newline at end of file