Commit 968c5eb7 authored by Max Kellermann's avatar Max Kellermann

output/httpd: keep track of queue size

Don't iterate the std::list each time.
parent 19424e95
...@@ -197,6 +197,7 @@ HttpdClient::HttpdClient(HttpdOutput &_httpd, int _fd, EventLoop &_loop, ...@@ -197,6 +197,7 @@ HttpdClient::HttpdClient(HttpdOutput &_httpd, int _fd, EventLoop &_loop,
:BufferedSocket(_fd, _loop), :BufferedSocket(_fd, _loop),
httpd(_httpd), httpd(_httpd),
state(REQUEST), state(REQUEST),
queue_size(0),
head_method(false), head_method(false),
dlna_streaming_requested(false), dlna_streaming_requested(false),
metadata_supported(_metadata_supported), metadata_supported(_metadata_supported),
...@@ -207,18 +208,6 @@ HttpdClient::HttpdClient(HttpdOutput &_httpd, int _fd, EventLoop &_loop, ...@@ -207,18 +208,6 @@ HttpdClient::HttpdClient(HttpdOutput &_httpd, int _fd, EventLoop &_loop,
{ {
} }
size_t
HttpdClient::GetQueueSize() const
{
if (state != RESPONSE)
return 0;
size_t size = 0;
for (auto page : pages)
size += page->size;
return size;
}
void void
HttpdClient::CancelQueue() HttpdClient::CancelQueue()
{ {
...@@ -228,6 +217,7 @@ HttpdClient::CancelQueue() ...@@ -228,6 +217,7 @@ HttpdClient::CancelQueue()
for (auto page : pages) for (auto page : pages)
page->Unref(); page->Unref();
pages.clear(); pages.clear();
queue_size = 0;
if (current_page == nullptr) if (current_page == nullptr)
CancelWrite(); CancelWrite();
...@@ -278,6 +268,9 @@ HttpdClient::TryWrite() ...@@ -278,6 +268,9 @@ HttpdClient::TryWrite()
current_page = pages.front(); current_page = pages.front();
pages.pop_front(); pages.pop_front();
current_position = 0; current_position = 0;
assert(queue_size >= current_page->size);
queue_size -= current_page->size;
} }
const ssize_t bytes_to_write = GetBytesTillMetaData(); const ssize_t bytes_to_write = GetBytesTillMetaData();
...@@ -380,6 +373,7 @@ HttpdClient::PushPage(Page *page) ...@@ -380,6 +373,7 @@ HttpdClient::PushPage(Page *page)
page->Ref(); page->Ref();
pages.push_back(page); pages.push_back(page);
queue_size += page->size;
ScheduleWrite(); ScheduleWrite();
} }
......
...@@ -56,6 +56,11 @@ class HttpdClient final : BufferedSocket { ...@@ -56,6 +56,11 @@ class HttpdClient final : BufferedSocket {
std::list<Page *> pages; std::list<Page *> pages;
/** /**
* The sum of all page sizes in #pages.
*/
size_t queue_size;
/**
* The #page which is currently being sent to the client. * The #page which is currently being sent to the client.
*/ */
Page *current_page; Page *current_page;
...@@ -140,7 +145,9 @@ public: ...@@ -140,7 +145,9 @@ public:
* Returns the total size of this client's page queue. * Returns the total size of this client's page queue.
*/ */
gcc_pure gcc_pure
size_t GetQueueSize() const; size_t GetQueueSize() const {
return queue_size;
}
/** /**
* Clears the page queue. * Clears the page queue.
......
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