fix(mango): reconnect IPC event thread on disconnect

The IPC event thread had no reconnect: on POLLHUP/POLLERR/POLLNVAL or
read()==0/error it broke out of the loop and the thread exited
permanently, freezing every mango module with stale content until
Waybar was restarted. Wrap the connect + poll/read loop in a reconnect
loop with a bounded 2s backoff, re-establishing the socket and resuming
on disconnect, modeled on the niri backend.

Add an atomic running_ flag so the worker exits cleanly on teardown;
the destructor now sets it false before closing the socket so the
worker breaks out and joins, and leaves the final close to the
destructor to avoid a double close.
This commit is contained in:
Alex
2026-07-05 10:13:24 +02:00
parent 8db89cc289
commit 2f2479ca35
2 changed files with 93 additions and 40 deletions
+2
View File
@@ -1,6 +1,7 @@
// include/modules/mango/backend.hpp
#pragma once
#include <atomic>
#include <list>
#include <mutex>
#include <string>
@@ -52,6 +53,7 @@ class IPC {
static Json::Value sendCommand(const std::string& cmd);
std::atomic<bool> running_ = true;
int sockfd_ = -1;
std::thread ipc_thread_;
mutable std::mutex data_mutex_;