Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:25

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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 // Official repository: https://github.com/boostorg/beast
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;    // for timing out
0050         tick_type tick = 0;         // counts waits
0051         bool pending = false;       // if op is pending
0052         bool timeout = false;       // if timed out
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             // If this assert goes off, it means you are attempting
0085             // to issue two of the same asynchronous I/O operation
0086             // at the same time, without waiting for the first one
0087             // to complete. For example, attempting two simultaneous
0088             // calls to async_read_some. Only one pending call of
0089             // each I/O type (read and write) is permitted.
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             // If this assert goes off, it means you are attempting
0110             // to issue two of the same asynchronous I/O operation
0111             // at the same time, without waiting for the first one
0112             // to complete. For example, attempting two simultaneous
0113             // calls to async_read_some. Only one pending call of
0114             // each I/O type (read and write) is permitted.
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 } // detail
0140 } // beast
0141 } // boost
0142 
0143 #endif