From ce6afe9379dff633fbf445031d612bf642f258dd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 17 Feb 2021 17:57:20 +0100 Subject: [PATCH] output/httpd/Page: convert to type alias on AllocatedArray --- src/output/plugins/httpd/HttpdClient.cxx | 26 ++++++++--------- src/output/plugins/httpd/HttpdInternal.hxx | 2 +- .../plugins/httpd/HttpdOutputPlugin.cxx | 2 +- .../plugins/httpd/IcyMetaDataServer.cxx | 3 +- src/output/plugins/httpd/Page.cxx | 28 ------------------- src/output/plugins/httpd/Page.hxx | 19 +------------ src/output/plugins/meson.build | 1 - 7 files changed, 17 insertions(+), 64 deletions(-) delete mode 100644 src/output/plugins/httpd/Page.cxx diff --git a/src/output/plugins/httpd/HttpdClient.cxx b/src/output/plugins/httpd/HttpdClient.cxx index e16389db0..c506f9cdb 100644 --- a/src/output/plugins/httpd/HttpdClient.cxx +++ b/src/output/plugins/httpd/HttpdClient.cxx @@ -197,8 +197,8 @@ HttpdClient::ClearQueue() noexcept while (!pages.empty()) { #ifndef NDEBUG auto &page = pages.front(); - assert(queue_size >= page->GetSize()); - queue_size -= page->GetSize(); + assert(queue_size >= page->size()); + queue_size -= page->size(); #endif pages.pop(); @@ -222,10 +222,10 @@ HttpdClient::CancelQueue() noexcept ssize_t HttpdClient::TryWritePage(const Page &page, size_t position) noexcept { - assert(position < page.GetSize()); + assert(position < page.size()); - return GetSocket().Write(page.GetData() + position, - page.GetSize() - position); + return GetSocket().Write(page.data() + position, + page.size() - position); } ssize_t @@ -233,7 +233,7 @@ HttpdClient::TryWritePageN(const Page &page, size_t position, ssize_t n) noexcept { return n >= 0 - ? GetSocket().Write(page.GetData() + position, n) + ? GetSocket().Write(page.data() + position, n) : TryWritePage(page, position); } @@ -241,7 +241,7 @@ ssize_t HttpdClient::GetBytesTillMetaData() const noexcept { if (metadata_requested && - current_page->GetSize() - current_position > metaint - metadata_fill) + current_page->size() - current_position > metaint - metadata_fill) return metaint - metadata_fill; return -1; @@ -267,8 +267,8 @@ HttpdClient::TryWrite() noexcept pages.pop(); current_position = 0; - assert(queue_size >= current_page->GetSize()); - queue_size -= current_page->GetSize(); + assert(queue_size >= current_page->size()); + queue_size -= current_page->size(); } const ssize_t bytes_to_write = GetBytesTillMetaData(); @@ -294,7 +294,7 @@ HttpdClient::TryWrite() noexcept metadata_current_position += nbytes; - if (metadata->GetSize() - metadata_current_position == 0) { + if (metadata->size() - metadata_current_position == 0) { metadata_fill = 0; metadata_current_position = 0; metadata_sent = true; @@ -343,12 +343,12 @@ HttpdClient::TryWrite() noexcept } current_position += nbytes; - assert(current_position <= current_page->GetSize()); + assert(current_position <= current_page->size()); if (metadata_requested) metadata_fill += nbytes; - if (current_position >= current_page->GetSize()) { + if (current_position >= current_page->size()) { current_page.reset(); if (pages.empty()) @@ -374,7 +374,7 @@ HttpdClient::PushPage(PagePtr page) noexcept ClearQueue(); } - queue_size += page->GetSize(); + queue_size += page->size(); pages.emplace(std::move(page)); event.ScheduleWrite(); diff --git a/src/output/plugins/httpd/HttpdInternal.hxx b/src/output/plugins/httpd/HttpdInternal.hxx index 0a04b5cc5..5283c73af 100644 --- a/src/output/plugins/httpd/HttpdInternal.hxx +++ b/src/output/plugins/httpd/HttpdInternal.hxx @@ -143,7 +143,7 @@ private: * A temporary buffer for the httpd_output_read_page() * function. */ - char buffer[32768]; + std::byte buffer[32768]; /** * The maximum and current number of clients connected diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index 3de732bac..3ac9cc183 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -164,7 +164,7 @@ HttpdOutput::ReadPage() if (size == 0) return nullptr; - return std::make_shared(buffer, size); + return std::make_shared(ConstBuffer{buffer, size}); } inline void diff --git a/src/output/plugins/httpd/IcyMetaDataServer.cxx b/src/output/plugins/httpd/IcyMetaDataServer.cxx index d746d0a0a..33cb2b60f 100644 --- a/src/output/plugins/httpd/IcyMetaDataServer.cxx +++ b/src/output/plugins/httpd/IcyMetaDataServer.cxx @@ -113,6 +113,5 @@ icy_server_metadata_page(const Tag &tag, const TagType *types) noexcept if (icy_string == nullptr) return nullptr; - return std::make_shared(icy_string.c_str(), - uint8_t(icy_string[0]) * 16 + 1); + return std::make_shared(ConstBuffer{(const std::byte *)icy_string.c_str(), uint8_t(icy_string[0]) * 16U + 1U}); } diff --git a/src/output/plugins/httpd/Page.cxx b/src/output/plugins/httpd/Page.cxx deleted file mode 100644 index 918222601..000000000 --- a/src/output/plugins/httpd/Page.cxx +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2003-2021 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "Page.hxx" - -#include - -Page::Page(const void *data, size_t size) noexcept - :buffer(size) -{ - memcpy(&buffer.front(), data, size); -} diff --git a/src/output/plugins/httpd/Page.hxx b/src/output/plugins/httpd/Page.hxx index aaafcb295..bc149484b 100644 --- a/src/output/plugins/httpd/Page.hxx +++ b/src/output/plugins/httpd/Page.hxx @@ -30,24 +30,7 @@ * reference-counted buffers around (using std::shared_ptr), when * several instances hold references to one buffer. */ -class Page { - AllocatedArray buffer; - -public: - explicit Page(size_t _size) noexcept:buffer(_size) {} - explicit Page(AllocatedArray &&_buffer) noexcept - :buffer(std::move(_buffer)) {} - - Page(const void *data, size_t size) noexcept; - - size_t GetSize() const noexcept { - return buffer.size(); - } - - const std::byte *GetData() const noexcept { - return &buffer.front(); - } -}; +using Page = AllocatedArray; typedef std::shared_ptr PagePtr; diff --git a/src/output/plugins/meson.build b/src/output/plugins/meson.build index 50618b866..c13998a74 100644 --- a/src/output/plugins/meson.build +++ b/src/output/plugins/meson.build @@ -36,7 +36,6 @@ output_features.set('ENABLE_HTTPD_OUTPUT', get_option('httpd')) if get_option('httpd') output_plugins_sources += [ 'httpd/IcyMetaDataServer.cxx', - 'httpd/Page.cxx', 'httpd/HttpdClient.cxx', 'httpd/HttpdOutputPlugin.cxx', ]