Commit ce6afe93 authored by Max Kellermann's avatar Max Kellermann

output/httpd/Page: convert to type alias on AllocatedArray

parent 6f04b223
......@@ -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();
......
......@@ -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
......
......@@ -164,7 +164,7 @@ HttpdOutput::ReadPage()
if (size == 0)
return nullptr;
return std::make_shared<Page>(buffer, size);
return std::make_shared<Page>(ConstBuffer{buffer, size});
}
inline void
......
......@@ -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<Page>(icy_string.c_str(),
uint8_t(icy_string[0]) * 16 + 1);
return std::make_shared<Page>(ConstBuffer<std::byte>{(const std::byte *)icy_string.c_str(), uint8_t(icy_string[0]) * 16U + 1U});
}
/*
* 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 <string.h>
Page::Page(const void *data, size_t size) noexcept
:buffer(size)
{
memcpy(&buffer.front(), data, size);
}
......@@ -30,24 +30,7 @@
* reference-counted buffers around (using std::shared_ptr), when
* several instances hold references to one buffer.
*/
class Page {
AllocatedArray<std::byte> buffer;
public:
explicit Page(size_t _size) noexcept:buffer(_size) {}
explicit Page(AllocatedArray<std::byte> &&_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<std::byte>;
typedef std::shared_ptr<Page> PagePtr;
......
......@@ -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',
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment