add Unix Socket API

This commit is contained in:
Maik Jurischka
2025-12-12 10:46:49 +01:00
parent 2edffd5f76
commit fe0af4dc64
7 changed files with 1033 additions and 19 deletions

29
SocketServer.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include <string>
#include <functional>
#include <thread>
#include <atomic>
#include <memory>
class SocketServer {
public:
using CommandCallback = std::function<std::string(const std::string&)>;
explicit SocketServer(const std::string& socketPath);
~SocketServer();
bool start(CommandCallback callback);
void stop();
bool isRunning() const { return running_; }
private:
void serverLoop();
void handleClient(int clientFd);
std::string socketPath_;
int serverFd_;
std::atomic<bool> running_;
std::unique_ptr<std::thread> serverThread_;
CommandCallback commandCallback_;
};