From e55670d0d0dfbc1c6844bba90605a025649a7188 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Tue, 26 Nov 2024 06:48:05 +0000 Subject: [PATCH] Remove Boost.Scope dependency from examples --- CMakeLists.txt | 46 +++++++++---------- .../server-flex-awaitable/CMakeLists.txt | 2 +- .../advanced/server-flex-awaitable/Jamfile | 1 - .../advanced_server_flex_awaitable.cpp | 40 ++++++++++++---- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 850f4689..fd432df3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,28 +55,28 @@ set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use #------------------------------------------------- # The boost super-project requires one explicit dependency per-line. set(BOOST_BEAST_DEPENDENCIES - Boost::asio - Boost::assert - Boost::bind - Boost::config - Boost::container - Boost::container_hash - Boost::core - Boost::endian - Boost::intrusive - Boost::logic - Boost::mp11 - Boost::optional - Boost::preprocessor - Boost::smart_ptr - Boost::static_assert - Boost::static_string - Boost::system - Boost::throw_exception - Boost::type_index - Boost::type_traits - Boost::winapi - ) + Boost::asio + Boost::assert + Boost::bind + Boost::config + Boost::container + Boost::container_hash + Boost::core + Boost::endian + Boost::intrusive + Boost::logic + Boost::mp11 + Boost::optional + Boost::preprocessor + Boost::smart_ptr + Boost::static_assert + Boost::static_string + Boost::system + Boost::throw_exception + Boost::type_index + Boost::type_traits + Boost::winapi) + foreach (BOOST_BEAST_DEPENDENCY ${BOOST_BEAST_DEPENDENCIES}) if (BOOST_BEAST_DEPENDENCY MATCHES "^[ ]*Boost::([A-Za-z0-9_]+)[ ]*$") list(APPEND BOOST_BEAST_INCLUDE_LIBRARIES ${CMAKE_MATCH_1}) @@ -87,7 +87,7 @@ if (BOOST_BEAST_BUILD_TESTS) set(BOOST_BEAST_UNIT_TEST_LIBRARIES filesystem) endif () if (BOOST_BEAST_BUILD_EXAMPLES) - set(BOOST_BEAST_EXAMPLE_LIBRARIES scope json) + set(BOOST_BEAST_EXAMPLE_LIBRARIES json) endif () # Complete dependency list set(BOOST_INCLUDE_LIBRARIES ${BOOST_BEAST_INCLUDE_LIBRARIES} ${BOOST_BEAST_UNIT_TEST_LIBRARIES} ${BOOST_BEAST_EXAMPLE_LIBRARIES}) diff --git a/example/advanced/server-flex-awaitable/CMakeLists.txt b/example/advanced/server-flex-awaitable/CMakeLists.txt index 0090f601..3e557b1a 100644 --- a/example/advanced/server-flex-awaitable/CMakeLists.txt +++ b/example/advanced/server-flex-awaitable/CMakeLists.txt @@ -20,7 +20,7 @@ target_include_directories(advanced-server-flex-awaitable PRIVATE ${PROJECT_SOURCE_DIR}) target_link_libraries(advanced-server-flex-awaitable - PRIVATE Boost::beast Boost::scope OpenSSL::SSL OpenSSL::Crypto) + PRIVATE Boost::beast OpenSSL::SSL OpenSSL::Crypto) set_target_properties(advanced-server-flex-awaitable PROPERTIES FOLDER "example-advanced-server") diff --git a/example/advanced/server-flex-awaitable/Jamfile b/example/advanced/server-flex-awaitable/Jamfile index 8b090c54..bf60ef0e 100644 --- a/example/advanced/server-flex-awaitable/Jamfile +++ b/example/advanced/server-flex-awaitable/Jamfile @@ -12,7 +12,6 @@ import ac ; project : requirements [ ac.check-library /boost/beast/test//lib-asio-ssl : /boost/beast/test//lib-asio-ssl/static : no ] - /boost/scope//boost_scope ; exe advanced-server-flex-awaitable : diff --git a/example/advanced/server-flex-awaitable/advanced_server_flex_awaitable.cpp b/example/advanced/server-flex-awaitable/advanced_server_flex_awaitable.cpp index f5da650b..0c62719d 100644 --- a/example/advanced/server-flex-awaitable/advanced_server_flex_awaitable.cpp +++ b/example/advanced/server-flex-awaitable/advanced_server_flex_awaitable.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -243,17 +242,42 @@ public: auto lg = std::lock_guard{ mtx_ }; auto cs = css_.emplace(css_.end()); + class remover + { + task_group* tg_; + decltype(css_)::iterator cs_; + + public: + remover( + task_group* tg, + decltype(css_)::iterator cs) + : tg_{ tg } + , cs_{ cs } + { + } + + remover(remover&& other) noexcept + : tg_{ std::exchange(other.tg_, nullptr) } + , cs_{ other.cs_ } + { + } + + ~remover() + { + if(tg_) + { + auto lg = std::lock_guard{ tg_->mtx_ }; + if(tg_->css_.erase(cs_) == tg_->css_.end()) + tg_->cv_.cancel(); + } + } + }; + return net::bind_cancellation_slot( cs->slot(), net::consign( std::forward(completion_token), - boost::scope::make_scope_exit( - [this, cs]() - { - auto lg = std::lock_guard{ mtx_ }; - if(css_.erase(cs) == css_.end()) - cv_.cancel(); - }))); + remover{ this, cs })); } /** Emits the signal to all child tasks and invokes the slot's