From fe5fdb200baf645f39ec260fd65bb882d7fbca68 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 15 Apr 2022 15:11:11 +0100 Subject: [PATCH] LibCore+LibIPC: Make Core::Stream read_without_waiting() return Bytes For the reasoning, see the earlier commit about Core::Stream::read(). --- Userland/Libraries/LibCore/Stream.cpp | 4 ++-- Userland/Libraries/LibCore/Stream.h | 2 +- Userland/Libraries/LibIPC/Connection.cpp | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index 5edcf6884d..179ee209ea 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -552,9 +552,9 @@ ErrorOr LocalSocket::peer_pid() const #endif } -ErrorOr LocalSocket::read_without_waiting(Bytes buffer) +ErrorOr LocalSocket::read_without_waiting(Bytes buffer) { - return TRY(m_helper.read(buffer, MSG_DONTWAIT)).size(); + return m_helper.read(buffer, MSG_DONTWAIT); } ErrorOr LocalSocket::release_fd() diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index 71c3432f52..1859e86a59 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -444,7 +444,7 @@ public: ErrorOr receive_fd(int flags); ErrorOr send_fd(int fd); ErrorOr peer_pid() const; - ErrorOr read_without_waiting(Bytes buffer); + ErrorOr read_without_waiting(Bytes buffer); /// Release the fd associated with this LocalSocket. After the fd is /// released, the socket will be considered "closed" and all operations done diff --git a/Userland/Libraries/LibIPC/Connection.cpp b/Userland/Libraries/LibIPC/Connection.cpp index 5de66aa0f2..0b43364858 100644 --- a/Userland/Libraries/LibIPC/Connection.cpp +++ b/Userland/Libraries/LibIPC/Connection.cpp @@ -121,9 +121,9 @@ ErrorOr> ConnectionBase::read_as_much_as_possible_from_socket_without u8 buffer[4096]; while (m_socket->is_open()) { - auto maybe_nread = m_socket->read_without_waiting({ buffer, 4096 }); - if (maybe_nread.is_error()) { - auto error = maybe_nread.release_error(); + auto maybe_bytes_read = m_socket->read_without_waiting({ buffer, 4096 }); + if (maybe_bytes_read.is_error()) { + auto error = maybe_bytes_read.release_error(); if (error.is_syscall() && error.code() == EAGAIN) { break; } @@ -133,13 +133,13 @@ ErrorOr> ConnectionBase::read_as_much_as_possible_from_socket_without VERIFY_NOT_REACHED(); } - auto nread = maybe_nread.release_value(); - if (nread == 0) { + auto bytes_read = maybe_bytes_read.release_value(); + if (bytes_read.is_empty()) { deferred_invoke([this] { shutdown(); }); return Error::from_string_literal("IPC connection EOF"sv); } - bytes.append(buffer, nread); + bytes.append(bytes_read.data(), bytes_read.size()); } if (!bytes.is_empty()) {