System: Windows process and handle support for the runner subset (closes #40)
This commit is contained in:
1 parent
7cfd30e550
commit
29b46839fd
7 files changed
+2754
-294
No files matched your search
+4
-290
@@ -20,295 +20,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
namespace Void::Process
|
||||
{
|
||||
|
||||
Child::Child(long long,
|
||||
long long,
|
||||
bool,
|
||||
Void::System::OwnedFd,
|
||||
Void::System::OwnedFd,
|
||||
Void::System::OwnedFd,
|
||||
std::chrono::milliseconds) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
Child::~Child() noexcept = default;
|
||||
Child::Child(Child&&) noexcept = default;
|
||||
Child& Child::operator=(Child&&) noexcept = default;
|
||||
bool Child::valid() const noexcept { return false; }
|
||||
bool Child::running() const noexcept { return false; }
|
||||
bool Child::process_group_alive() const noexcept { return false; }
|
||||
long long Child::pid() const noexcept { return -1; }
|
||||
long long Child::pgid() const noexcept { return -1; }
|
||||
bool Child::owns_process_group() const noexcept { return false; }
|
||||
int Child::stdin_fd() const noexcept { return -1; }
|
||||
int Child::stdout_fd() const noexcept { return -1; }
|
||||
int Child::stderr_fd() const noexcept { return -1; }
|
||||
Void::System::OwnedFd Child::take_stdin_fd() noexcept { return {}; }
|
||||
Void::System::OwnedFd Child::take_stdout_fd() noexcept { return {}; }
|
||||
Void::System::OwnedFd Child::take_stderr_fd() noexcept { return {}; }
|
||||
void Child::close_stdin() noexcept {}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> Child::send_signal(int) noexcept
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::Child::send_signal: not implemented on Windows")};
|
||||
}
|
||||
|
||||
Void::Result::Result<ExitStatus, Void::Result::Error>
|
||||
Child::terminate(std::chrono::milliseconds)
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::Child::terminate: not implemented on Windows")};
|
||||
}
|
||||
|
||||
Void::Result::Result<std::optional<ExitStatus>, Void::Result::Error>
|
||||
Child::try_wait()
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::Child::try_wait: not implemented on Windows")};
|
||||
}
|
||||
|
||||
Void::Result::Result<ExitStatus, Void::Result::Error>
|
||||
Child::wait_blocking(std::chrono::milliseconds,
|
||||
std::stop_token,
|
||||
std::chrono::milliseconds)
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::Child::wait_blocking: not implemented on Windows")};
|
||||
}
|
||||
|
||||
Void::Result::Result<Child, Void::Result::Error> spawn(const SpawnOptions&)
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::spawn: not implemented on Windows")};
|
||||
}
|
||||
|
||||
BinarySession::BinarySession(Child child, BinarySessionOptions options)
|
||||
: child_(std::move(child)), options_(options)
|
||||
{
|
||||
}
|
||||
|
||||
BinarySession::~BinarySession() noexcept = default;
|
||||
|
||||
BinarySession::BinarySession(BinarySession&& other) noexcept
|
||||
: child_(std::move(other.child_)),
|
||||
stdin_(std::move(other.stdin_)),
|
||||
stdout_(std::move(other.stdout_)),
|
||||
stderr_(std::move(other.stderr_)),
|
||||
stdout_buffer_(std::move(other.stdout_buffer_)),
|
||||
stdout_offset_(std::exchange(other.stdout_offset_, 0)),
|
||||
stderr_buffer_(std::move(other.stderr_buffer_)),
|
||||
stderr_offset_(std::exchange(other.stderr_offset_, 0)),
|
||||
stdout_eof_(other.stdout_eof_),
|
||||
stderr_eof_(other.stderr_eof_),
|
||||
stdin_closed_(other.stdin_closed_),
|
||||
stdout_truncated_(other.stdout_truncated_),
|
||||
stderr_truncated_(other.stderr_truncated_),
|
||||
options_(other.options_),
|
||||
cancelled_(other.cancelled_.exchange(false)),
|
||||
status_(other.status_),
|
||||
reaped_(other.reaped_)
|
||||
{
|
||||
other.stdout_eof_ = true;
|
||||
other.stderr_eof_ = true;
|
||||
other.stdin_closed_ = true;
|
||||
other.reaped_ = true;
|
||||
}
|
||||
|
||||
BinarySession& BinarySession::operator=(BinarySession&& other) noexcept
|
||||
{
|
||||
if (this != &other) {
|
||||
child_ = std::move(other.child_);
|
||||
stdin_ = std::move(other.stdin_);
|
||||
stdout_ = std::move(other.stdout_);
|
||||
stderr_ = std::move(other.stderr_);
|
||||
stdout_buffer_ = std::move(other.stdout_buffer_);
|
||||
stdout_offset_ = std::exchange(other.stdout_offset_, 0);
|
||||
stderr_buffer_ = std::move(other.stderr_buffer_);
|
||||
stderr_offset_ = std::exchange(other.stderr_offset_, 0);
|
||||
stdout_eof_ = other.stdout_eof_;
|
||||
stderr_eof_ = other.stderr_eof_;
|
||||
stdin_closed_ = other.stdin_closed_;
|
||||
stdout_truncated_ = other.stdout_truncated_;
|
||||
stderr_truncated_ = other.stderr_truncated_;
|
||||
options_ = other.options_;
|
||||
cancelled_.store(other.cancelled_.exchange(false));
|
||||
status_ = other.status_;
|
||||
reaped_ = other.reaped_;
|
||||
other.stdout_eof_ = true;
|
||||
other.stderr_eof_ = true;
|
||||
other.stdin_closed_ = true;
|
||||
other.reaped_ = true;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Void::Result::Result<BinarySession, Void::Result::Error>
|
||||
BinarySession::spawn(const SpawnOptions&, BinarySessionOptions)
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession: not implemented on Windows")};
|
||||
}
|
||||
|
||||
bool BinarySession::valid() const noexcept { return false; }
|
||||
|
||||
Void::Result::Result<BinaryTransfer, BinaryError> BinarySession::write_stdin(
|
||||
std::span<const std::byte>, std::chrono::milliseconds, std::stop_token)
|
||||
{
|
||||
return std::unexpected{BinaryError{
|
||||
0,
|
||||
false,
|
||||
BinaryFailureCode::io_error,
|
||||
Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession::write_stdin: not implemented on Windows")}};
|
||||
}
|
||||
|
||||
Void::Result::Result<BinaryTransfer, BinaryError> BinarySession::read_stdout(
|
||||
std::span<std::byte>, std::chrono::milliseconds, std::stop_token)
|
||||
{
|
||||
return std::unexpected{BinaryError{
|
||||
0,
|
||||
false,
|
||||
BinaryFailureCode::io_error,
|
||||
Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession::read_stdout: not implemented on Windows")}};
|
||||
}
|
||||
|
||||
Void::Result::Result<BinaryTransfer, BinaryError> BinarySession::read_stderr(
|
||||
std::span<std::byte>, std::chrono::milliseconds, std::stop_token)
|
||||
{
|
||||
return std::unexpected{BinaryError{
|
||||
0,
|
||||
false,
|
||||
BinaryFailureCode::io_error,
|
||||
Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession::read_stderr: not implemented on Windows")}};
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> BinarySession::close_stdin()
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession::close_stdin: not implemented on Windows")};
|
||||
}
|
||||
|
||||
Void::Result::Result<ExitStatus, Void::Result::Error> BinarySession::wait(
|
||||
std::chrono::milliseconds, std::stop_token)
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession::wait: not implemented on Windows")};
|
||||
}
|
||||
|
||||
Void::Result::Result<ExitStatus, Void::Result::Error> BinarySession::terminate(
|
||||
std::chrono::milliseconds)
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession::terminate: not implemented on Windows")};
|
||||
}
|
||||
|
||||
BinarySession::PollFill BinarySession::poll_fill(int,
|
||||
std::span<const std::byte>,
|
||||
std::size_t&,
|
||||
bool)
|
||||
{
|
||||
PollFill result;
|
||||
result.failure = BinaryFailureCode::io_error;
|
||||
result.error = Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession: not implemented on Windows");
|
||||
return result;
|
||||
}
|
||||
|
||||
Void::Result::Result<BinaryTransfer, BinaryError> BinarySession::read_stream(
|
||||
bool, std::span<std::byte>, std::chrono::milliseconds, std::stop_token)
|
||||
{
|
||||
return std::unexpected{BinaryError{
|
||||
0,
|
||||
false,
|
||||
BinaryFailureCode::io_error,
|
||||
Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::BinarySession: not implemented on Windows")}};
|
||||
}
|
||||
|
||||
void BinarySession::note_exit() noexcept {}
|
||||
|
||||
Void::Result::Result<CommunicateResult, Void::Result::Error>
|
||||
communicate_blocking(Child&,
|
||||
std::string_view,
|
||||
CaptureLimits,
|
||||
std::chrono::milliseconds,
|
||||
std::stop_token,
|
||||
const StreamCallbacks*)
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::communicate_blocking: not implemented on Windows")};
|
||||
}
|
||||
|
||||
Void::Result::Result<Output, Void::Result::Error> run(
|
||||
const std::filesystem::path&,
|
||||
std::vector<std::string>,
|
||||
std::string_view,
|
||||
std::chrono::milliseconds)
|
||||
{
|
||||
return Void::Result::fail("Process::run: not implemented on Windows");
|
||||
}
|
||||
|
||||
Void::Result::Result<Output, Void::Result::Error> run_streaming(
|
||||
const std::filesystem::path&,
|
||||
std::vector<std::string>,
|
||||
const StreamCallbacks&,
|
||||
std::string_view,
|
||||
std::chrono::milliseconds)
|
||||
{
|
||||
return Void::Result::fail(
|
||||
"Process::run_streaming: not implemented on Windows");
|
||||
}
|
||||
|
||||
Void::Result::Result<Output, Void::Result::Error>
|
||||
shell(std::string_view, std::chrono::milliseconds)
|
||||
{
|
||||
return Void::Result::fail("Process::shell: not implemented on Windows");
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
reexec(const std::filesystem::path&, const std::vector<std::string>&)
|
||||
{
|
||||
return Void::Result::fail("Process::reexec: not implemented on Windows");
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> reexec(
|
||||
const std::filesystem::path&, const std::vector<std::string>&, bool)
|
||||
{
|
||||
return Void::Result::fail("Process::reexec: not implemented on Windows");
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> enable_subreaper() noexcept
|
||||
{
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::unsupported,
|
||||
"Process::enable_subreaper: not supported on Windows")};
|
||||
}
|
||||
|
||||
} // namespace Void::Process
|
||||
|
||||
#else // POSIX
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
@@ -896,6 +608,8 @@ void emit_lines_from_offset(const std::string& buf,
|
||||
|
||||
} // namespace
|
||||
|
||||
Child::Child() noexcept = default;
|
||||
|
||||
Child::Child(long long pid,
|
||||
long long pgid,
|
||||
bool owns_process_group,
|
||||
@@ -2511,4 +2225,4 @@ Void::Result::Result<void, Void::Result::Error> enable_subreaper() noexcept
|
||||
|
||||
} // namespace Void::Process
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // !_WIN32
|
||||
Reference in new issue
Block a user