TLA Line data 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/detail/scheduler_op.hpp>
14 :
15 : #include <atomic>
16 : #include <cstddef>
17 : #include <memory>
18 :
19 : namespace boost::corosio::detail {
20 :
21 : /** Non-template base for reactor operations.
22 :
23 : Holds per-operation state accessed by reactor_descriptor_state
24 : and reactor_socket without requiring knowledge of the concrete
25 : backend socket/acceptor types. This avoids duplicate template
26 : instantiations for the descriptor_state and scheduler hot paths.
27 :
28 : @see reactor_op
29 : */
30 : struct reactor_op_base : scheduler_op
31 : {
32 : /// Errno from the last I/O attempt.
33 : int errn = 0;
34 :
35 : /// Bytes transferred on success.
36 : std::size_t bytes_transferred = 0;
37 :
38 : /// True when cancellation has been requested.
39 : std::atomic<bool> cancelled{false};
40 :
41 : /// Prevents use-after-free when socket is closed with pending ops.
42 : std::shared_ptr<void> impl_ptr;
43 :
44 : /// Record the result of an I/O attempt.
45 HIT 116581 : void complete(int err, std::size_t bytes) noexcept
46 : {
47 116581 : errn = err;
48 116581 : bytes_transferred = bytes;
49 116581 : }
50 :
51 : /// Perform the I/O syscall (overridden by concrete op types).
52 MIS 0 : virtual void perform_io() noexcept {}
53 :
54 : /// Mark as cancelled (visible to the I/O completion path).
55 HIT 204056 : void request_cancel() noexcept
56 : {
57 204056 : cancelled.store(true, std::memory_order_release);
58 204056 : }
59 :
60 : /// Destroy without invoking.
61 MIS 0 : void destroy() override
62 : {
63 0 : impl_ptr.reset();
64 0 : }
65 : };
66 :
67 : } // namespace boost::corosio::detail
68 :
69 : #endif // BOOST_COROSIO_NATIVE_DETAIL_REACTOR_REACTOR_OP_BASE_HPP
|