summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-12-11 18:27:30 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-12 14:16:42 +0100
commit6c7c5a6786f5f168b9e228f9d4b41ed1e64bc8f3 (patch)
tree327b04fb4820758e4d8cc60d30bd849d7b3511eb /Userland
parented4c2f2f8ea59295edceca77bf308df5de6872d6 (diff)
downloadserenity-6c7c5a6786f5f168b9e228f9d4b41ed1e64bc8f3.zip
LibCore: Rename `Stream::*_or_error` to `*_entire_buffer`
All of our functions are `_or_error` (or are about to be), and maybe making it less reminiscient of AK::Stream will make people use it more.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp2
-rw-r--r--Userland/DevTools/SQLStudio/ScriptEditor.cpp4
-rw-r--r--Userland/Libraries/LibCore/InputBitStream.h4
-rw-r--r--Userland/Libraries/LibCore/MemoryStream.h2
-rw-r--r--Userland/Libraries/LibCore/Stream.cpp4
-rw-r--r--Userland/Libraries/LibCore/Stream.h16
-rw-r--r--Userland/Libraries/LibGemini/Job.cpp2
-rw-r--r--Userland/Libraries/LibHTTP/Job.cpp2
-rw-r--r--Userland/Libraries/LibTLS/HandshakeClient.cpp10
-rw-r--r--Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp2
10 files changed, 28 insertions, 20 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index 8b4cfeba8d..0f9532d831 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -471,7 +471,7 @@ ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)
auto search_engines_file = TRY(Core::Stream::File::open(Browser::search_engines_file_path(), Core::Stream::OpenMode::Read));
auto file_size = TRY(search_engines_file->size());
auto buffer = TRY(ByteBuffer::create_uninitialized(file_size));
- if (search_engines_file->read_or_error(buffer)) {
+ if (search_engines_file->read_entire_buffer(buffer)) {
StringView buffer_contents { buffer.bytes() };
if (auto json = TRY(JsonValue::from_string(buffer_contents)); json.is_array()) {
auto json_array = json.as_array();
diff --git a/Userland/DevTools/SQLStudio/ScriptEditor.cpp b/Userland/DevTools/SQLStudio/ScriptEditor.cpp
index 539e979e9c..0a4560e038 100644
--- a/Userland/DevTools/SQLStudio/ScriptEditor.cpp
+++ b/Userland/DevTools/SQLStudio/ScriptEditor.cpp
@@ -44,7 +44,7 @@ ErrorOr<bool> ScriptEditor::save()
auto file = TRY(Core::Stream::File::open(m_path, Core::Stream::OpenMode::Write));
auto editor_text = text();
- if (editor_text.length() && !file->write_or_error(editor_text.bytes()))
+ if (editor_text.length() && !file->write_entire_buffer(editor_text.bytes()))
return Error::from_string_literal("Failed to write to file");
document().set_unmodified();
@@ -60,7 +60,7 @@ ErrorOr<bool> ScriptEditor::save_as()
auto file = TRY(Core::Stream::File::open(save_path, Core::Stream::OpenMode::Write));
auto editor_text = text();
- if (editor_text.length() && !file->write_or_error(editor_text.bytes()))
+ if (editor_text.length() && !file->write_entire_buffer(editor_text.bytes()))
return Error::from_string_literal("Failed to write to file");
m_path = save_path;
diff --git a/Userland/Libraries/LibCore/InputBitStream.h b/Userland/Libraries/LibCore/InputBitStream.h
index 494963d2a8..f0eb126a39 100644
--- a/Userland/Libraries/LibCore/InputBitStream.h
+++ b/Userland/Libraries/LibCore/InputBitStream.h
@@ -40,7 +40,7 @@ public:
return m_stream.read(bytes);
}
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_stream.write(bytes); }
- virtual bool write_or_error(ReadonlyBytes bytes) override { return m_stream.write_or_error(bytes); }
+ virtual bool write_entire_buffer(ReadonlyBytes bytes) override { return m_stream.write_entire_buffer(bytes); }
virtual bool is_eof() const override { return m_stream.is_eof() && !m_current_byte.has_value(); }
virtual bool is_open() const override { return m_stream.is_open(); }
virtual void close() override
@@ -155,7 +155,7 @@ public:
return m_stream.read(bytes);
}
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_stream.write(bytes); }
- virtual bool write_or_error(ReadonlyBytes bytes) override { return m_stream.write_or_error(bytes); }
+ virtual bool write_entire_buffer(ReadonlyBytes bytes) override { return m_stream.write_entire_buffer(bytes); }
virtual bool is_eof() const override { return m_stream.is_eof() && !m_current_byte.has_value(); }
virtual bool is_open() const override { return m_stream.is_open(); }
virtual void close() override
diff --git a/Userland/Libraries/LibCore/MemoryStream.h b/Userland/Libraries/LibCore/MemoryStream.h
index 811f5e8bc2..29ebcfc73b 100644
--- a/Userland/Libraries/LibCore/MemoryStream.h
+++ b/Userland/Libraries/LibCore/MemoryStream.h
@@ -79,7 +79,7 @@ public:
m_offset += nwritten;
return nwritten;
}
- virtual bool write_or_error(ReadonlyBytes bytes) override
+ virtual bool write_entire_buffer(ReadonlyBytes bytes) override
{
if (remaining() < bytes.size())
return false;
diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp
index ba69c533c7..c8b0e477a1 100644
--- a/Userland/Libraries/LibCore/Stream.cpp
+++ b/Userland/Libraries/LibCore/Stream.cpp
@@ -23,7 +23,7 @@
namespace Core::Stream {
-bool Stream::read_or_error(Bytes buffer)
+bool Stream::read_entire_buffer(Bytes buffer)
{
VERIFY(buffer.size());
@@ -89,7 +89,7 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
return {};
}
-bool Stream::write_or_error(ReadonlyBytes buffer)
+bool Stream::write_entire_buffer(ReadonlyBytes buffer)
{
VERIFY(buffer.size());
diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h
index 550a376e03..ca440e6cb4 100644
--- a/Userland/Libraries/LibCore/Stream.h
+++ b/Userland/Libraries/LibCore/Stream.h
@@ -35,7 +35,7 @@ public:
virtual ErrorOr<Bytes> read(Bytes) = 0;
/// Tries to fill the entire buffer through reading. Returns whether the
/// buffer was filled without an error.
- virtual bool read_or_error(Bytes);
+ virtual bool read_entire_buffer(Bytes);
/// Reads the stream until EOF, storing the contents into a ByteBuffer which
/// is returned once EOF is encountered. The block size determines the size
/// of newly allocated chunks while reading.
@@ -50,9 +50,17 @@ public:
/// bytes written into the stream, or an errno in the case of failure.
virtual ErrorOr<size_t> write(ReadonlyBytes) = 0;
/// Same as write, but does not return until either the entire buffer
- /// contents are written or an error occurs. Returns whether the entire
- /// contents were written without an error.
- virtual bool write_or_error(ReadonlyBytes);
+ /// contents are written or an error occurs.
+ virtual bool write_entire_buffer(ReadonlyBytes);
+
+ // This is a wrapper around `write_entire_buffer` that is compatible with
+ // `write_or_error`. This is required by some templated code in LibProtocol
+ // that needs to work with either type of stream.
+ // TODO: Fully port or wrap `Request::stream_into_impl` into `Core::Stream` and remove this.
+ bool write_or_error(ReadonlyBytes buffer)
+ {
+ return write_entire_buffer(buffer);
+ }
/// Returns whether the stream has reached the end of file. For sockets,
/// this most likely means that the protocol has disconnected (in the case
diff --git a/Userland/Libraries/LibGemini/Job.cpp b/Userland/Libraries/LibGemini/Job.cpp
index 1893ea5959..9cc936733f 100644
--- a/Userland/Libraries/LibGemini/Job.cpp
+++ b/Userland/Libraries/LibGemini/Job.cpp
@@ -75,7 +75,7 @@ bool Job::can_read() const
bool Job::write(ReadonlyBytes bytes)
{
- return m_socket->write_or_error(bytes);
+ return m_socket->write_entire_buffer(bytes);
}
void Job::flush_received_buffers()
diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp
index 5ab3ea0458..f870427498 100644
--- a/Userland/Libraries/LibHTTP/Job.cpp
+++ b/Userland/Libraries/LibHTTP/Job.cpp
@@ -220,7 +220,7 @@ void Job::on_socket_connected()
dbgln("{}", DeprecatedString::copy(raw_request));
}
- bool success = m_socket->write_or_error(raw_request);
+ bool success = m_socket->write_entire_buffer(raw_request);
if (!success)
deferred_invoke([this] { did_fail(Core::NetworkJob::Error::TransmissionFailed); });
diff --git a/Userland/Libraries/LibTLS/HandshakeClient.cpp b/Userland/Libraries/LibTLS/HandshakeClient.cpp
index 20cfb8ac12..89bd1e88c3 100644
--- a/Userland/Libraries/LibTLS/HandshakeClient.cpp
+++ b/Userland/Libraries/LibTLS/HandshakeClient.cpp
@@ -141,11 +141,11 @@ bool TLSv12::compute_master_secret_from_pre_master_secret(size_t length)
if constexpr (TLS_SSL_KEYLOG_DEBUG) {
auto file = MUST(Core::Stream::File::open("/home/anon/ssl_keylog"sv, Core::Stream::OpenMode::Append | Core::Stream::OpenMode::Write));
- VERIFY(file->write_or_error("CLIENT_RANDOM "sv.bytes()));
- VERIFY(file->write_or_error(encode_hex({ m_context.local_random, 32 }).bytes()));
- VERIFY(file->write_or_error(" "sv.bytes()));
- VERIFY(file->write_or_error(encode_hex(m_context.master_key).bytes()));
- VERIFY(file->write_or_error("\n"sv.bytes()));
+ VERIFY(file->write_entire_buffer("CLIENT_RANDOM "sv.bytes()));
+ VERIFY(file->write_entire_buffer(encode_hex({ m_context.local_random, 32 }).bytes()));
+ VERIFY(file->write_entire_buffer(" "sv.bytes()));
+ VERIFY(file->write_entire_buffer(encode_hex(m_context.master_key).bytes()));
+ VERIFY(file->write_entire_buffer("\n"sv.bytes()));
}
expand_key();
diff --git a/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp b/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp
index 0f2004a336..42ea661c71 100644
--- a/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp
+++ b/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp
@@ -21,7 +21,7 @@ bool WebSocketImplSerenity::can_read_line()
bool WebSocketImplSerenity::send(ReadonlyBytes bytes)
{
- return m_socket->write_or_error(bytes);
+ return m_socket->write_entire_buffer(bytes);
}
bool WebSocketImplSerenity::eof()