From 4f61cd0b9346d61316ec3d2efd75ee90325e4f18 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 12 Aug 2019 20:10:37 +0200 Subject: [PATCH] client/Response: add constant MAX_BINARY_SIZE Use the same chunk size for all binary commands. --- src/client/Response.cxx | 2 ++ src/client/Response.hxx | 2 ++ src/command/FileCommands.cxx | 5 ++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client/Response.cxx b/src/client/Response.cxx index 9d85a27e6..4d1b575d2 100644 --- a/src/client/Response.cxx +++ b/src/client/Response.cxx @@ -59,6 +59,8 @@ Response::Format(const char *fmt, ...) noexcept bool Response::WriteBinary(ConstBuffer payload) noexcept { + assert(payload.size <= MAX_BINARY_SIZE); + return Format("binary: %zu\n", payload.size) && Write(payload.data, payload.size) && Write("\n"); diff --git a/src/client/Response.hxx b/src/client/Response.hxx index cac365552..17e8fe7d5 100644 --- a/src/client/Response.hxx +++ b/src/client/Response.hxx @@ -77,6 +77,8 @@ public: bool FormatV(const char *fmt, va_list args) noexcept; bool Format(const char *fmt, ...) noexcept; + static constexpr size_t MAX_BINARY_SIZE = 8192; + /** * Write a binary chunk; this writes the "binary" line, the * given chunk and the trailing newline. diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx index 5de92a721..965e596fd 100644 --- a/src/command/FileCommands.cxx +++ b/src/command/FileCommands.cxx @@ -286,14 +286,13 @@ read_stream_art(Response &r, const char *uri, size_t offset) const offset_type art_file_size = is->GetSize(); - constexpr size_t CHUNK_SIZE = 8192; - uint8_t buffer[CHUNK_SIZE]; + uint8_t buffer[Response::MAX_BINARY_SIZE]; size_t read_size; { std::unique_lock lock(mutex); is->Seek(lock, offset); - read_size = is->Read(lock, &buffer, CHUNK_SIZE); + read_size = is->Read(lock, &buffer, sizeof(buffer)); } r.Format("size: %" PRIoffset "\n", art_file_size);