File indexing completed on 2025-01-18 09:29:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_CORE_DETAIL_STREAM_BASE_HPP
0011 #define BOOST_BEAST_CORE_DETAIL_STREAM_BASE_HPP
0012
0013 #include <boost/asio/steady_timer.hpp>
0014 #include <boost/assert.hpp>
0015 #include <boost/core/exchange.hpp>
0016 #include <chrono>
0017 #include <cstdint>
0018 #include <utility>
0019
0020 namespace boost {
0021 namespace beast {
0022 namespace detail {
0023
0024 struct any_endpoint
0025 {
0026 template<class Error, class Endpoint>
0027 bool
0028 operator()(
0029 Error const&, Endpoint const&) const noexcept
0030 {
0031 return true;
0032 }
0033 };
0034
0035 struct stream_base
0036 {
0037 using clock_type = std::chrono::steady_clock;
0038 using time_point = typename
0039 std::chrono::steady_clock::time_point;
0040 using tick_type = std::uint64_t;
0041
0042 template<typename Executor>
0043 struct basic_op_state
0044 {
0045 net::basic_waitable_timer<
0046 std::chrono::steady_clock,
0047 net::wait_traits<
0048 std::chrono::steady_clock>,
0049 Executor> timer;
0050 tick_type tick = 0;
0051 bool pending = false;
0052 bool timeout = false;
0053
0054 template<class... Args>
0055 explicit
0056 basic_op_state(Args&&... args)
0057 : timer(std::forward<Args>(args)...)
0058 {
0059 }
0060 };
0061
0062 class pending_guard
0063 {
0064 bool* b_ = nullptr;
0065 bool clear_ = true;
0066
0067 public:
0068 ~pending_guard()
0069 {
0070 if(clear_ && b_)
0071 *b_ = false;
0072 }
0073
0074 pending_guard()
0075 : b_(nullptr)
0076 , clear_(true)
0077 {
0078 }
0079
0080 explicit
0081 pending_guard(bool& b)
0082 : b_(&b)
0083 {
0084
0085
0086
0087
0088
0089
0090
0091 BOOST_ASSERT(! *b_);
0092 *b_ = true;
0093 }
0094
0095 pending_guard(
0096 pending_guard&& other) noexcept
0097 : b_(other.b_)
0098 , clear_(boost::exchange(
0099 other.clear_, false))
0100 {
0101 }
0102
0103 void assign(bool& b)
0104 {
0105 BOOST_ASSERT(!b_);
0106 BOOST_ASSERT(clear_);
0107 b_ = &b;
0108
0109
0110
0111
0112
0113
0114
0115
0116 BOOST_ASSERT(! *b_);
0117 *b_ = true;
0118 }
0119
0120 void
0121 reset()
0122 {
0123 BOOST_ASSERT(clear_);
0124 if (b_)
0125 *b_ = false;
0126 clear_ = false;
0127 }
0128 };
0129
0130 static time_point never() noexcept
0131 {
0132 return (time_point::max)();
0133 }
0134
0135 static std::size_t constexpr no_limit =
0136 (std::numeric_limits<std::size_t>::max)();
0137 };
0138
0139 }
0140 }
0141 }
0142
0143 #endif