stream optimizations

This commit is contained in:
Maik Jurischka
2025-12-12 14:37:57 +01:00
parent 43a1abdd31
commit 9c9f822f35
10 changed files with 168 additions and 24 deletions

View File

@@ -17,7 +17,7 @@ bool SocketServer::start(CommandCallback callback) {
return false;
}
commandCallback_ = callback;
commandCallback_ = std::move(callback);
// Remove existing socket file if it exists
unlink(socketPath_.c_str());
@@ -30,12 +30,11 @@ bool SocketServer::start(CommandCallback callback) {
}
// Bind socket
struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
struct sockaddr_un addr = {};
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, socketPath_.c_str(), sizeof(addr.sun_path) - 1);
if (bind(serverFd_, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
if (bind(serverFd_, reinterpret_cast<struct sockaddr *>(&addr), sizeof(addr)) < 0) {
std::cerr << "Failed to bind socket: " << strerror(errno) << std::endl;
close(serverFd_);
return false;
@@ -94,16 +93,16 @@ void SocketServer::serverLoop() {
}
}
void SocketServer::handleClient(int clientFd) {
void SocketServer::handleClient(const int clientFd) {
char buffer[4096];
ssize_t bytesRead = recv(clientFd, buffer, sizeof(buffer) - 1, 0);
if (bytesRead > 0) {
buffer[bytesRead] = '\0';
std::string command(buffer);
const std::string command(buffer);
// Call the command callback
std::string response = commandCallback_(command);
const std::string response = commandCallback_(command);
// Send response back to client
send(clientFd, response.c_str(), response.length(), 0);