From 74829cdb753086323fef867cdd1469adfd7ee431 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 25 Jan 2020 10:19:53 +0100 Subject: [PATCH] LibIPC: Short-cirtcuit post_message() if socket already disconnected To allow for more asynchronous teardown of IClientConnection, make the post_message() function simply return if called after the IPC socket has been closed. --- Libraries/LibIPC/IClientConnection.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/LibIPC/IClientConnection.h b/Libraries/LibIPC/IClientConnection.h index 89570fd6ae..e20219cbbb 100644 --- a/Libraries/LibIPC/IClientConnection.h +++ b/Libraries/LibIPC/IClientConnection.h @@ -98,6 +98,11 @@ public: void post_message(const IMessage& message) { + // NOTE: If this connection is being shut down, but has not yet been destroyed, + // the socket will be closed. Don't try to send more messages. + if (!m_socket->is_open()) + return; + auto buffer = message.encode(); int nwritten = write(m_socket->fd(), buffer.data(), (size_t)buffer.size());