add Unix Socket API
This commit is contained in:
29
SocketServer.h
Normal file
29
SocketServer.h
Normal 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_;
|
||||
};
|
||||
Reference in New Issue
Block a user