diff --git a/Userland/Libraries/LibIPC/ClientConnection.h b/Userland/Libraries/LibIPC/ClientConnection.h index e7817edc01..29a7125fac 100644 --- a/Userland/Libraries/LibIPC/ClientConnection.h +++ b/Userland/Libraries/LibIPC/ClientConnection.h @@ -30,7 +30,10 @@ public: , m_client_id(client_id) { VERIFY(this->socket().is_connected()); - this->socket().on_ready_to_read = [this] { this->drain_messages_from_peer(); }; + this->socket().on_ready_to_read = [this] { + // FIXME: Do something about errors. + (void)this->drain_messages_from_peer(); + }; } virtual ~ClientConnection() override diff --git a/Userland/Libraries/LibIPC/Connection.cpp b/Userland/Libraries/LibIPC/Connection.cpp index 5780761d24..b9600a8332 100644 --- a/Userland/Libraries/LibIPC/Connection.cpp +++ b/Userland/Libraries/LibIPC/Connection.cpp @@ -113,7 +113,7 @@ void ConnectionBase::wait_for_socket_to_become_readable() } } -Result, bool> ConnectionBase::read_as_much_as_possible_from_socket_without_blocking() +ErrorOr> ConnectionBase::read_as_much_as_possible_from_socket_without_blocking() { Vector bytes; @@ -130,12 +130,11 @@ Result, bool> ConnectionBase::read_as_much_as_possible_from_socket_wi break; perror("recv"); exit(1); - return false; } if (nread == 0) { if (bytes.is_empty()) { deferred_invoke([this] { shutdown(); }); - return false; + return Error::from_string_literal("IPC connection EOF"sv); } break; } @@ -150,7 +149,7 @@ Result, bool> ConnectionBase::read_as_much_as_possible_from_socket_wi return bytes; } -bool ConnectionBase::drain_messages_from_peer() +ErrorOr ConnectionBase::drain_messages_from_peer() { auto bytes = TRY(read_as_much_as_possible_from_socket_without_blocking()); @@ -161,17 +160,14 @@ bool ConnectionBase::drain_messages_from_peer() // Sometimes we might receive a partial message. That's okay, just stash away // the unprocessed bytes and we'll prepend them to the next incoming message // in the next run of this function. - auto remaining_bytes_result = ByteBuffer::copy(bytes.span().slice(index)); - if (!remaining_bytes_result.has_value()) { - dbgln("{}::drain_messages_from_peer: Failed to allocate buffer", static_cast(*this)); - return false; - } + auto maybe_remaining_bytes = ByteBuffer::copy(bytes.span().slice(index)); + if (!maybe_remaining_bytes.has_value()) + return Error::from_string_literal("drain_messages_from_peer: Failed to allocate buffer"sv); if (!m_unprocessed_bytes.is_empty()) { - dbgln("{}::drain_messages_from_peer: Already have unprocessed bytes", static_cast(*this)); shutdown(); - return false; + return Error::from_string_literal("drain_messages_from_peer: Already have unprocessed bytes"sv); } - m_unprocessed_bytes = remaining_bytes_result.release_value(); + m_unprocessed_bytes = maybe_remaining_bytes.release_value(); } if (!m_unprocessed_messages.is_empty()) { @@ -179,7 +175,7 @@ bool ConnectionBase::drain_messages_from_peer() handle_messages(); }); } - return true; + return {}; } OwnPtr ConnectionBase::wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id) @@ -199,7 +195,7 @@ OwnPtr ConnectionBase::wait_for_specific_endpoint_message_impl(u32 break; wait_for_socket_to_become_readable(); - if (!drain_messages_from_peer()) + if (drain_messages_from_peer().is_error()) break; } return {}; diff --git a/Userland/Libraries/LibIPC/Connection.h b/Userland/Libraries/LibIPC/Connection.h index 446ba9e151..15861015b2 100644 --- a/Userland/Libraries/LibIPC/Connection.h +++ b/Userland/Libraries/LibIPC/Connection.h @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -50,8 +49,8 @@ protected: OwnPtr wait_for_specific_endpoint_message_impl(u32 endpoint_magic, int message_id); void wait_for_socket_to_become_readable(); - Result, bool> read_as_much_as_possible_from_socket_without_blocking(); - bool drain_messages_from_peer(); + ErrorOr> read_as_much_as_possible_from_socket_without_blocking(); + ErrorOr drain_messages_from_peer(); void post_message(MessageBuffer); void handle_messages(); @@ -76,7 +75,8 @@ public: { m_notifier->on_ready_to_read = [this] { NonnullRefPtr protect = *this; - drain_messages_from_peer(); + // FIXME: Do something about errors. + (void)drain_messages_from_peer(); handle_messages(); }; }