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

90.9% Lines (40 / 44) 62.5% Branches (5 / 8) 93.8% Functions (15 / 16)
win_stream_handle_service.hpp
f(x) Functions (16)
Function Calls Lines Branches Blocks
boost::corosio::detail::win_stream_handle_impl::win_stream_handle_impl(boost::corosio::detail::win_stream_handle_service&, boost::corosio::detail::win_scheduler&) :36 35x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_impl::reuse() :51 0 0.0% 0.0% 0.0% boost::corosio::detail::win_stream_handle_impl::get_internal() :56 126x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_impl::read_some(boost::capy::continuation&, boost::capy::executor_ref, boost::corosio::detail::buffer_param, std::stop_token, std::error_code*, unsigned long long*) :61 23x 100.0% 100.0% 80.0% boost::corosio::detail::win_stream_handle_impl::write_some(boost::capy::continuation&, boost::capy::executor_ref, boost::corosio::detail::buffer_param, std::stop_token, std::error_code*, unsigned long long*) :72 6x 100.0% 100.0% 80.0% boost::corosio::detail::win_stream_handle_impl::native_handle() const :83 95x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_impl::release_handle() :88 7x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_impl::cancel() :93 1x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_service::win_stream_handle_service(boost::capy::execution_context&) :106 34x 100.0% 100.0% 83.3% boost::corosio::detail::win_stream_handle_service::construct() :111 35x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_service::destroy(boost::corosio::io_object::implementation*) :116 35x 83.3% 50.0% 83.3% boost::corosio::detail::win_stream_handle_service::close(boost::corosio::io_object::handle&) :125 54x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_service::shutdown() :132 34x 100.0% 100.0% 100.0% boost::corosio::detail::win_stream_handle_service::shutdown()::{lambda(boost::corosio::detail::win_stream_handle_impl*)#1}::operator()(boost::corosio::detail::win_stream_handle_impl*) const :135 4x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_service::assign_stream_handle(boost::corosio::win_stream_handle::implementation&, unsigned long long) :138 33x 100.0% – 100.0% boost::corosio::detail::win_stream_handle_impl::retire() :156 35x 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_STREAM_HANDLE_SERVICE_HPP
11 #define BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_STREAM_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_stream_handle_service;
26
27 /** IOCP implementation of @ref win_stream_handle: the slot model at offset 0. */
28 class win_stream_handle_impl final
29 : public win_stream_handle::implementation
30 , public intrusive_list<win_stream_handle_impl>::node
31 {
32 win_stream_handle_service& svc_;
33 win_slot_handle internal_;
34
35 public:
36 35x win_stream_handle_impl(
37 win_stream_handle_service& svc, win_scheduler& sched) noexcept
38 70x : svc_(svc)
39 35x , internal_(sched, *this, /*track_offset=*/false)
40 {
41 35x }
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 126x win_slot_handle* get_internal() noexcept
57 {
58 126x return &internal_;
59 }
60
61 23x std::coroutine_handle<> read_some(
62 capy::continuation& cont,
63 capy::executor_ref ex,
64 buffer_param buf,
65 std::stop_token token,
66 std::error_code* ec,
67 std::size_t* bytes) override
68 {
69
1/1
✓ Branch 4 → 5 taken 23 times.
23x return internal_.read_some(cont, ex, buf, std::move(token), ec, bytes);
70 }
71
72 6x std::coroutine_handle<> write_some(
73 capy::continuation& cont,
74 capy::executor_ref ex,
75 buffer_param buf,
76 std::stop_token token,
77 std::error_code* ec,
78 std::size_t* bytes) override
79 {
80
1/1
✓ Branch 4 → 5 taken 6 times.
6x return internal_.write_some(cont, ex, buf, std::move(token), ec, bytes);
81 }
82
83 95x native_handle_type native_handle() const noexcept override
84 {
85 95x return reinterpret_cast<native_handle_type>(internal_.native_handle());
86 }
87
88 7x capy::results<native_handle_type> release_handle() noexcept override
89 {
90 7x return internal_.release();
91 }
92
93 1x void cancel() noexcept override
94 {
95 1x internal_.cancel();
96 1x }
97 };
98
99 /** IOCP service that owns the @ref win_stream_handle implementations. */
100 class BOOST_COROSIO_DECL win_stream_handle_service final
101 : public stream_handle_service
102 {
103 friend class win_stream_handle_impl;
104
105 public:
106 34x explicit win_stream_handle_service(capy::execution_context& ctx)
107
1/1
✓ Branch 3 → 4 taken 34 times.
34x : sched_(ctx.use_service<win_scheduler>())
108 {
109 34x }
110
111 35x io_object::implementation* construct() override
112 {
113 35x return pool_.acquire(*this, sched_);
114 }
115
116 35x void destroy(io_object::implementation* p) override
117 {
118
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 35 times.
35x if (!p)
119 ✗ return;
120 35x auto* impl = static_cast<win_stream_handle_impl*>(p);
121 35x impl->get_internal()->close_handle();
122 35x release(impl);
123 }
124
125 54x void close(io_object::handle& h) override
126 {
127 54x static_cast<win_stream_handle_impl&>(*h.get())
128 .get_internal()
129 54x ->close_handle();
130 54x }
131
132 34x void shutdown() override
133 {
134
1/1
✓ Branch 2 → 3 taken 34 times.
34x pool_.shutdown(
135 4x [](win_stream_handle_impl* impl) { impl->get_internal()->close_handle(); });
136 34x }
137
138 33x std::error_code assign_stream_handle(
139 win_stream_handle::implementation& impl,
140 native_handle_type h) override
141 {
142 return static_cast<win_stream_handle_impl&>(impl)
143 .get_internal()
144 33x ->assign(h, handle_kind::stream_handle);
145 }
146
147 private:
148 win_scheduler& sched_;
149 BOOST_COROSIO_MSVC_WARNING_PUSH
150 BOOST_COROSIO_MSVC_WARNING_DISABLE(4251) // detail:: members, dll-interface
151 object_pool<win_stream_handle_impl> pool_;
152 BOOST_COROSIO_MSVC_WARNING_POP
153 };
154
155 inline void
156 35x win_stream_handle_impl::retire() noexcept
157 {
158 35x svc_.pool_.recycle(this);
159 35x }
160
161 } // namespace boost::corosio::detail
162
163 #endif // BOOST_COROSIO_HAS_IOCP
164
165 #endif
166