From 570eafcd4001637e9e4fe9fd28f7f95365fa0f29 Mon Sep 17 00:00:00 2001 From: Richard Hodges Date: Fri, 13 Mar 2020 18:47:08 +0100 Subject: [PATCH] Ensure basic_stream::close will not throw refs: #1875 --- CHANGELOG.md | 1 + include/boost/beast/core/basic_stream.hpp | 4 ++-- include/boost/beast/core/impl/basic_stream.hpp | 18 ++++++++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c4599c..d4c2726a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Version XXX: * Refactor websocket read * Correct buffer_bytes documentation * Fix examples to dispatch to strand +* Ensure basic_stream::close will not throw -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/basic_stream.hpp b/include/boost/beast/core/basic_stream.hpp index c92793e4..0768dd84 100644 --- a/include/boost/beast/core/basic_stream.hpp +++ b/include/boost/beast/core/basic_stream.hpp @@ -291,8 +291,8 @@ private: template void on_timer(Executor2 const& ex2); - void reset(); // set timeouts to never - void close(); // cancel everything + void reset(); // set timeouts to never + void close() noexcept; // cancel everything }; // We use shared ownership for the state so it can diff --git a/include/boost/beast/core/impl/basic_stream.hpp b/include/boost/beast/core/impl/basic_stream.hpp index 4cb5058a..0e70f7ce 100644 --- a/include/boost/beast/core/impl/basic_stream.hpp +++ b/include/boost/beast/core/impl/basic_stream.hpp @@ -143,21 +143,19 @@ template void basic_stream:: impl_type:: -close() +close() noexcept { { error_code ec; socket.close(ec); } - timer.cancel(); - - - // have to let the read/write ops cancel the timer, - // otherwise we will get error::timeout on close when - // we actually want net::error::operation_aborted. - // - //read.timer.cancel(); - //write.timer.cancel(); + try + { + timer.cancel(); + } + catch(...) + { + } } //------------------------------------------------------------------------------