From c0a9434f3414e42e5f94ea7c9ed5423a637f6e87 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 29 Jan 2025 12:44:26 +0100 Subject: [PATCH] command/file: "albumart" tries to send larger chunks if available If we only receive very little data from the InputStream, try a second Read() call to get more data. This works around tiny reads at input buffer boundaries with the io_uring input plugin. These tiny reads are inefficient, and we can afford to wait one more low-level I/O iteration to finish (but not more). Closes https://github.com/MusicPlayerDaemon/MPD/issues/2186 --- NEWS | 2 ++ src/command/FileCommands.cxx | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/NEWS b/NEWS index f39025288..75ce69e6d 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ ver 0.23.17 (not yet released) +* protocol + - "albumart" tries to send larger chunks if available * storage - nfs: require libnfs 4.0 or later * database diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx index e28cc2eb5..fbf2ee70a 100644 --- a/src/command/FileCommands.cxx +++ b/src/command/FileCommands.cxx @@ -215,7 +215,20 @@ read_stream_art(Response &r, const std::string_view art_directory, if (buffer_size > 0) { std::unique_lock lock(is->mutex); is->Seek(lock, offset); + + const bool was_ready = is->IsReady(); + read_size = is->Read(lock, buffer.get(), buffer_size); + + if (was_ready && read_size < buffer_size / 2) + /* the InputStream was ready before, but we + got only very little data; probably just + some data left in the buffer without doing + any I/O; let's wait for the next low-level + read to complete to get more data for the + client */ + read_size += is->Read(lock, buffer.get() + read_size, + buffer_size - read_size); } r.Fmt("size: {}\n", art_file_size);