| 554 | } |
| 555 | |
| 556 | void HttpServerConnection::CheckLiveness(boost::asio::yield_context yc) |
| 557 | { |
| 558 | boost::system::error_code ec; |
| 559 | |
| 560 | for (;;) { |
| 561 | // Wait for the half of the liveness timeout to give the connection some leeway to do other work. |
| 562 | // But never wait longer than 5 seconds to ensure timely shutdowns. |
| 563 | auto sleepTime = std::min(5000ms, m_LivenessTimeout / 2); |
| 564 | m_CheckLivenessTimer.expires_from_now(boost::posix_time::milliseconds(sleepTime.count())); |
| 565 | m_CheckLivenessTimer.async_wait(yc[ec]); |
| 566 | |
| 567 | if (m_ShuttingDown) { |
| 568 | break; |
| 569 | } |
| 570 | |
| 571 | if (m_LivenessTimeout < std::chrono::steady_clock::now() - m_Seen) { |
| 572 | Log(LogInformation, "HttpServerConnection") |
| 573 | << "No messages for HTTP connection have been received in the last " |
| 574 | << std::chrono::duration_cast<std::chrono::seconds>(m_LivenessTimeout).count() |
| 575 | << " seconds, disconnecting (from " << m_PeerAddress << ")."; |
| 576 | |
| 577 | Disconnect(yc); |
| 578 | break; |
| 579 | } |
| 580 | } |
| 581 | } |