include/boost/corosio/native/detail/iocp/win_random_access_handle_service.hpp

100.0% Lines (44/44) 100.0% List of functions (14/14) 80.0% Branches (8/10)
win_random_access_handle_service.hpp
f(x) Functions (14)
Function Calls Lines Branches Blocks
boost::corosio::detail::win_random_access_handle_impl::win_random_access_handle_impl(std::shared_ptr<boost::corosio::detail::win_concurrent_handle>) :33 24x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::close_internal() :39 23x 100.0% 50.0% 100.0% boost::corosio::detail::win_random_access_handle_impl::get_internal() const :48 63x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::read_some_at(unsigned long long, boost::capy::continuation&, boost::capy::executor_ref, boost::corosio::buffer_param, std::stop_token, std::error_code*, unsigned long long*) :53 15x 100.0% 100.0% 81.8% boost::corosio::detail::win_random_access_handle_impl::write_some_at(unsigned long long, boost::capy::continuation&, boost::capy::executor_ref, boost::corosio::buffer_param, std::stop_token, std::error_code*, unsigned long long*) :66 36x 100.0% 100.0% 81.8% boost::corosio::detail::win_random_access_handle_impl::native_handle() const :79 116x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::release_handle() :84 4x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::cancel() :89 1x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_service::win_random_access_handle_service(boost::capy::execution_context&) :100 24x 100.0% 100.0% 83.3% boost::corosio::detail::win_random_access_handle_service::construct() :105 24x 100.0% 100.0% 85.7% boost::corosio::detail::win_random_access_handle_service::destroy(boost::corosio::io_object::implementation*) :112 23x 100.0% 50.0% 100.0% boost::corosio::detail::win_random_access_handle_service::close(boost::corosio::io_object::handle&) :118 39x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_service::shutdown() :125 24x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_service::assign_random_access_handle(boost::corosio::win_random_access_handle::implementation&, unsigned long long) :130 24x 100.0% – 100.0%
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Michael Vandeberg
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_IOCP_WIN_RANDOM_ACCESS_HANDLE_SERVICE_HPP
11 #define BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_RANDOM_ACCESS_HANDLE_SERVICE_HPP
12
13 #include <boost/corosio/detail/platform.hpp>
14
15 #if BOOST_COROSIO_HAS_IOCP
16
17 #include <boost/corosio/detail/config.hpp>
18 #include <boost/corosio/detail/win_handle_service.hpp>
19 #include <boost/corosio/native/detail/iocp/win_overlapped_handle.hpp>
20
21 #include <memory>
22
23 namespace boost::corosio::detail {
24
25 /** IOCP implementation of @ref win_random_access_handle: any number of positional operations. */
26 class win_random_access_handle_impl final
27 : public win_random_access_handle::implementation
28 , public intrusive_list<win_random_access_handle_impl>::node
29 {
30 std::shared_ptr<win_concurrent_handle> internal_;
31
32 public:
33 24x explicit win_random_access_handle_impl(
34 std::shared_ptr<win_concurrent_handle> internal) noexcept
35 24x : internal_(std::move(internal))
36 {
37 24x }
38
39 23x void close_internal() noexcept
40 {
41
1/2
✓ Branch 3 → 4 taken 23 times.
✗ Branch 3 → 7 not taken.
23x if (internal_)
42 {
43 23x internal_->close_handle();
44 23x internal_.reset();
45 }
46 23x }
47
48 63x win_concurrent_handle* get_internal() const noexcept
49 {
50 63x return internal_.get();
51 }
52
53 15x std::coroutine_handle<> read_some_at(
54 std::uint64_t offset,
55 capy::continuation& cont,
56 capy::executor_ref ex,
57 buffer_param buf,
58 std::stop_token token,
59 std::error_code* ec,
60 std::size_t* bytes) override
61 {
62
1/1
✓ Branch 5 → 6 taken 15 times.
45x return internal_->read_some_at(
63 45x offset, cont, ex, buf, std::move(token), ec, bytes);
64 }
65
66 36x std::coroutine_handle<> write_some_at(
67 std::uint64_t offset,
68 capy::continuation& cont,
69 capy::executor_ref ex,
70 buffer_param buf,
71 std::stop_token token,
72 std::error_code* ec,
73 std::size_t* bytes) override
74 {
75
1/1
✓ Branch 5 → 6 taken 36 times.
108x return internal_->write_some_at(
76 108x offset, cont, ex, buf, std::move(token), ec, bytes);
77 }
78
79 116x native_handle_type native_handle() const noexcept override
80 {
81 116x return reinterpret_cast<native_handle_type>(internal_->native_handle());
82 }
83
84 4x native_handle_type release_handle() override
85 {
86 4x return internal_->release();
87 }
88
89 1x void cancel() noexcept override
90 {
91 1x internal_->cancel();
92 1x }
93 };
94
95 /** IOCP service that owns the @ref win_random_access_handle implementations. */
96 class BOOST_COROSIO_DECL win_random_access_handle_service final
97 : public random_access_handle_service
98 {
99 public:
100 24x explicit win_random_access_handle_service(capy::execution_context& ctx)
101
2/2
✓ Branch 3 → 4 taken 24 times.
✓ Branch 4 → 5 taken 24 times.
24x : sched_(ctx.use_service<win_scheduler>())
102 {
103 24x }
104
105 24x io_object::implementation* construct() override
106 {
107 auto internal = std::make_shared<win_concurrent_handle>(
108
1/1
✓ Branch 3 → 4 taken 24 times.
24x sched_, reg_.states());
109
1/1
✓ Branch 4 → 5 taken 24 times.
48x return reg_.add(new win_random_access_handle_impl(std::move(internal)));
110 24x }
111
112 23x void destroy(io_object::implementation* p) override
113 {
114
1/2
✓ Branch 2 → 3 taken 23 times.
✗ Branch 2 → 4 not taken.
23x if (p)
115 23x reg_.destroy(static_cast<win_random_access_handle_impl&>(*p));
116 23x }
117
118 39x void close(io_object::handle& h) override
119 {
120 39x static_cast<win_random_access_handle_impl&>(*h.get())
121 39x .get_internal()
122 39x ->close_handle();
123 39x }
124
125 24x void shutdown() override
126 {
127 24x reg_.shutdown();
128 24x }
129
130 24x std::error_code assign_random_access_handle(
131 win_random_access_handle::implementation& impl,
132 native_handle_type h) override
133 {
134 return static_cast<win_random_access_handle_impl&>(impl)
135 .get_internal()
136 24x ->assign(h, handle_kind::random_access_handle);
137 }
138
139 private:
140 win_scheduler& sched_;
141 BOOST_COROSIO_MSVC_WARNING_PUSH
142 BOOST_COROSIO_MSVC_WARNING_DISABLE(4251) // detail:: members, dll-interface
143 win_handle_registry<win_random_access_handle_impl, win_handle_base> reg_;
144 BOOST_COROSIO_MSVC_WARNING_POP
145 };
146
147 } // namespace boost::corosio::detail
148
149 #endif // BOOST_COROSIO_HAS_IOCP
150
151 #endif
152