Skip to content

Commit

Permalink
Fix connection close bug when response write over 5 seconds
Browse files Browse the repository at this point in the history
PR ipkn#294 shyblue
  • Loading branch information
rustyx committed Feb 8, 2019
1 parent 973909f commit 157760e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 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 @@ -54,7 +54,8 @@ namespace crow
{
CROW_LOG_DEBUG << "timer call: " << this << ' ' << step_;
// we know that timer handlers are very simple currenty; call here
x.second();
if (!x.second())
break;
}
dq_.pop_front();
step_++;
Expand All @@ -74,7 +75,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
8 changes: 7 additions & 1 deletion include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,15 @@ 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

0 comments on commit 157760e

Please sign in to comment.