[+] IPCPipe::ToFileStream

[+] IPCPipe::ToStreamReader
[+] IPCPipe::ToStreamWriter
This commit is contained in:
Reece Wilson 2023-10-20 16:33:18 +01:00
parent 88094c48ae
commit bd69ad6739
5 changed files with 78 additions and 2 deletions

View File

@ -57,6 +57,24 @@ namespace Aurora::IO::IPC
* @return * @return
*/ */
virtual bool Write(const Memory::MemoryViewStreamRead &read) = 0; virtual bool Write(const Memory::MemoryViewStreamRead &read) = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IO::FS::IFileStream> ToFileStream() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IStreamReader> ToStreamReader() = 0;
/**
* @brief
* @return
*/
virtual AuSPtr<IStreamWriter> ToStreamWriter() = 0;
}; };
/** /**

View File

@ -101,6 +101,12 @@ namespace Aurora::IO::IPC
AuStaticCast<AFileHandle>(this->fsHandle_)->bIsAsync = true; AuStaticCast<AFileHandle>(this->fsHandle_)->bIsAsync = true;
AuStaticCast<AFileHandle>(this->fsHandle_)->pIPCPipe = this; AuStaticCast<AFileHandle>(this->fsHandle_)->pIPCPipe = this;
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_); this->fsStream_->Init(this->fsHandle_);
TryConnect(); TryConnect();
@ -225,7 +231,6 @@ namespace Aurora::IO::IPC
return true; return true;
} }
OVERLAPPED a {}; OVERLAPPED a {};
a.hEvent = CreateEventA(NULL, true, 0, NULL); a.hEvent = CreateEventA(NULL, true, 0, NULL);
@ -335,6 +340,21 @@ namespace Aurora::IO::IPC
AuString {}; AuString {};
} }
AuSPtr<IO::FS::IFileStream> IPCPipeImpl::ToFileStream()
{
return this->fsBlockingStream_;
}
AuSPtr<IStreamReader> IPCPipeImpl::ToStreamReader()
{
return this->fsStreamReader_;
}
AuSPtr<IStreamWriter> IPCPipeImpl::ToStreamWriter()
{
return this->fsStreamWriter_;
}
AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uBytesLength) AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uBytesLength)
{ {
IPC::IPCHandle handle; IPC::IPCHandle handle;

View File

@ -22,7 +22,9 @@ namespace Aurora::IO::IPC
struct IPCHasConnectionEvent; struct IPCHasConnectionEvent;
struct IPCHandle; struct IPCHandle;
struct IPCPipeImpl : IPCPipe, Loop::LSHandle, AuEnableSharedFromThis<IPCPipeImpl> struct IPCPipeImpl : IPCPipe,
Loop::LSHandle,
AuEnableSharedFromThis<IPCPipeImpl>
{ {
IPCPipeImpl(HANDLE clientHandle, HANDLE serverHandle, const IPCHandle &handle); IPCPipeImpl(HANDLE clientHandle, HANDLE serverHandle, const IPCHandle &handle);
~IPCPipeImpl(); ~IPCPipeImpl();
@ -39,6 +41,10 @@ namespace Aurora::IO::IPC
virtual bool Write(const Memory::MemoryViewStreamRead &read) override; virtual bool Write(const Memory::MemoryViewStreamRead &read) override;
virtual AuString ExportToString() override; virtual AuString ExportToString() override;
virtual AuSPtr<IO::FS::IFileStream> ToFileStream() override;
virtual AuSPtr<IStreamReader> ToStreamReader() override;
virtual AuSPtr<IStreamWriter> ToStreamWriter() override;
bool IsSignaled() override; bool IsSignaled() override;
bool WaitOn(AuUInt32 timeout) override; bool WaitOn(AuUInt32 timeout) override;
Loop::ELoopSource GetType() override; Loop::ELoopSource GetType() override;
@ -60,5 +66,8 @@ namespace Aurora::IO::IPC
AuSPtr<IO::FS::NtAsyncFileStream> fsStream_; AuSPtr<IO::FS::NtAsyncFileStream> fsStream_;
AuSPtr<IPCHasConnectionEvent> lshasConnection_; AuSPtr<IPCHasConnectionEvent> lshasConnection_;
bool bFirstTime {true}; bool bFirstTime {true};
AuSPtr<IO::FS::IFileStream> fsBlockingStream_;
AuSPtr<IO::IStreamReader> fsStreamReader_;
AuSPtr<IO::IStreamWriter> fsStreamWriter_;
}; };
} }

View File

@ -170,6 +170,12 @@ namespace Aurora::IO::IPC
this->fsHandle_->InitFromPairMove(fds2[0], fds2[1]); this->fsHandle_->InitFromPairMove(fds2[0], fds2[1]);
this->fsStream_->Init(this->fsHandle_); this->fsStream_->Init(this->fsHandle_);
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() AuSPtr<Loop::ILoopSource> IPCPipeImpl::AsReadChannelIsOpen()
@ -364,6 +370,21 @@ namespace Aurora::IO::IPC
return handle.ToString(); return handle.ToString();
} }
AuSPtr<IO::FS::IFileStream> IPCPipeImpl::ToFileStream()
{
return this->fsBlockingStream_;
}
AuSPtr<IStreamReader> IPCPipeImpl::ToStreamReader()
{
return this->fsStreamReader_;
}
AuSPtr<IStreamWriter> IPCPipeImpl::ToStreamWriter()
{
return this->fsStreamWriter_;
}
AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uPipeLength) AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uPipeLength)
{ {
IPCToken readEnd, writeEnd; IPCToken readEnd, writeEnd;

View File

@ -62,6 +62,10 @@ namespace Aurora::IO::IPC
virtual bool Write(const Memory::MemoryViewStreamRead &read) override; virtual bool Write(const Memory::MemoryViewStreamRead &read) override;
virtual AuString ExportToString() override; virtual AuString ExportToString() override;
virtual AuSPtr<IO::FS::IFileStream> ToFileStream() override;
virtual AuSPtr<IStreamReader> ToStreamReader() override;
virtual AuSPtr<IStreamWriter> ToStreamWriter() override;
bool ReadEx(const Memory::MemoryViewStreamWrite &write, bool nonblock, bool bSide); bool ReadEx(const Memory::MemoryViewStreamWrite &write, bool nonblock, bool bSide);
bool IsSignaled() override; bool IsSignaled() override;
@ -105,6 +109,10 @@ namespace Aurora::IO::IPC
bool bHasDied {}; bool bHasDied {};
AuSPtr<IO::FS::IFileStream> fsBlockingStream_;
AuSPtr<IO::IStreamReader> fsStreamReader_;
AuSPtr<IO::IStreamWriter> fsStreamWriter_;
void FinishFinalize(); void FinishFinalize();
}; };
} }