Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:28:51

0001 //
0002 // Copyright (c) 2023 Klemens Morgenstern (klemens.morgenstern@gmx.net)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_BEAST_TEST_IMMEDIATE_EXECUTOR_HPP
0009 #define BOOST_BEAST_TEST_IMMEDIATE_EXECUTOR_HPP
0010 
0011 #include <boost/asio/any_io_executor.hpp>
0012 #include <boost/asio/execution_context.hpp>
0013 
0014 namespace boost
0015 {
0016 namespace beast
0017 {
0018 namespace test
0019 {
0020 
0021 /** A immediate executor that directly invokes and counts how often that happened. */
0022 
0023 class immediate_executor
0024 {
0025     asio::execution_context* context_ = nullptr;
0026     std::size_t &count_;
0027 
0028   public:
0029     immediate_executor(std::size_t & count) noexcept : count_(count) {}
0030 
0031     asio::execution_context &query(asio::execution::context_t) const noexcept
0032     {
0033         BOOST_ASSERT(false);
0034         return *context_;
0035     }
0036 
0037     constexpr static asio::execution::blocking_t
0038     query(asio::execution::blocking_t) noexcept
0039     {
0040         return asio::execution::blocking_t::never_t{};
0041     }
0042 
0043     constexpr static asio::execution::relationship_t
0044     query(asio::execution::relationship_t) noexcept
0045     {
0046         return asio::execution::relationship_t::fork_t{};
0047     }
0048     // this function takes the function F and runs it on the event loop.
0049     template<class F>
0050     void
0051     execute(F f) const
0052     {
0053         count_++;
0054         std::forward<F>(f)();
0055     }
0056 
0057     bool
0058     operator==(immediate_executor const &) const noexcept
0059     {
0060         return true;
0061     }
0062 
0063     bool
0064     operator!=(immediate_executor const &) const noexcept
0065     {
0066         return false;
0067     }
0068 };
0069 
0070 } // test
0071 } // beast
0072 
0073 #if ! BOOST_BEAST_DOXYGEN
0074 namespace asio
0075 {
0076 namespace traits
0077 {
0078 template<typename F>
0079 struct execute_member<beast::test::immediate_executor, F>
0080 {
0081     static constexpr bool is_valid    = true;
0082     static constexpr bool is_noexcept = false;
0083     typedef void result_type;
0084 };
0085 
0086 template<>
0087 struct equality_comparable<beast::test::immediate_executor>
0088 {
0089     static constexpr bool is_valid    = true;
0090     static constexpr bool is_noexcept = true;
0091 };
0092 
0093 template<>
0094 struct query_member<beast::test::immediate_executor, execution::context_t>
0095 {
0096     static constexpr bool is_valid    = true;
0097     static constexpr bool is_noexcept = true;
0098     typedef execution_context& result_type;
0099 };
0100 
0101 template<typename Property>
0102 struct query_static_constexpr_member<
0103     beast::test::immediate_executor,
0104     Property,
0105     typename enable_if<std::is_convertible<Property, execution::blocking_t>::value>::type>
0106 {
0107     static constexpr bool is_valid    = true;
0108     static constexpr bool is_noexcept = true;
0109     typedef execution::blocking_t::never_t result_type;
0110     static constexpr result_type value() noexcept
0111     {
0112         return result_type();
0113     }
0114 };
0115 } // traits
0116 } // asio
0117 #endif
0118 
0119 } // boost
0120 
0121 #endif //BOOST_BEAST_TEST_IMMEDIATE_EXECUTOR_HPP