AuroraRuntime/Source/Processes/Process.Unix.hpp

88 lines
2.2 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Process.Unix.hpp
2021-06-27 21:25:29 +00:00
File: Process.Linux.hpp
Date: 2021-6-12
Author: Reece
***/
#pragma once
2022-06-12 13:53:35 +00:00
#include <Source/IO/Loop/LSEvent.hpp>
#include <Source/IO/FS/FS.hpp>
#if defined(AURORA_IS_LINUX_DERIVED)
#include <Source/IO/UNIX/IOSubmit.Linux.hpp>
#include <Source/IO/FS/Async.Linux.hpp>
using ProcessPipeFileStream = Aurora::IO::FS::LinuxAsyncFileStream;
#else
#include <Source/IO/FS/Async.Unix.hpp>
using ProcessPipeFileStream = Aurora::IO::FS::UnixAsyncFileStream;
#endif
namespace Aurora::Processes
{
void DeinitUnix();
void InitUnix();
2022-04-05 10:18:35 +00:00
struct ProcessImpl : IProcess
2022-04-05 10:18:35 +00:00
{
ProcessImpl(const StartupParmaters &params);
~ProcessImpl();
void ShutdownPipes();
bool TryKill() override;
bool Terminate() override;
AuSPtr<Threading::IWaitable> AsWaitable() override;
2022-06-12 13:53:35 +00:00
AuSPtr<IO::Loop::ILoopSource> AsLoopSource() override;
2022-04-05 10:18:35 +00:00
AuSInt GetExitCode() override;
AuUInt GetProcessId() override;
bool Read(EStandardHandle stream, const AuMemoryViewStreamWrite &destination, bool nonblock) override;
bool Write(const AuMemoryViewStreamRead &source) override;
AuSPtr<IO::IAsyncTransaction> NewAsyncTransaction() override;
AuSPtr<IO::IAsyncTransaction> NewErrorStreamAsyncTransaction() override;
2022-04-05 10:18:35 +00:00
bool Start() override;
bool Init();
void ByeLol(AuSInt code);
void ForkMain();
2022-04-05 10:18:35 +00:00
private:
int pipeStdOut_[2]{};
int pipeStdErr_[2]{};
int pipeStdIn_ [2]{};
2022-06-23 12:25:20 +00:00
bool bDontRelOut_ {};
bool bDontRelIn_ {};
bool bDontRelErr_ {};
2022-06-12 13:53:35 +00:00
AuSPtr<IO::Loop::ILSEvent> loopSource_;
AuSPtr<IO::FS::FileHandle> fsHandle_;
AuSPtr<ProcessPipeFileStream> fsStream_;
AuSPtr<IO::FS::FileHandle> fsErrorHandle_;
AuSPtr<ProcessPipeFileStream> fsErrorStream_;
2022-04-05 10:18:35 +00:00
AuThreadPrimitives::EventShared_t finished_;
StartupParmaters startup_;
ESpawnType type_;
AuList<const char *> cargs_;
AuString debug_;
pid_t pidt_;
bool alive_ {};
AuSInt exitCode_;
};
}