aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/platform/unix/PosixSpawnSubProcess.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-10-06 13:57:39 +0800
committercrupest <crupest@outlook.com>2024-10-06 13:57:39 +0800
commitdfe62dcf8bcefc523b466e127c3edc4dc2756629 (patch)
tree1c751a14ba0da07ca2ff805633f97568060aa4c9 /include/cru/base/platform/unix/PosixSpawnSubProcess.h
parentf51eb955e188858272230a990565931e7403f23b (diff)
downloadcru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.gz
cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.bz2
cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.zip
Rename common to base.
Diffstat (limited to 'include/cru/base/platform/unix/PosixSpawnSubProcess.h')
-rw-r--r--include/cru/base/platform/unix/PosixSpawnSubProcess.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/cru/base/platform/unix/PosixSpawnSubProcess.h b/include/cru/base/platform/unix/PosixSpawnSubProcess.h
new file mode 100644
index 00000000..ee4e912a
--- /dev/null
+++ b/include/cru/base/platform/unix/PosixSpawnSubProcess.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include "../../PreConfig.h"
+
+#ifndef CRU_PLATFORM_UNIX
+#error "This file can only be included on unix."
+#endif
+
+#include "../../Base.h"
+#include "../../SubProcess.h"
+#include "../../io/AutoReadStream.h"
+
+#include "UnixFileStream.h"
+#include "UnixPipe.h"
+
+#include <spawn.h>
+
+namespace cru::platform::unix {
+class PosixSpawnSubProcessImpl : public Object,
+ public virtual IPlatformSubProcessImpl {
+ CRU_DEFINE_CLASS_LOG_TAG(u"PosixSpawnSubProcess")
+
+ public:
+ explicit PosixSpawnSubProcessImpl();
+ ~PosixSpawnSubProcessImpl();
+
+ void PlatformCreateProcess(const SubProcessStartInfo& start_info) override;
+ SubProcessExitResult PlatformWaitForProcess() override;
+ void PlatformKillProcess() override;
+
+ io::Stream* GetStdinStream() override;
+ io::Stream* GetStdoutStream() override;
+ io::Stream* GetStderrStream() override;
+
+ private:
+ pid_t pid_;
+ int exit_code_;
+
+ UnixPipe stdin_pipe_;
+ UnixPipe stdout_pipe_;
+ UnixPipe stderr_pipe_;
+
+ std::unique_ptr<UnixFileStream> stdin_stream_;
+ std::unique_ptr<UnixFileStream> stdout_stream_;
+ std::unique_ptr<UnixFileStream> stderr_stream_;
+
+ std::unique_ptr<io::AutoReadStream> stdout_buffer_stream_;
+ std::unique_ptr<io::AutoReadStream> stderr_buffer_stream_;
+};
+} // namespace cru::platform::unix