diff --git a/include/crow/dumb_timer_queue.h b/include/crow/dumb_timer_queue.h index fd5151834..f74e123e6 100644 --- a/include/crow/dumb_timer_queue.h +++ b/include/crow/dumb_timer_queue.h @@ -30,7 +30,7 @@ namespace crow self->dq_[index].second = nullptr; } - key add(std::function f) + key add(std::function f) { dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f)); int ret = step_+dq_.size()-1; @@ -48,14 +48,18 @@ namespace crow while(!dq_.empty()) { auto& x = dq_.front(); + bool is_remove = true; if (now - x.first < std::chrono::seconds(tick)) break; if (x.second) { CROW_LOG_DEBUG << "timer call: " << this << ' ' << step_; // we know that timer handlers are very simple currenty; call here - x.second(); + is_remove = x.second(); } + if (!is_remove) + break; + dq_.pop_front(); step_++; } @@ -74,7 +78,7 @@ namespace crow int tick{5}; boost::asio::io_service* io_service_{}; - std::deque>> dq_; + std::deque>> dq_; int step_{}; }; } diff --git a/include/crow/http_connection.h b/include/crow/http_connection.h index 3d214f3d2..a15a4f27d 100644 --- a/include/crow/http_connection.h +++ b/include/crow/http_connection.h @@ -557,9 +557,17 @@ namespace crow { if (!adaptor_.is_open()) { - return; + return true; } + + if(this->is_writing) + { + CROW_LOG_DEBUG << this << " timer called functor but didn't close connection in writing"; + return false; + } adaptor_.close(); + + return true; }); CROW_LOG_DEBUG << this << " timer added: " << timer_cancel_key_.first << ' ' << timer_cancel_key_.second; }