read.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright (c) 2025 Klemens Morgenstern (klemens.morgenstern@gmx.net)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BOOST_COBALT_IO_READ_HPP
  8. #define BOOST_COBALT_IO_READ_HPP
  9. #include <boost/cobalt/io/detail/config.hpp>
  10. #include <boost/cobalt/io/buffer.hpp>
  11. #include <boost/cobalt/io/ops.hpp>
  12. #include <concepts>
  13. namespace boost::cobalt::io
  14. {
  15. struct BOOST_COBALT_IO_DECL read_all final : op<system::error_code, std::size_t>
  16. {
  17. read_op step;
  18. read_all(read_op op) : step(op) {}
  19. ~read_all() = default;
  20. void initiate(completion_handler<system::error_code, std::size_t>) final;
  21. };
  22. template<typename Stream>
  23. requires requires (Stream & str, mutable_buffer_sequence buffer)
  24. {
  25. {str.read_some(buffer)} -> std::same_as<read_op>;
  26. }
  27. [[nodiscard]] BOOST_COBALT_MSVC_NOINLINE
  28. read_all read(Stream & str, mutable_buffer_sequence buffer)
  29. {
  30. return read_all{str.read_some(buffer)};
  31. }
  32. struct BOOST_COBALT_IO_DECL read_all_at final : op<system::error_code, std::size_t>
  33. {
  34. read_at_op step;
  35. read_all_at(read_at_op op) : step(op) {}
  36. ~read_all_at() = default;
  37. void initiate(completion_handler<system::error_code, std::size_t>) final;
  38. };
  39. template<typename Stream>
  40. requires requires (Stream & str, std::uint64_t offset, mutable_buffer_sequence buffer)
  41. {
  42. {str.read_some_at(offset, buffer)} -> std::same_as<read_at_op>;
  43. }
  44. [[nodiscard]] BOOST_COBALT_MSVC_NOINLINE
  45. read_all_at read_at(Stream & str, std::uint64_t offset, mutable_buffer_sequence buffer)
  46. {
  47. return read_all_at{str.read_some_at(offset, buffer)};
  48. }
  49. }
  50. #endif //BOOST_COBALT_IO_READ_HPP