Fix timer on websocket upgrade in examples

fix #1091, fix #1240, fix #1253
This commit is contained in:
jarle
2018-09-02 13:28:50 +02:00
committed by Vinnie Falco
parent 806979e37b
commit 2b977f2770
4 changed files with 19 additions and 0 deletions

View File

@ -3,6 +3,7 @@ Version 184:
* Remove extraneous function
* Fix some typos
* Add BOOST_BEAST_USE_STD_STRING_VIEW
* Fix timer on websocket upgrade in examples
--------------------------------------------------------------------------------

View File

@ -25,6 +25,8 @@
* ([issue 1233]) Use [@boost:/doc/html/core/empty_value.html `boost::empty_value`]
* ([issue 1091]) Fix timer on websocket upgrade in examples
* Workaround for http-server-fast and libstdc++

View File

@ -811,6 +811,10 @@ public:
if(ec && ec != boost::asio::error::operation_aborted)
return fail(ec, "timer");
// Check if this has been upgraded to Websocket
if(timer_.expires_at() == (std::chrono::steady_clock::time_point::min)())
return;
// Verify that the timer really expired since the deadline may have moved.
if(timer_.expiry() <= std::chrono::steady_clock::now())
return derived().do_timeout();
@ -842,6 +846,10 @@ public:
// See if it is a WebSocket Upgrade
if(websocket::is_upgrade(req_))
{
// Make timer expire immediately, by setting expiry to time_point::min we can detect
// the upgrade to websocket in the timer handler
timer_.expires_at((std::chrono::steady_clock::time_point::min)());
// Transfer the stream to a new WebSocket session
return make_websocket_session(
derived().release_stream(),

View File

@ -621,6 +621,10 @@ public:
if(ec && ec != boost::asio::error::operation_aborted)
return fail(ec, "timer");
// Check if this has been upgraded to Websocket
if(timer_.expires_at() == (std::chrono::steady_clock::time_point::min)())
return;
// Verify that the timer really expired since the deadline may have moved.
if(timer_.expiry() <= std::chrono::steady_clock::now())
{
@ -658,6 +662,10 @@ public:
// See if it is a WebSocket Upgrade
if(websocket::is_upgrade(req_))
{
// Make timer expire immediately, by setting expiry to time_point::min we can detect
// the upgrade to websocket in the timer handler
timer_.expires_at((std::chrono::steady_clock::time_point::min)());
// Create a WebSocket websocket_session by transferring the socket
std::make_shared<websocket_session>(
std::move(socket_))->do_accept(std::move(req_));