37 lines
995 B
C++
37 lines
995 B
C++
#pragma once
|
|
// Runs safari_server next to the client executable for "Host & Play".
|
|
// The child's stdin is a pipe: stop() sends the console command `quit` so the
|
|
// server saves and exits cleanly on every platform (Windows has no SIGTERM),
|
|
// and only kills it if it does not exit in time. Its output goes to a log file.
|
|
|
|
#include "Paths.h"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace bs {
|
|
|
|
class LocalServer {
|
|
public:
|
|
LocalServer() = default;
|
|
LocalServer(const LocalServer&) = delete;
|
|
LocalServer& operator=(const LocalServer&) = delete;
|
|
~LocalServer() { stop(); }
|
|
|
|
// Starts `safari_server --port <port> --name <name>`; false + `error` on failure.
|
|
bool start(uint16_t port, const std::string& name, std::string& error);
|
|
void stop();
|
|
bool running() const;
|
|
|
|
private:
|
|
#if defined(_WIN32)
|
|
void* process_ = nullptr; // HANDLE
|
|
void* stdin_ = nullptr; // HANDLE (write end)
|
|
#else
|
|
int pid_ = -1;
|
|
int stdin_ = -1;
|
|
#endif
|
|
};
|
|
|
|
} // namespace bs
|