output/httpd/Page: convert to type alias on AllocatedArray
This commit is contained in:
parent
6f04b2230a
commit
ce6afe9379
@ -197,8 +197,8 @@ HttpdClient::ClearQueue() noexcept
|
|||||||
while (!pages.empty()) {
|
while (!pages.empty()) {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
auto &page = pages.front();
|
auto &page = pages.front();
|
||||||
assert(queue_size >= page->GetSize());
|
assert(queue_size >= page->size());
|
||||||
queue_size -= page->GetSize();
|
queue_size -= page->size();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pages.pop();
|
pages.pop();
|
||||||
@ -222,10 +222,10 @@ HttpdClient::CancelQueue() noexcept
|
|||||||
ssize_t
|
ssize_t
|
||||||
HttpdClient::TryWritePage(const Page &page, size_t position) noexcept
|
HttpdClient::TryWritePage(const Page &page, size_t position) noexcept
|
||||||
{
|
{
|
||||||
assert(position < page.GetSize());
|
assert(position < page.size());
|
||||||
|
|
||||||
return GetSocket().Write(page.GetData() + position,
|
return GetSocket().Write(page.data() + position,
|
||||||
page.GetSize() - position);
|
page.size() - position);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
@ -233,7 +233,7 @@ HttpdClient::TryWritePageN(const Page &page,
|
|||||||
size_t position, ssize_t n) noexcept
|
size_t position, ssize_t n) noexcept
|
||||||
{
|
{
|
||||||
return n >= 0
|
return n >= 0
|
||||||
? GetSocket().Write(page.GetData() + position, n)
|
? GetSocket().Write(page.data() + position, n)
|
||||||
: TryWritePage(page, position);
|
: TryWritePage(page, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ ssize_t
|
|||||||
HttpdClient::GetBytesTillMetaData() const noexcept
|
HttpdClient::GetBytesTillMetaData() const noexcept
|
||||||
{
|
{
|
||||||
if (metadata_requested &&
|
if (metadata_requested &&
|
||||||
current_page->GetSize() - current_position > metaint - metadata_fill)
|
current_page->size() - current_position > metaint - metadata_fill)
|
||||||
return metaint - metadata_fill;
|
return metaint - metadata_fill;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -267,8 +267,8 @@ HttpdClient::TryWrite() noexcept
|
|||||||
pages.pop();
|
pages.pop();
|
||||||
current_position = 0;
|
current_position = 0;
|
||||||
|
|
||||||
assert(queue_size >= current_page->GetSize());
|
assert(queue_size >= current_page->size());
|
||||||
queue_size -= current_page->GetSize();
|
queue_size -= current_page->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const ssize_t bytes_to_write = GetBytesTillMetaData();
|
const ssize_t bytes_to_write = GetBytesTillMetaData();
|
||||||
@ -294,7 +294,7 @@ HttpdClient::TryWrite() noexcept
|
|||||||
|
|
||||||
metadata_current_position += nbytes;
|
metadata_current_position += nbytes;
|
||||||
|
|
||||||
if (metadata->GetSize() - metadata_current_position == 0) {
|
if (metadata->size() - metadata_current_position == 0) {
|
||||||
metadata_fill = 0;
|
metadata_fill = 0;
|
||||||
metadata_current_position = 0;
|
metadata_current_position = 0;
|
||||||
metadata_sent = true;
|
metadata_sent = true;
|
||||||
@ -343,12 +343,12 @@ HttpdClient::TryWrite() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
current_position += nbytes;
|
current_position += nbytes;
|
||||||
assert(current_position <= current_page->GetSize());
|
assert(current_position <= current_page->size());
|
||||||
|
|
||||||
if (metadata_requested)
|
if (metadata_requested)
|
||||||
metadata_fill += nbytes;
|
metadata_fill += nbytes;
|
||||||
|
|
||||||
if (current_position >= current_page->GetSize()) {
|
if (current_position >= current_page->size()) {
|
||||||
current_page.reset();
|
current_page.reset();
|
||||||
|
|
||||||
if (pages.empty())
|
if (pages.empty())
|
||||||
@ -374,7 +374,7 @@ HttpdClient::PushPage(PagePtr page) noexcept
|
|||||||
ClearQueue();
|
ClearQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_size += page->GetSize();
|
queue_size += page->size();
|
||||||
pages.emplace(std::move(page));
|
pages.emplace(std::move(page));
|
||||||
|
|
||||||
event.ScheduleWrite();
|
event.ScheduleWrite();
|
||||||
|
@ -143,7 +143,7 @@ private:
|
|||||||
* A temporary buffer for the httpd_output_read_page()
|
* A temporary buffer for the httpd_output_read_page()
|
||||||
* function.
|
* function.
|
||||||
*/
|
*/
|
||||||
char buffer[32768];
|
std::byte buffer[32768];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum and current number of clients connected
|
* The maximum and current number of clients connected
|
||||||
|
@ -164,7 +164,7 @@ HttpdOutput::ReadPage()
|
|||||||
if (size == 0)
|
if (size == 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return std::make_shared<Page>(buffer, size);
|
return std::make_shared<Page>(ConstBuffer{buffer, size});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
|
@ -113,6 +113,5 @@ icy_server_metadata_page(const Tag &tag, const TagType *types) noexcept
|
|||||||
if (icy_string == nullptr)
|
if (icy_string == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return std::make_shared<Page>(icy_string.c_str(),
|
return std::make_shared<Page>(ConstBuffer<std::byte>{(const std::byte *)icy_string.c_str(), uint8_t(icy_string[0]) * 16U + 1U});
|
||||||
uint8_t(icy_string[0]) * 16 + 1);
|
|
||||||
}
|
}
|
||||||
|
@ -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 <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
|
* reference-counted buffers around (using std::shared_ptr), when
|
||||||
* several instances hold references to one buffer.
|
* several instances hold references to one buffer.
|
||||||
*/
|
*/
|
||||||
class Page {
|
using Page = AllocatedArray<std::byte>;
|
||||||
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();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::shared_ptr<Page> PagePtr;
|
typedef std::shared_ptr<Page> PagePtr;
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ output_features.set('ENABLE_HTTPD_OUTPUT', get_option('httpd'))
|
|||||||
if get_option('httpd')
|
if get_option('httpd')
|
||||||
output_plugins_sources += [
|
output_plugins_sources += [
|
||||||
'httpd/IcyMetaDataServer.cxx',
|
'httpd/IcyMetaDataServer.cxx',
|
||||||
'httpd/Page.cxx',
|
|
||||||
'httpd/HttpdClient.cxx',
|
'httpd/HttpdClient.cxx',
|
||||||
'httpd/HttpdOutputPlugin.cxx',
|
'httpd/HttpdOutputPlugin.cxx',
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user