VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 5s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 22s
69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
|
|
#include <chrono>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <memory>
|
|
#include <stop_token>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace Void::Build::Daemon {
|
|
|
|
struct DaemonOptions {
|
|
std::filesystem::path project_root;
|
|
std::filesystem::path build_root;
|
|
std::filesystem::path lock_root; // Empty => project_root (workspace members share a root lock)
|
|
std::filesystem::path socket_path; // empty => build_root/".vbs/vbs-daemon.sock"
|
|
std::chrono::milliseconds poll_interval{200};
|
|
std::size_t max_requests{0}; // 0 => unlimited
|
|
};
|
|
|
|
struct DaemonStatus {
|
|
std::uint64_t pid{};
|
|
std::uint64_t uptime_ms{};
|
|
std::size_t recorded_actions{};
|
|
std::size_t watched_directories{};
|
|
std::uint64_t watch_events{};
|
|
std::string last_event_path;
|
|
std::uint64_t sequence{};
|
|
};
|
|
|
|
// Bounded single-threaded Unix-domain-socket daemon holding a warm StateStore and
|
|
// InotifyWatcher for the project root (Track E3). Requests are one JSON object per
|
|
// line; responses are one JSON object per line.
|
|
class DaemonServer {
|
|
public:
|
|
~DaemonServer();
|
|
DaemonServer(const DaemonServer &) = delete;
|
|
DaemonServer &operator=(const DaemonServer &) = delete;
|
|
DaemonServer(DaemonServer &&) noexcept;
|
|
DaemonServer &operator=(DaemonServer &&) noexcept;
|
|
|
|
[[nodiscard]] static Void::Result::Result<DaemonServer, Void::Result::Error>
|
|
create(DaemonOptions options);
|
|
|
|
// Serves until `stop` is requested, a `shutdown` request arrives, or max_requests is hit.
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error> run(std::stop_token stop = {});
|
|
|
|
[[nodiscard]] const std::filesystem::path &socket_path() const noexcept;
|
|
[[nodiscard]] DaemonStatus status() const;
|
|
|
|
private:
|
|
struct Impl;
|
|
explicit DaemonServer(std::unique_ptr<Impl> impl) noexcept;
|
|
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
|
|
// Sends one newline-delimited JSON request and returns the response line.
|
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
|
request(const std::filesystem::path &socket_path, std::string_view request_json,
|
|
std::chrono::milliseconds timeout = std::chrono::milliseconds{2000});
|
|
|
|
} // namespace Void::Build::Daemon
|