fix windows build

This commit is contained in:
Xuan Son Nguyen 2025-11-19 22:30:47 +01:00
parent abc0ca478a
commit 54b3545791
2 changed files with 10 additions and 8 deletions

View File

@ -210,7 +210,7 @@ void server_models::load(const std::string & name) {
inst.meta.port = get_free_port(base_params.hostname);
inst.meta.status = SERVER_MODEL_STATUS_LOADING;
process_handle_t child_pid = SERVER_DEFAULT_PID;
PROCESS_HANDLE_T child_pid = SERVER_DEFAULT_PID;
{
std::string exec_path = get_server_exec_path().string();
SRV_INF("spawning server instance with name=%s on port %d\n", inst.meta.name.c_str(), inst.meta.port);

View File

@ -7,17 +7,19 @@
#include <mutex>
#include <condition_variable>
// pid_t is defined in <sys/types.h> on POSIX systems. On Windows, this
// header doesn't exist and the server code is not expected to build/run,
// but provide a minimal fallback typedef to avoid include errors when this
// header is parsed in non-POSIX builds.
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <windows.h>
#define SERVER_DEFAULT_PID NULL
using process_handle_t = HANDLE;
#define PROCESS_HANDLE_T HANDLE
#else
#include <sys/types.h>
#define SERVER_DEFAULT_PID 0
using process_handle_t = pid_t;
#define PROCESS_HANDLE_T pid_t
#endif
enum server_model_status {
@ -63,7 +65,7 @@ struct server_model_meta {
struct server_models {
private:
struct instance_t {
process_handle_t pid = SERVER_DEFAULT_PID;
PROCESS_HANDLE_T pid = SERVER_DEFAULT_PID;
std::thread th;
server_model_meta meta;
};