Skip to content

Commit

Permalink
Fixed sigabort when quitting feathers
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeng-Zer authored and Gaspard-- committed Dec 11, 2019
1 parent ae76097 commit f5eecd0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/IpcServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IpcServer
{
public:
IpcServer(std::string const& socket, Server *server);
~IpcServer() = default;
~IpcServer();

private:
void acceptClients();
Expand All @@ -31,4 +31,5 @@ class IpcServer
std::thread acceptThread;
std::thread processThread;
std::mutex mutex;
bool shutdown;
};
20 changes: 16 additions & 4 deletions source/IpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,41 @@
#include <signal.h>

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<libsocket::unix_stream_client> client = ipcServer.accept2();
usleep(10000);
if (shutdown)
break;
std::unique_ptr<libsocket::unix_stream_client> 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;
}
}
}
Expand All @@ -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;
Expand Down

0 comments on commit f5eecd0

Please sign in to comment.