From 3b1e063d30d915826949ce13e069761d7a32e8a5 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 15 Apr 2022 13:33:02 +0100 Subject: LibCore+Everywhere: Make Core::Stream::read() return Bytes A mistake I've repeatedly made is along these lines: ```c++ auto nread = TRY(source_file->read(buffer)); TRY(destination_file->write(buffer)); ``` It's a little clunky to have to create a Bytes or StringView from the buffer's data pointer and the nread, and easy to forget and just use the buffer. So, this patch changes the read() function to return a Bytes of the data that were just read. The other read_foo() methods will be modified in the same way in subsequent commits. Fixes #13687 --- Userland/Services/TelnetServer/Client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Userland/Services/TelnetServer/Client.cpp') diff --git a/Userland/Services/TelnetServer/Client.cpp b/Userland/Services/TelnetServer/Client.cpp index d45800975c..68dda4074d 100644 --- a/Userland/Services/TelnetServer/Client.cpp +++ b/Userland/Services/TelnetServer/Client.cpp @@ -76,9 +76,9 @@ ErrorOr Client::drain_socket() auto buffer = TRY(ByteBuffer::create_uninitialized(1024)); while (TRY(m_socket->can_read_without_blocking())) { - auto nread = TRY(m_socket->read(buffer)); + auto read_bytes = TRY(m_socket->read(buffer)); - m_parser.write({ buffer.data(), nread }); + m_parser.write(StringView { read_bytes }); if (m_socket->is_eof()) { Core::deferred_invoke([this, strong_this = NonnullRefPtr(*this)] { quit(); }); -- cgit v1.2.3