include/boost/corosio/io/io_read_stream.hpp
91.7% Lines (11 / 12)
50.0% Branches (6 / 12)
96.3% Functions (26 / 27)
Functions (27)
Function
Calls
Lines
Branches
Blocks
boost::corosio::io_read_stream::~io_read_stream()
:47
44305x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::detail::slice_of<boost::capy::mutable_buffer>>::read_some_awaitable(boost::corosio::io_read_stream::read_some_awaitable<boost::capy::detail::slice_of<boost::capy::mutable_buffer>>&&)
:52
78x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::detail::slice_of<boost::capy::mutable_buffer>>::~read_some_awaitable()
:52
156x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::mutable_buffer>::read_some_awaitable(boost::corosio::io_read_stream::read_some_awaitable<boost::capy::mutable_buffer>&&)
:52
1250589x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::mutable_buffer>::~read_some_awaitable()
:52
2501180x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 2ul>>::read_some_awaitable(boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 2ul>>&&)
:52
26x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 2ul>>::~read_some_awaitable()
:52
52x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 3ul>>::read_some_awaitable(boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 3ul>>&&)
:52
8x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 3ul>>::~read_some_awaitable()
:52
16x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul>>::read_some_awaitable(boost::corosio::io_read_stream::read_some_awaitable<std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul>>&&)
:52
0
100.0%
–
0.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul>>::~read_some_awaitable()
:52
35412x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::detail::slice_of<boost::capy::mutable_buffer>>::read_some_awaitable(boost::corosio::io_read_stream&, boost::capy::detail::slice_of<boost::capy::mutable_buffer>)
:58
78x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::mutable_buffer>::read_some_awaitable(boost::corosio::io_read_stream&, boost::capy::mutable_buffer)
:58
1250582x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 2ul>>::read_some_awaitable(boost::corosio::io_read_stream&, std::__1::array<boost::capy::mutable_buffer, 2ul>)
:58
26x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 3ul>>::read_some_awaitable(boost::corosio::io_read_stream&, std::__1::array<boost::capy::mutable_buffer, 3ul>)
:58
8x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul>>::read_some_awaitable(boost::corosio::io_read_stream&, std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul>)
:58
35412x
100.0%
–
100.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::detail::slice_of<boost::capy::mutable_buffer>>::dispatch(boost::capy::continuation&, boost::capy::executor_ref) const
:71
38x
75.0%
33.3%
50.0%
boost::corosio::io_read_stream::read_some_awaitable<boost::capy::mutable_buffer>::dispatch(boost::capy::continuation&, boost::capy::executor_ref) const
:71
625280x
75.0%
50.0%
50.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 2ul>>::dispatch(boost::capy::continuation&, boost::capy::executor_ref) const
:71
13x
75.0%
33.3%
50.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::array<boost::capy::mutable_buffer, 3ul>>::dispatch(boost::capy::continuation&, boost::capy::executor_ref) const
:71
4x
75.0%
25.0%
50.0%
boost::corosio::io_read_stream::read_some_awaitable<std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul>>::dispatch(boost::capy::continuation&, boost::capy::executor_ref) const
:71
17705x
75.0%
25.0%
50.0%
boost::corosio::io_read_stream::io_read_stream()
:99
44300x
100.0%
–
100.0%
auto boost::corosio::io_read_stream::read_some<boost::capy::detail::slice_of<boost::capy::mutable_buffer>>(boost::capy::detail::slice_of<boost::capy::mutable_buffer> const&)
:130
39x
100.0%
–
100.0%
auto boost::corosio::io_read_stream::read_some<boost::capy::mutable_buffer>(boost::capy::mutable_buffer const&)
:130
625292x
100.0%
–
100.0%
auto boost::corosio::io_read_stream::read_some<std::__1::array<boost::capy::mutable_buffer, 2ul>>(std::__1::array<boost::capy::mutable_buffer, 2ul> const&)
:130
13x
100.0%
–
100.0%
auto boost::corosio::io_read_stream::read_some<std::__1::array<boost::capy::mutable_buffer, 3ul>>(std::__1::array<boost::capy::mutable_buffer, 3ul> const&)
:130
4x
100.0%
–
100.0%
auto boost::corosio::io_read_stream::read_some<std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul>>(std::__1::span<boost::capy::mutable_buffer const, 18446744073709551615ul> const&)
:130
17706x
100.0%
–
100.0%
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2026 Steve Gerbino | |||
| 3 | // Copyright (c) 2026 Michael Vandeberg | |||
| 4 | // | |||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 7 | // | |||
| 8 | // Official repository: https://github.com/cppalliance/corosio | |||
| 9 | // | |||
| 10 | ||||
| 11 | #ifndef BOOST_COROSIO_IO_IO_READ_STREAM_HPP | |||
| 12 | #define BOOST_COROSIO_IO_IO_READ_STREAM_HPP | |||
| 13 | ||||
| 14 | #include <boost/corosio/detail/config.hpp> | |||
| 15 | #include <boost/corosio/detail/op_base.hpp> | |||
| 16 | #include <boost/corosio/io/io_object.hpp> | |||
| 17 | #include <boost/corosio/detail/buffer_param.hpp> | |||
| 18 | #include <boost/capy/results.hpp> | |||
| 19 | #include <boost/capy/ex/executor_ref.hpp> | |||
| 20 | #include <boost/capy/ex/await_context.hpp> | |||
| 21 | ||||
| 22 | #include <boost/capy/continuation.hpp> | |||
| 23 | ||||
| 24 | #include <coroutine> | |||
| 25 | #include <cstddef> | |||
| 26 | #include <stop_token> | |||
| 27 | #include <system_error> | |||
| 28 | ||||
| 29 | namespace boost::corosio { | |||
| 30 | ||||
| 31 | /** Reads bytes from a stream asynchronously. | |||
| 32 | ||||
| 33 | Provides the `read_some` operation via a pure virtual | |||
| 34 | `do_read_some` dispatch point. Concrete classes override | |||
| 35 | `do_read_some` to route through their implementation. | |||
| 36 | ||||
| 37 | Uses virtual inheritance from @ref io_object so that | |||
| 38 | @ref io_stream can combine this with @ref io_write_stream | |||
| 39 | without duplicating the `io_object` base. | |||
| 40 | ||||
| 41 | @par Thread Safety | |||
| 42 | Distinct objects: Safe. | |||
| 43 | Shared objects: Unsafe. | |||
| 44 | ||||
| 45 | @see @ref io_write_stream, @ref io_stream, @ref io_object | |||
| 46 | */ | |||
| 47 | class BOOST_COROSIO_DECL io_read_stream : virtual public io_object | |||
| 48 | { | |||
| 49 | protected: | |||
| 50 | /// Awaitable for async read operations. | |||
| 51 | template<class MutableBufferSequence> | |||
| 52 | struct read_some_awaitable | |||
| 53 | : detail::bytes_op_base<read_some_awaitable<MutableBufferSequence>> | |||
| 54 | { | |||
| 55 | private: | |||
| 56 | friend io_read_stream; | |||
| 57 | ||||
| 58 | 1286106x | read_some_awaitable( | ||
| 59 | io_read_stream& ios, MutableBufferSequence buffers) noexcept | |||
| 60 | 643053x | : ios_(ios) | ||
| 61 | 643053x | , buffers_(std::move(buffers)) | ||
| 62 | 643053x | { | ||
| 63 | 1286106x | } | ||
| 64 | ||||
| 65 | friend detail::bytes_op_base< | |||
| 66 | read_some_awaitable<MutableBufferSequence>>; | |||
| 67 | io_read_stream& ios_; | |||
| 68 | MutableBufferSequence buffers_; | |||
| 69 | ||||
| 70 | std::coroutine_handle<> | |||
| 71 | 643040x | dispatch(capy::continuation& cont, capy::executor_ref ex) const | ||
| 72 | { | |||
| 73 |
6/12✓ Branch 0 taken 642974 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 642974 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 43 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 43 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
|
1286080x | return ios_.do_read_some( | |
| 74 | 643040x | cont, ex, buffers_, this->token_, &this->ec_, &this->bytes_); | ||
| 75 | ✗ | } | ||
| 76 | }; | |||
| 77 | ||||
| 78 | /** Dispatch a read through the concrete implementation. | |||
| 79 | ||||
| 80 | @param cont Continuation to resume on completion; it lives in | |||
| 81 | the awaiting frame until then. | |||
| 82 | @param ex Executor for dispatching the completion. | |||
| 83 | @param buffers Target buffer sequence. | |||
| 84 | @param token Stop token for cancellation. | |||
| 85 | @param ec Output error code. | |||
| 86 | @param bytes Output bytes transferred. | |||
| 87 | ||||
| 88 | @return Coroutine handle to resume immediately. | |||
| 89 | */ | |||
| 90 | virtual std::coroutine_handle<> do_read_some( | |||
| 91 | capy::continuation& cont, | |||
| 92 | capy::executor_ref ex, | |||
| 93 | detail::buffer_param buffers, | |||
| 94 | std::stop_token token, | |||
| 95 | std::error_code* ec, | |||
| 96 | std::size_t* bytes) = 0; | |||
| 97 | ||||
| 98 | /// Default construct; the handle is supplied through @ref io_object. | |||
| 99 | 44300x | io_read_stream() noexcept = default; | ||
| 100 | ||||
| 101 | /// Move construct; the handle moves with @ref io_object. | |||
| 102 | io_read_stream(io_read_stream&&) noexcept = default; | |||
| 103 | /// Move assignment is disabled; reseating a live stream is not supported. | |||
| 104 | io_read_stream& operator=(io_read_stream&&) noexcept = delete; | |||
| 105 | /// Copy construction is disabled; the handle is uniquely owned. | |||
| 106 | io_read_stream(io_read_stream const&) = delete; | |||
| 107 | /// Copy assignment is disabled; the handle is uniquely owned. | |||
| 108 | io_read_stream& operator=(io_read_stream const&) = delete; | |||
| 109 | ||||
| 110 | public: | |||
| 111 | /** Asynchronously read data from the stream. | |||
| 112 | ||||
| 113 | Suspends the calling coroutine and initiates a kernel-level | |||
| 114 | read. The coroutine resumes when at least one byte is read, | |||
| 115 | an error occurs, or the operation is cancelled. | |||
| 116 | ||||
| 117 | This stream must outlive the returned awaitable. The memory | |||
| 118 | referenced by @p buffers must remain valid until the operation | |||
| 119 | completes. | |||
| 120 | ||||
| 121 | A closed stream completes with `errc::bad_file_descriptor`. | |||
| 122 | ||||
| 123 | @param buffers The buffer sequence to read data into. | |||
| 124 | ||||
| 125 | @return An awaitable yielding `(error_code, std::size_t)`. | |||
| 126 | ||||
| 127 | @see @ref io_stream::write_some | |||
| 128 | */ | |||
| 129 | template<capy::MutableBufferSequence MB> | |||
| 130 | 643054x | [[nodiscard]] auto read_some(MB const& buffers) | ||
| 131 | { | |||
| 132 | 643054x | return read_some_awaitable<MB>(*this, buffers); | ||
| 133 | } | |||
| 134 | }; | |||
| 135 | ||||
| 136 | } // namespace boost::corosio | |||
| 137 | ||||
| 138 | #endif | |||
| 139 |