From 6386554cd9f04f9079d9e03a22676133200867bd Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 17 Mar 2022 20:54:08 +0330 Subject: [PATCH] LibProtocol: Don't block indefinitely in stream_into's on_ready_to_read Blocking there will lead to blocking the entire event loop, so just try to read until something has been read or we hit EOF, this allows the event loop to continue to deliver other events while a long download is happening. --- Userland/Libraries/LibProtocol/Request.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibProtocol/Request.cpp b/Userland/Libraries/LibProtocol/Request.cpp index 6fa59bad17..ccbb3d6e29 100644 --- a/Userland/Libraries/LibProtocol/Request.cpp +++ b/Userland/Libraries/LibProtocol/Request.cpp @@ -43,7 +43,7 @@ void Request::stream_into_impl(T& stream) } }; m_internal_stream_data->read_notifier->on_ready_to_read = [this, &stream] { - constexpr size_t buffer_size = 16 * KiB; + constexpr size_t buffer_size = 256 * KiB; static char buf[buffer_size]; do { auto result = m_internal_stream_data->read_stream->read({ buf, buffer_size }); @@ -58,6 +58,7 @@ void Request::stream_into_impl(T& stream) // FIXME: What do we do here? TODO(); } + break; } while (true); if (m_internal_stream_data->read_stream->is_eof())