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

91.5% Lines (43 / 47) 62.5% Branches (5 / 8) 93.8% Functions (15 / 16)
win_random_access_handle_service.hpp
f(x) Functions (16)
Function Calls Lines Branches Blocks
boost::corosio::detail::win_random_access_handle_impl::win_random_access_handle_impl(boost::corosio::detail::win_random_access_handle_service&, boost::corosio::detail::win_scheduler&) :36 25x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::reuse() :51 0 0.0% 0.0% 0.0% boost::corosio::detail::win_random_access_handle_impl::get_internal() :56 92x 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::detail::buffer_param, std::stop_token, std::error_code*, unsigned long long*) :61 15x 100.0% 100.0% 80.0% boost::corosio::detail::win_random_access_handle_impl::write_some_at(unsigned long long, boost::capy::continuation&, boost::capy::executor_ref, boost::corosio::detail::buffer_param, std::stop_token, std::error_code*, unsigned long long*) :74 36x 100.0% 100.0% 80.0% boost::corosio::detail::win_random_access_handle_impl::native_handle() const :87 119x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::release_handle() :92 4x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::cancel() :97 1x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_service::win_random_access_handle_service(boost::capy::execution_context&) :110 25x 100.0% 100.0% 83.3% boost::corosio::detail::win_random_access_handle_service::construct() :115 25x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_service::destroy(boost::corosio::io_object::implementation*) :120 25x 83.3% 50.0% 83.3% boost::corosio::detail::win_random_access_handle_service::close(boost::corosio::io_object::handle&) :129 41x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_service::shutdown() :136 25x 100.0% 100.0% 100.0% boost::corosio::detail::win_random_access_handle_service::shutdown()::{lambda(boost::corosio::detail::win_random_access_handle_impl*)#1}::operator()(boost::corosio::detail::win_random_access_handle_impl*) const :139 2x 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) :142 24x 100.0% – 100.0% boost::corosio::detail::win_random_access_handle_impl::retire() :160 25x 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/object_pool.hpp>
19 #include <boost/corosio/detail/object_ref.hpp>
20 #include <boost/corosio/detail/win_handle_service.hpp>
21 #include <boost/corosio/native/detail/iocp/win_overlapped_handle.hpp>
22
23 namespace boost::corosio::detail {
24
25 class win_random_access_handle_service;
26
27 /** IOCP implementation of @ref win_random_access_handle: any number of positional operations. */
28 class win_random_access_handle_impl final
29 : public win_random_access_handle::implementation
30 , public intrusive_list<win_random_access_handle_impl>::node
31 {
32 win_random_access_handle_service& svc_;
33 win_concurrent_handle internal_;
34
35 public:
36 25x win_random_access_handle_impl(
37 win_random_access_handle_service& svc, win_scheduler& sched) noexcept
38 50x : svc_(svc)
39 25x , internal_(sched, *this)
40 {
41 25x }
42
43 /// Recycle into the owning service's pool. Defined out-of-line
44 /// after the service is complete.
45 void retire() noexcept override;
46
47 /** Assert the closed state a recycled handle starts from.
48
49 @pre refs_ == 0, handle closed, no op in flight.
50 */
51 ✗ void reuse() noexcept
52 {
53
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ BOOST_COROSIO_ASSERT(!internal_.is_open());
54 ✗ }
55
56 92x win_concurrent_handle* get_internal() noexcept
57 {
58 92x return &internal_;
59 }
60
61 15x std::coroutine_handle<> read_some_at(
62 std::uint64_t offset,
63 capy::continuation& cont,
64 capy::executor_ref ex,
65 buffer_param buf,
66 std::stop_token token,
67 std::error_code* ec,
68 std::size_t* bytes) override
69 {
70
1/1
✓ Branch 4 → 5 taken 15 times.
30x return internal_.read_some_at(
71 45x offset, cont, ex, buf, std::move(token), ec, bytes);
72 }
73
74 36x std::coroutine_handle<> write_some_at(
75 std::uint64_t offset,
76 capy::continuation& cont,
77 capy::executor_ref ex,
78 buffer_param buf,
79 std::stop_token token,
80 std::error_code* ec,
81 std::size_t* bytes) override
82 {
83
1/1
✓ Branch 4 → 5 taken 36 times.
72x return internal_.write_some_at(
84 108x offset, cont, ex, buf, std::move(token), ec, bytes);
85 }
86
87 119x native_handle_type native_handle() const noexcept override
88 {
89 119x return reinterpret_cast<native_handle_type>(internal_.native_handle());
90 }
91
92 4x capy::results<native_handle_type> release_handle() noexcept override
93 {
94 4x return internal_.release();
95 }
96
97 1x void cancel() noexcept override
98 {
99 1x internal_.cancel();
100 1x }
101 };
102
103 /** IOCP service that owns the @ref win_random_access_handle implementations. */
104 class BOOST_COROSIO_DECL win_random_access_handle_service final
105 : public random_access_handle_service
106 {
107 friend class win_random_access_handle_impl;
108
109 public:
110 25x explicit win_random_access_handle_service(capy::execution_context& ctx)
111
1/1
✓ Branch 3 → 4 taken 25 times.
25x : sched_(ctx.use_service<win_scheduler>())
112 {
113 25x }
114
115 25x io_object::implementation* construct() override
116 {
117 25x return pool_.acquire(*this, sched_);
118 }
119
120 25x void destroy(io_object::implementation* p) override
121 {
122
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 25 times.
25x if (!p)
123 ✗ return;
124 25x auto* impl = static_cast<win_random_access_handle_impl*>(p);
125 25x impl->get_internal()->close_handle();
126 25x release(impl);
127 }
128
129 41x void close(io_object::handle& h) override
130 {
131 41x static_cast<win_random_access_handle_impl&>(*h.get())
132 41x .get_internal()
133 41x ->close_handle();
134 41x }
135
136 25x void shutdown() override
137 {
138
1/1
✓ Branch 2 → 3 taken 25 times.
25x pool_.shutdown(
139 2x [](win_random_access_handle_impl* impl) { impl->get_internal()->close_handle(); });
140 25x }
141
142 24x std::error_code assign_random_access_handle(
143 win_random_access_handle::implementation& impl,
144 native_handle_type h) override
145 {
146 return static_cast<win_random_access_handle_impl&>(impl)
147 .get_internal()
148 24x ->assign(h, handle_kind::random_access_handle);
149 }
150
151 private:
152 win_scheduler& sched_;
153 BOOST_COROSIO_MSVC_WARNING_PUSH
154 BOOST_COROSIO_MSVC_WARNING_DISABLE(4251) // detail:: members, dll-interface
155 object_pool<win_random_access_handle_impl> pool_;
156 BOOST_COROSIO_MSVC_WARNING_POP
157 };
158
159 inline void
160 25x win_random_access_handle_impl::retire() noexcept
161 {
162 25x svc_.pool_.recycle(this);
163 25x }
164
165 } // namespace boost::corosio::detail
166
167 #endif // BOOST_COROSIO_HAS_IOCP
168
169 #endif
170