From 86504f446108577c5a7811e551c64afb8e54da89 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 2 Dec 2019 10:49:47 +0100 Subject: [PATCH] LibIPC: Don't handle incoming messages right away when draining When draining the socket in IServerConnection, we would previously handle each incoming (local endpoint) message as it came in. This would cause unexpected things to happen while blocked waiting for a synchronous response. That's definitely not what we want, so this patch puts all of the incoming messages in a queue and does a separate pass over the queue to handle everything in order. --- Libraries/LibIPC/IServerConnection.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Libraries/LibIPC/IServerConnection.h b/Libraries/LibIPC/IServerConnection.h index e95f7d7206..71e31894a9 100644 --- a/Libraries/LibIPC/IServerConnection.h +++ b/Libraries/LibIPC/IServerConnection.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -25,6 +26,7 @@ public: m_connection->set_blocking(true); m_notifier->on_ready_to_read = [this] { drain_messages_from_server(); + handle_messages(); }; int retries = 100000; @@ -131,7 +133,7 @@ private: for (size_t index = 0; index < (size_t)bytes.size(); index += decoded_bytes) { auto remaining_bytes = ByteBuffer::wrap(bytes.data() + index, bytes.size() - index); if (auto message = LocalEndpoint::decode_message(remaining_bytes, decoded_bytes)) { - m_local_endpoint.handle(*message); + m_unprocessed_messages.append(move(message)); } else if (auto message = PeerEndpoint::decode_message(remaining_bytes, decoded_bytes)) { m_unprocessed_messages.append(move(message)); } else { @@ -142,6 +144,15 @@ private: return true; } + void handle_messages() + { + auto messages = move(m_unprocessed_messages); + for (auto& message : messages) { + if (message->endpoint_magic() == LocalEndpoint::static_magic()) + m_local_endpoint.handle(*message); + } + } + LocalEndpoint& m_local_endpoint; RefPtr m_connection; RefPtr m_notifier;