Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:39:19

0001 //
0002 // Copyright (c) 2025 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_COBALT_OPS_HPP
0009 #define BOOST_COBALT_OPS_HPP
0010 
0011 #include <boost/cobalt/io/detail/config.hpp>
0012 #include <boost/cobalt/config.hpp>
0013 #include <boost/cobalt/detail/handler.hpp>
0014 #include <boost/cobalt/io/buffer.hpp>
0015 #include <boost/cobalt/op.hpp>
0016 #include <boost/cobalt/result.hpp>
0017 
0018 
0019 #include <optional>
0020 
0021 namespace boost::cobalt::io
0022 {
0023 
0024 struct BOOST_COBALT_IO_DECL write_op final : op<system::error_code, std::size_t>
0025 {
0026   const_buffer_sequence buffer;
0027 
0028   using     implementation_t = void(void*, const_buffer_sequence, completion_handler<system::error_code, std::size_t>);
0029   using try_implementation_t = void(void*, const_buffer_sequence,            handler<system::error_code, std::size_t>);
0030 
0031   BOOST_COBALT_MSVC_NOINLINE
0032   write_op(const_buffer_sequence buffer,
0033            void * this_,
0034            implementation_t *implementation,
0035            try_implementation_t * try_implementation = nullptr)
0036             :  buffer(buffer), this_(this_),
0037                implementation_(implementation),
0038                try_implementation_(try_implementation)
0039   {}
0040 
0041 
0042   void initiate(completion_handler<system::error_code, std::size_t> handler) final
0043   {
0044     implementation_(this_, buffer, std::move(handler));
0045   }
0046 
0047   void ready(handler<system::error_code, std::size_t> handler) final
0048   {
0049     if (try_implementation_)
0050         try_implementation_(this_, buffer, std::move(handler));
0051   }
0052   ~write_op() = default;
0053 
0054  private:
0055   void *this_;
0056   implementation_t *implementation_;
0057   try_implementation_t * try_implementation_;
0058 };
0059 
0060 
0061 struct BOOST_COBALT_IO_DECL read_op final : op<system::error_code, std::size_t>
0062 {
0063   mutable_buffer_sequence buffer;
0064 
0065   using     implementation_t = void(void*, mutable_buffer_sequence, completion_handler<system::error_code, std::size_t>);
0066   using try_implementation_t = void(void*, mutable_buffer_sequence,            handler<system::error_code, std::size_t>);
0067 
0068   BOOST_COBALT_MSVC_NOINLINE
0069   read_op(mutable_buffer_sequence buffer,
0070            void * this_,
0071            implementation_t *implementation,
0072            try_implementation_t * try_implementation = nullptr)
0073       :  buffer(buffer), this_(this_),
0074          implementation_(implementation),
0075          try_implementation_(try_implementation)
0076   {}
0077 
0078 
0079   void initiate(completion_handler<system::error_code, std::size_t> handler) final
0080   {
0081     implementation_(this_, buffer, std::move(handler));
0082   }
0083 
0084   void ready(handler<system::error_code, std::size_t> handler) final
0085   {
0086     if (try_implementation_)
0087         try_implementation_(this_, buffer, std::move(handler));
0088   }
0089   ~read_op() = default;
0090 
0091  private:
0092   void *this_;
0093   implementation_t *implementation_;
0094   try_implementation_t * try_implementation_;
0095 };
0096 
0097 
0098 struct BOOST_COBALT_IO_DECL write_at_op final : op<system::error_code, std::size_t>
0099 {
0100   std::uint64_t offset;
0101   const_buffer_sequence buffer;
0102 
0103   using     implementation_t = void(void*, std::uint64_t, const_buffer_sequence, completion_handler<system::error_code, std::size_t>);
0104   using try_implementation_t = void(void*, std::uint64_t, const_buffer_sequence,            handler<system::error_code, std::size_t>);
0105 
0106   BOOST_COBALT_MSVC_NOINLINE
0107   write_at_op(std::uint64_t offset,
0108            const_buffer_sequence buffer,
0109            void * this_,
0110            implementation_t *implementation,
0111            try_implementation_t * try_implementation = nullptr)
0112       :  offset(offset), buffer(buffer), this_(this_),
0113          implementation_(implementation),
0114          try_implementation_(try_implementation)
0115   {}
0116 
0117 
0118   void initiate(completion_handler<system::error_code, std::size_t> handler) final
0119   {
0120     implementation_(this_, offset, buffer, std::move(handler));
0121   }
0122 
0123   void ready(handler<system::error_code, std::size_t> handler) final
0124   {
0125     if (try_implementation_)
0126         try_implementation_(this_, offset, buffer, std::move(handler));
0127   }
0128   ~write_at_op() = default;
0129  private:
0130   void *this_;
0131   implementation_t *implementation_;
0132   try_implementation_t * try_implementation_;
0133 };
0134 
0135 
0136 struct BOOST_COBALT_IO_DECL read_at_op final : op<system::error_code, std::size_t>
0137 {
0138   std::uint64_t offset;
0139   mutable_buffer_sequence buffer;
0140 
0141   using     implementation_t = void(void*, std::uint64_t, mutable_buffer_sequence, completion_handler<system::error_code, std::size_t>);
0142   using try_implementation_t = void(void*, std::uint64_t, mutable_buffer_sequence,            handler<system::error_code, std::size_t>);
0143 
0144   BOOST_COBALT_MSVC_NOINLINE
0145   read_at_op(std::uint64_t offset,
0146           mutable_buffer_sequence buffer,
0147           void * this_,
0148           implementation_t *implementation,
0149           try_implementation_t * try_implementation = nullptr)
0150       :  offset(offset), buffer(buffer), this_(this_),
0151          implementation_(implementation),
0152          try_implementation_(try_implementation)
0153   {}
0154 
0155 
0156   void initiate(completion_handler<system::error_code, std::size_t> handler) final
0157   {
0158     implementation_(this_, offset, buffer, std::move(handler));
0159   }
0160 
0161   void ready(handler<system::error_code, std::size_t> handler) final
0162   {
0163     if (try_implementation_)
0164         try_implementation_(this_, offset, buffer, std::move(handler));
0165   }
0166   ~read_at_op() = default;
0167  private:
0168   void *this_;
0169   implementation_t *implementation_;
0170   try_implementation_t * try_implementation_;
0171 };
0172 
0173 
0174 struct BOOST_COBALT_IO_DECL wait_op final : op<system::error_code>
0175 {
0176   using     implementation_t = void(void*, completion_handler<system::error_code>);
0177   using try_implementation_t = void(void*,            handler<system::error_code>);
0178 
0179   BOOST_COBALT_MSVC_NOINLINE
0180   wait_op(void * this_,
0181           implementation_t *implementation,
0182           try_implementation_t * try_implementation = nullptr)
0183       :  this_(this_),
0184          implementation_(implementation),
0185          try_implementation_(try_implementation)
0186   {}
0187 
0188 
0189   void initiate(completion_handler<system::error_code> handler) final
0190   {
0191     implementation_(this_, std::move(handler));
0192   }
0193 
0194   void ready(handler<system::error_code> handler) final
0195   {
0196     if (try_implementation_)
0197       try_implementation_(this_, std::move(handler));
0198   }
0199   ~wait_op() = default;
0200 
0201  private:
0202   void *this_;
0203   implementation_t *implementation_;
0204   try_implementation_t * try_implementation_;
0205 };
0206 
0207 
0208 }
0209 
0210 #endif //BOOST_COBALT_OPS_HPP