include/boost/corosio/native/detail/reactor/reactor_op_base.hpp

100.0% Lines (7 / 7) 100.0% Functions (2 / 2)
reactor_op_base.hpp
f(x) Functions (2)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Steve Gerbino
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 // Official repository: https://github.com/cppalliance/corosio
8 //
9
10 #ifndef BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_OP_BASE_HPP
11 #define BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_OP_BASE_HPP
12
13 #include <boost/corosio/native/detail/coro_op.hpp>
14
15 #include <cstddef>
16
17 namespace boost::corosio::detail {
18
19 /** Non-template base for reactor operations.
20
21 Adds the reactor-specific result model (the recorded errno + bytes and
22 the perform_io() readiness re-run) on top of coro_op, the shared op
23 envelope (coroutine handle, executor, output pointers, stop_token wiring,
24 cancelled flag, object_ref_ keepalive) common to every backend.
25
26 Kept as a non-template layer so reactor_descriptor_state and the
27 scheduler hot paths can touch op state without knowing the concrete
28 socket/acceptor types.
29
30 @see coro_op, reactor_op
31 */
32 struct reactor_op_base : coro_op
33 {
34 /// Errno from the last I/O attempt.
35 int errn = 0;
36
37 /// Bytes transferred on success.
38 std::size_t bytes_transferred = 0;
39
40 // cancelled, object_ref_, and request_cancel() are inherited from coro_op.
41
42 /// Record the result of an I/O attempt.
43 102544x void complete(int err, std::size_t bytes) noexcept
44 {
45 102544x errn = err;
46 102544x bytes_transferred = bytes;
47 102544x }
48
49 /// Perform the I/O syscall (implemented by concrete op types).
50 virtual void perform_io() noexcept = 0;
51
52 /// Destroy without invoking — drop the keepalive held in
53 /// coro_op's `object_ref_`.
54 56x void destroy() override
55 {
56 56x object_ref_.reset();
57 56x }
58 };
59
60 } // namespace boost::corosio::detail
61
62 #endif // BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_OP_BASE_HPP
63