From 509c86dca0d484a0db1f50dc8223cc50a088c7a4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 14 Oct 2025 11:33:54 +0200 Subject: [PATCH] LibIPC: Simplify IPC read hook - Return `PeerEOF` enum instead of `Error` containing string from `drain_messages_from_peer()`. There are no other error types to return from this function, so boolean-like enum is sufficient. - Don't override read hook in `ConnectionFromClient` constructor. It was previously redefined only to suppress EOF error returned by `drain_messages_from_peer()`. --- Libraries/LibIPC/Connection.cpp | 13 +++++-------- Libraries/LibIPC/Connection.h | 6 +++++- Libraries/LibIPC/ConnectionFromClient.h | 5 ----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Libraries/LibIPC/Connection.cpp b/Libraries/LibIPC/Connection.cpp index 88e177b30a..92603c16e1 100644 --- a/Libraries/LibIPC/Connection.cpp +++ b/Libraries/LibIPC/Connection.cpp @@ -21,10 +21,7 @@ ConnectionBase::ConnectionBase(IPC::Stub& local_stub, NonnullOwnPtr t { m_transport->set_up_read_hook([this] { NonnullRefPtr protect = *this; - - if (auto result = drain_messages_from_peer(); result.is_error()) - dbgln("Read hook error while draining messages: {}", result.error()); - + drain_messages_from_peer(); handle_messages(); }); } @@ -96,7 +93,7 @@ void ConnectionBase::wait_for_transport_to_become_readable() m_transport->wait_until_readable(); } -ErrorOr ConnectionBase::drain_messages_from_peer() +ConnectionBase::PeerEOF ConnectionBase::drain_messages_from_peer() { auto schedule_shutdown = m_transport->read_as_many_messages_as_possible_without_blocking([&](auto&& raw_message) { if (auto message = try_parse_message(raw_message.bytes, raw_message.fds)) { @@ -117,10 +114,10 @@ ErrorOr ConnectionBase::drain_messages_from_peer() deferred_invoke([this] { shutdown(); }); - return Error::from_string_literal("IPC connection EOF"); + return PeerEOF::Yes; } - return {}; + return PeerEOF::No; } OwnPtr ConnectionBase::wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id) @@ -140,7 +137,7 @@ OwnPtr ConnectionBase::wait_for_specific_endpoint_message_impl(u32 break; wait_for_transport_to_become_readable(); - if (drain_messages_from_peer().is_error()) + if (drain_messages_from_peer() == PeerEOF::Yes) break; } diff --git a/Libraries/LibIPC/Connection.h b/Libraries/LibIPC/Connection.h index 8858d308b0..6f96565a94 100644 --- a/Libraries/LibIPC/Connection.h +++ b/Libraries/LibIPC/Connection.h @@ -41,7 +41,11 @@ protected: OwnPtr wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id); void wait_for_transport_to_become_readable(); - ErrorOr drain_messages_from_peer(); + enum class PeerEOF { + No, + Yes + }; + PeerEOF drain_messages_from_peer(); void handle_messages(); diff --git a/Libraries/LibIPC/ConnectionFromClient.h b/Libraries/LibIPC/ConnectionFromClient.h index 389c5f7148..8f720ac1e0 100644 --- a/Libraries/LibIPC/ConnectionFromClient.h +++ b/Libraries/LibIPC/ConnectionFromClient.h @@ -31,11 +31,6 @@ public: , ClientEndpoint::template Proxy(*this, {}) , m_client_id(client_id) { - this->transport().set_up_read_hook([this] { - NonnullRefPtr protect = *this; - // FIXME: Do something about errors. - (void)this->drain_messages_from_peer(); - }); } virtual ~ConnectionFromClient() override = default;