Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 // Copyright (c) 2020 Richard Hodges (hodges.r@gmail.com)
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // Official repository: https://github.com/boostorg/beast
0009 //
0010 
0011 #ifndef BOOST_BEAST_TEST_DETAIL_STREAM_STATE_HPP
0012 #define BOOST_BEAST_TEST_DETAIL_STREAM_STATE_HPP
0013 
0014 #include <boost/asio/any_io_executor.hpp>
0015 #include <boost/beast/core/detail/config.hpp>
0016 #include <boost/beast/_experimental/test/fail_count.hpp>
0017 #include <boost/beast/core/detail/service_base.hpp>
0018 #include <boost/beast/core/flat_buffer.hpp>
0019 #include <boost/smart_ptr/weak_ptr.hpp>
0020 
0021 #include <condition_variable>
0022 #include <memory>
0023 #include <mutex>
0024 #include <vector>
0025 
0026 namespace boost {
0027 namespace beast {
0028 namespace test {
0029 namespace detail {
0030 
0031 struct stream_state;
0032 
0033 struct stream_service_impl
0034 {
0035     std::mutex m_;
0036     std::vector<stream_state*> v_;
0037 
0038     BOOST_BEAST_DECL
0039     void
0040     remove(stream_state& impl);
0041 };
0042 
0043 //------------------------------------------------------------------------------
0044 
0045 class stream_service
0046     : public beast::detail::service_base<stream_service>
0047 {
0048     boost::shared_ptr<detail::stream_service_impl> sp_;
0049 
0050     BOOST_BEAST_DECL
0051     void
0052     shutdown() override;
0053 
0054 public:
0055     BOOST_BEAST_DECL
0056     explicit
0057     stream_service(net::execution_context& ctx);
0058 
0059     BOOST_BEAST_DECL
0060     static
0061     auto
0062     make_impl(
0063         net::any_io_executor exec,
0064         test::fail_count* fc) ->
0065             boost::shared_ptr<detail::stream_state>;
0066 };
0067 
0068 //------------------------------------------------------------------------------
0069 
0070 struct stream_read_op_base
0071 {
0072     virtual ~stream_read_op_base() = default;
0073     virtual void operator()(error_code ec) = 0;
0074 };
0075 
0076 //------------------------------------------------------------------------------
0077 
0078 enum class stream_status
0079 {
0080     ok,
0081     eof,
0082 };
0083 
0084 //------------------------------------------------------------------------------
0085 
0086 struct stream_state
0087 {
0088     net::any_io_executor exec;
0089     boost::weak_ptr<stream_service_impl> wp;
0090     std::mutex m;
0091     flat_buffer b;
0092     std::condition_variable cv;
0093     std::unique_ptr<stream_read_op_base> op;
0094     stream_status code = stream_status::ok;
0095     fail_count* fc = nullptr;
0096     std::size_t nread = 0;
0097     std::size_t nread_bytes = 0;
0098     std::size_t nwrite = 0;
0099     std::size_t nwrite_bytes = 0;
0100     std::size_t read_max =
0101         (std::numeric_limits<std::size_t>::max)();
0102     std::size_t write_max =
0103         (std::numeric_limits<std::size_t>::max)();
0104 
0105     BOOST_BEAST_DECL
0106     stream_state(
0107         net::any_io_executor exec_,
0108         boost::weak_ptr<stream_service_impl> wp_,
0109         fail_count* fc_);
0110 
0111     BOOST_BEAST_DECL
0112     ~stream_state();
0113 
0114     BOOST_BEAST_DECL
0115     void
0116     remove() noexcept;
0117 
0118     BOOST_BEAST_DECL
0119     void
0120     notify_read();
0121 
0122     BOOST_BEAST_DECL
0123     void
0124     cancel_read();
0125 };
0126 
0127 
0128 
0129 } // detail
0130 } // test
0131 } // beast
0132 } // boost
0133 
0134 #ifdef BOOST_BEAST_HEADER_ONLY
0135 #include <boost/beast/_experimental/test/detail/stream_state.ipp>
0136 #endif
0137 
0138 #endif // BOOST_BEAST_TEST_DETAIL_STREAM_STATE_HPP