From af13614bf39d8e2aa1965293dc151f1344dc1db5 Mon Sep 17 00:00:00 2001 From: David Zeng Date: Wed, 11 Dec 2019 21:00:26 +0100 Subject: [PATCH] Fixed sigabort when quitting feathers --- include/IpcServer.hpp | 3 ++- source/IpcServer.cpp | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/IpcServer.hpp b/include/IpcServer.hpp index 5350a98..43f9632 100644 --- a/include/IpcServer.hpp +++ b/include/IpcServer.hpp @@ -15,7 +15,7 @@ class IpcServer { public: IpcServer(std::string const& socket, Server *server); - ~IpcServer() = default; + ~IpcServer(); private: void acceptClients(); @@ -31,4 +31,5 @@ class IpcServer std::thread acceptThread; std::thread processThread; std::mutex mutex; + bool shutdown; }; diff --git a/source/IpcServer.cpp b/source/IpcServer.cpp index af0d35c..2d83368 100644 --- a/source/IpcServer.cpp +++ b/source/IpcServer.cpp @@ -7,31 +7,41 @@ #include IpcServer::IpcServer(std::string const& socket, Server *server) - : ipcServer(socket) + : ipcServer(socket, SOCK_NONBLOCK) , socket(socket) , server(server) , clients() , acceptThread(&IpcServer::acceptClients, this) , processThread(&IpcServer::processClients, this) , mutex() + , shutdown(false) { // Ignore broken pipe signal(SIGPIPE, SIG_IGN); } +IpcServer::~IpcServer() +{ + shutdown = true; + acceptThread.join(); + processThread.join(); +} + void IpcServer::acceptClients() { while (1) { try { - std::unique_ptr client = ipcServer.accept2(); + usleep(10000); + if (shutdown) + break; + std::unique_ptr client = ipcServer.accept2(SOCK_NONBLOCK); std::cout << "New ipc client" << std::endl; mutex.lock(); clients.emplace_back(std::move(client)); mutex.unlock(); } catch (const libsocket::socket_exception& e) { - std::cerr << e.mesg; } } } @@ -43,7 +53,9 @@ void IpcServer::processClients() unsigned int clientSize = -1; while (1) { - usleep(100); + usleep(10000); + if (shutdown) + break; if (clients.empty()) continue; int newSize = server->outputManager.workspaceCount;