From c91a5f0898a35871ce5f65cd08901f133ad5b2d2 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 7 Aug 2017 21:12:18 +0200 Subject: Protocol related fixes full() clears text so protocols that doesn't implement append() doesn't end up with repeats. precaching works now because of correct want calculation. if a package is updated while being active in a worker the package is requeud when done instead of forgotten --- src/http_protocol.cc | 2 ++ src/protocols.cc | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/http_protocol.cc b/src/http_protocol.cc index 5915f77..7a7c68b 100644 --- a/src/http_protocol.cc +++ b/src/http_protocol.cc @@ -432,6 +432,8 @@ protected: } void full(void const* data, size_t size, AttributedText* text) override { + text->reset(); + auto iter = http_->header(); while (iter->valid()) { text->append(iter->name()); diff --git a/src/protocols.cc b/src/protocols.cc index 31b3bfd..df7353a 100644 --- a/src/protocols.cc +++ b/src/protocols.cc @@ -66,7 +66,7 @@ public: entry.data_ = data; entry.size_ = size; - reschedule_with_lock(); + if (size) reschedule_with_lock(); } void update(size_t id, void const* data, size_t size) override { @@ -87,6 +87,15 @@ public: return; } } + + for (auto const& active : active_) { + if (active == id) { + invalidate_.emplace(id); + return; + } + } + + if (old == 0) reschedule_with_lock(); } void remove(size_t id) override { @@ -268,7 +277,7 @@ private: void reschedule_with_lock() { if (cache_.size() < cache_size_) { - size_t want = cache_.size() - cache_size_; + size_t want = cache_size_ - cache_.size(); size_t queued = active_.size() + queue_.size(); if (want < queued) { want = 0; @@ -382,6 +391,14 @@ private: std::unique_ptr&& match, std::unique_ptr&& text) { active_.erase(std::find(active_.begin(), active_.end(), id)); + if (invalidate_.erase(id)) { + if (wanted_ == id) { + queue_.emplace_front(id, size, std::move(match), std::move(text)); + } else { + queue_.emplace_back(id, size, std::move(match), std::move(text)); + } + return; + } while (cache_.size() >= cache_size_) { auto oldest = cache_.end(); for (auto it = cache_.begin(); it != cache_.end(); ++it) { @@ -457,6 +474,7 @@ private: std::vector cache_; std::vector active_; std::deque queue_; + std::unordered_set invalidate_; std::deque content_done_; std::deque content_queue_; -- cgit v1.2.3-70-g09d2