[+] IPCPipeWriter

[+] IPCPipeReader
This commit is contained in:
Reece Wilson 2023-10-21 10:39:47 +01:00
parent c79993af74
commit 4d454287b8
8 changed files with 171 additions and 16 deletions

View File

@ -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<AuFS::FileReader>(this->fsBlockingStream_);
this->fsStreamWriter_ = AuMakeSharedPanic<AuFS::FileWriter>(this->fsBlockingStream_);
this->fsStream_->Init(this->fsHandle_);
TryConnect();
@ -347,12 +348,12 @@ namespace Aurora::IO::IPC
AuSPtr<IStreamReader> IPCPipeImpl::ToStreamReader()
{
return this->fsStreamReader_;
return AuSPtr<IStreamReader>(this->SharedFromThis(), &this->pipeReader_);
}
AuSPtr<IStreamWriter> IPCPipeImpl::ToStreamWriter()
{
return this->fsStreamWriter_;
return AuSPtr<IStreamWriter>(this->SharedFromThis(), &this->pipeWriter_);
}
AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uBytesLength)

View File

@ -12,6 +12,9 @@
#include <Source/IO/IPC/AuIPCHandle.hpp>
#include <Source/IO/Loop/LSHandle.hpp>
#include "AuIPCPipeWriter.hpp"
#include "AuIPCPipeReader.hpp"
namespace Aurora::IO::FS
{
struct NtAsyncFileStream;
@ -67,7 +70,7 @@ namespace Aurora::IO::IPC
AuSPtr<IPCHasConnectionEvent> lshasConnection_;
bool bFirstTime {true};
AuSPtr<IO::FS::IFileStream> fsBlockingStream_;
AuSPtr<IO::IStreamReader> fsStreamReader_;
AuSPtr<IO::IStreamWriter> fsStreamWriter_;
IPCPipeReader pipeReader_;
IPCPipeWriter pipeWriter_;
};
}

View File

@ -149,7 +149,9 @@ namespace Aurora::IO::IPC
IPCPipeImpl::IPCPipeImpl(int (fds2)[2], int (fds3)[2], IPCToken readEnd, IPCToken writeEnd, AuSPtr<IPCEvent> event, AuSPtr<IPCMutex> 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<AuFS::FileReader>(this->fsBlockingStream_);
this->fsStreamWriter_ = AuMakeSharedPanic<AuFS::FileWriter>(this->fsBlockingStream_);
}
AuSPtr<Loop::ILoopSource> IPCPipeImpl::AsReadChannelIsOpen()
@ -377,12 +376,12 @@ namespace Aurora::IO::IPC
AuSPtr<IStreamReader> IPCPipeImpl::ToStreamReader()
{
return this->fsStreamReader_;
return AuSPtr<IStreamReader>(this->SharedFromThis(), &this->pipeReader_);
}
AuSPtr<IStreamWriter> IPCPipeImpl::ToStreamWriter()
{
return this->fsStreamWriter_;
return AuSPtr<IStreamWriter>(this->SharedFromThis(), &this->pipeWriter_);
}
AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uPipeLength)

View File

@ -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<IPCPipeImpl>
@ -110,8 +113,8 @@ namespace Aurora::IO::IPC
bool bHasDied {};
AuSPtr<IO::FS::IFileStream> fsBlockingStream_;
AuSPtr<IO::IStreamReader> fsStreamReader_;
AuSPtr<IO::IStreamWriter> fsStreamWriter_;
IPCPipeReader pipeReader_;
IPCPipeWriter pipeWriter_;
void FinishFinalize();
};

View File

@ -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 <Source/RuntimeInternal.hpp>
#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 &parameters)
{
if (this->pParent->Read(parameters, true))
{
return EStreamError::eErrorNone;
}
return EStreamError::eErrorStreamInterrupted;
}
void IPCPipeReader::Close()
{
}
}

View File

@ -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 &parameters) override;
void Close() override;
IPCPipe *pParent;
};
}

View File

@ -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 <Source/RuntimeInternal.hpp>
#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 &parameters)
{
if (this->pParent->Write(parameters))
{
return EStreamError::eErrorNone;
}
return EStreamError::eErrorStreamInterrupted;
}
void IPCPipeWriter::Flush()
{
}
void IPCPipeWriter::Close()
{
}
}

View File

@ -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 &parameters) override;
void Close() override;
void Flush() override;
IPCPipe *pParent;
};
}