108 lines
3.0 KiB
C++
108 lines
3.0 KiB
C++
/***
|
|
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 <Source/IO/Loop/ILoopSourceEx.hpp>
|
|
#include <Source/IO/Loop/LSHandle.hpp>
|
|
#include <Source/IO/Loop/LSEvent.hpp>
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
#include <Source/IO/UNIX/IOSubmit.Linux.hpp>
|
|
#include <Source/IO/FS/Async.Linux.hpp>
|
|
#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<IPCPipeImpl>
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
, IMutexClosedHook
|
|
#endif
|
|
{
|
|
IPCPipeImpl(int (fds)[2], int (secondary)[2], IPCToken readEnd, IPCToken writeEnd, AuSPtr<IPCEvent> event, AuSPtr<IPCMutex> 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<IO::IAsyncTransaction> NewAsyncTransaction() override;
|
|
virtual AuSPtr<IO::IIOHandle> GetCurrentSharedDuplexHandles() override;
|
|
|
|
virtual AuSPtr<Loop::ILoopSource> AsReadChannelIsOpen() override;
|
|
virtual AuSPtr<Loop::ILoopSource> 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<AuUInt> &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<IO::IIOHandle> fsHandle_;
|
|
AuSPtr<IO::FS::LinuxAsyncFileStream> fsStream_;
|
|
|
|
void SendTerminateSignal();
|
|
|
|
AuList<AuUInt> handles;
|
|
|
|
|
|
IPCToken readEnd_;
|
|
IPCToken writeEnd_;
|
|
|
|
AuSPtr<IPCEvent> event_;
|
|
AuSPtr<IPCMutex> mutex_;
|
|
|
|
AuLoop::LSEvent eventPreempt_;
|
|
|
|
bool bHasDied {};
|
|
|
|
void FinishFinalize();
|
|
};
|
|
} |