2022-04-15 10:01:43 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-12-14 05:03:37 +00:00
|
|
|
File: AuIPCPipe.Unix.hpp
|
2022-04-15 10:01:43 +00:00
|
|
|
Date: 2022-4-14
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-08-09 06:48:29 +00:00
|
|
|
#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>
|
2022-12-16 00:41:01 +00:00
|
|
|
#include "AuIPCPrimitives.Linux.hpp"
|
|
|
|
#include "AuIPCMutexFutex.Linux.hpp"
|
2022-08-09 06:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2022-12-16 00:41:01 +00:00
|
|
|
#include "AuIPCMemory.Unix.hpp" // required for handle
|
2022-08-09 06:48:29 +00:00
|
|
|
|
2023-10-21 09:39:47 +00:00
|
|
|
#include "AuIPCPipeWriter.hpp"
|
|
|
|
#include "AuIPCPipeReader.hpp"
|
|
|
|
|
2022-06-11 23:52:46 +00:00
|
|
|
namespace Aurora::IO::IPC
|
2022-04-15 10:01:43 +00:00
|
|
|
{
|
2022-08-09 06:48:29 +00:00
|
|
|
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;
|
2023-08-11 15:51:42 +00:00
|
|
|
virtual AuSPtr<IO::IIOHandle> GetCurrentSharedDuplexHandles() override;
|
|
|
|
|
2022-08-09 06:48:29 +00:00
|
|
|
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;
|
|
|
|
|
2023-10-20 15:33:18 +00:00
|
|
|
virtual AuSPtr<IO::FS::IFileStream> ToFileStream() override;
|
|
|
|
virtual AuSPtr<IStreamReader> ToStreamReader() override;
|
|
|
|
virtual AuSPtr<IStreamWriter> ToStreamWriter() override;
|
|
|
|
|
2023-09-16 22:30:10 +00:00
|
|
|
bool ReadEx(const Memory::MemoryViewStreamWrite &write, bool nonblock, bool bSide);
|
|
|
|
|
2022-08-09 06:48:29 +00:00
|
|
|
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 {};
|
2023-12-16 21:08:46 +00:00
|
|
|
bool bDead {};
|
2022-08-09 06:48:29 +00:00
|
|
|
private:
|
|
|
|
int fds[2] {-1, -1};
|
|
|
|
int secondary[2] {-1, -1};
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
AuSPtr<IO::IIOHandle> fsHandle_;
|
2022-08-09 06:48:29 +00:00
|
|
|
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 {};
|
2022-04-15 10:01:43 +00:00
|
|
|
|
2023-10-20 15:33:18 +00:00
|
|
|
AuSPtr<IO::FS::IFileStream> fsBlockingStream_;
|
2023-10-21 09:39:47 +00:00
|
|
|
IPCPipeReader pipeReader_;
|
|
|
|
IPCPipeWriter pipeWriter_;
|
2023-10-20 15:33:18 +00:00
|
|
|
|
2022-08-09 06:48:29 +00:00
|
|
|
void FinishFinalize();
|
|
|
|
};
|
2022-04-15 10:01:43 +00:00
|
|
|
}
|