/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuIPCPipe.Unix.hpp Date: 2022-4-14 Author: Reece ***/ #pragma once #include #include #include #if defined(AURORA_IS_LINUX_DERIVED) #include #include #include "AuIPCPrimitives.Linux.hpp" #include "AuIPCMutexFutex.Linux.hpp" #endif #include "AuIPCMemory.Unix.hpp" // required for handle namespace Aurora::IO::IPC { struct IPCPipeImpl : IPCPipe, Loop::LSHandle, AuEnableSharedFromThis #if defined(AURORA_IS_LINUX_DERIVED) , IMutexClosedHook #endif { IPCPipeImpl(int (fds)[2], int (secondary)[2], IPCToken readEnd, IPCToken writeEnd, AuSPtr event, AuSPtr mutex); ~IPCPipeImpl(); #if defined(AURORA_IS_LINUX_DERIVED) inline virtual void OnPresleep() override { Loop::LSHandle::OnPresleep(); }; inline virtual void OnFinishSleep() override { Loop::LSHandle:: OnFinishSleep(); } inline virtual AuUInt GetHandle() override { return Loop::LSHandle:: GetHandle(); } inline bool HasValidHandle() { return Loop::LSHandle:: HasValidHandle(); } #else PROXY_INTERNAL_INTERFACE_(LSHandle::) #endif virtual AuSPtr NewAsyncTransaction() override; virtual AuSPtr AsReadChannelIsOpen() override; virtual AuSPtr AsReadChannelHasData() override; virtual bool Read(const Memory::MemoryViewStreamWrite &write, bool nonblock) override; virtual bool Write(const Memory::MemoryViewStreamRead &read) override; virtual AuString ExportToString() override; bool IsSignaled() override; bool WaitOn(AuUInt32 timeout) override; Loop::ELoopSource GetType() override; #if defined(AURORA_IS_LINUX_DERIVED) bool OnClosed() override; virtual const AuList &GetHandles() override; virtual bool Singular() override; virtual bool OnTrigger(AuUInt handle) override; #endif bool LIOS_PopOne(); void DrainOtherFd(); AuUInt GetPreemptFd(); bool bIsSendingZero {}; private: int fds[2] {-1, -1}; int secondary[2] {-1, -1}; AuSPtr fsHandle_; AuSPtr fsStream_; void SendTerminateSignal(); AuList handles; IPCToken readEnd_; IPCToken writeEnd_; AuSPtr event_; AuSPtr mutex_; AuLoop::LSEvent eventPreempt_; bool bHasDied {}; void FinishFinalize(); }; }