Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions include/crow/dumb_timer_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace crow
self->dq_[index].second = nullptr;
}

key add(std::function<void()> f)
key add(std::function<bool()> f)
{
dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f));
int ret = step_+dq_.size()-1;
Expand All @@ -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_++;
}
Expand All @@ -74,7 +78,7 @@ namespace crow

int tick{5};
boost::asio::io_service* io_service_{};
std::deque<std::pair<decltype(std::chrono::steady_clock::now()), std::function<void()>>> dq_;
std::deque<std::pair<decltype(std::chrono::steady_clock::now()), std::function<bool()>>> dq_;
int step_{};
};
}
Expand Down
10 changes: 9 additions & 1 deletion include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down