include/boost/corosio/native/detail/iocp/win_stream_handle_service.hpp
100.0% Lines (41/41)
100.0% List of functions (14/14)
80.0% Branches (8/10)
Functions (14)
Function
Calls
Lines
Branches
Blocks
boost::corosio::detail::win_stream_handle_impl::win_stream_handle_impl(std::shared_ptr<boost::corosio::detail::win_slot_handle>)
:33
35x
100.0%
–
100.0%
boost::corosio::detail::win_stream_handle_impl::close_internal()
:39
31x
100.0%
50.0%
100.0%
boost::corosio::detail::win_stream_handle_impl::get_internal() const
:48
83x
100.0%
–
100.0%
boost::corosio::detail::win_stream_handle_impl::read_some(std::__n4861::coroutine_handle<void>, boost::capy::executor_ref, boost::corosio::buffer_param, std::stop_token, std::error_code*, unsigned long long*)
:53
23x
100.0%
100.0%
81.8%
boost::corosio::detail::win_stream_handle_impl::write_some(std::__n4861::coroutine_handle<void>, boost::capy::executor_ref, boost::corosio::buffer_param, std::stop_token, std::error_code*, unsigned long long*)
:64
6x
100.0%
100.0%
81.8%
boost::corosio::detail::win_stream_handle_impl::native_handle() const
:75
91x
100.0%
–
100.0%
boost::corosio::detail::win_stream_handle_impl::release_handle()
:80
7x
100.0%
–
100.0%
boost::corosio::detail::win_stream_handle_impl::cancel()
:85
1x
100.0%
–
100.0%
boost::corosio::detail::win_stream_handle_service::win_stream_handle_service(boost::capy::execution_context&)
:96
34x
100.0%
100.0%
83.3%
boost::corosio::detail::win_stream_handle_service::construct()
:101
35x
100.0%
100.0%
80.0%
boost::corosio::detail::win_stream_handle_service::destroy(boost::corosio::io_object::implementation*)
:108
31x
100.0%
50.0%
100.0%
boost::corosio::detail::win_stream_handle_service::close(boost::corosio::io_object::handle&)
:114
50x
100.0%
–
100.0%
boost::corosio::detail::win_stream_handle_service::shutdown()
:121
34x
100.0%
–
100.0%
boost::corosio::detail::win_stream_handle_service::assign_stream_handle(boost::corosio::win_stream_handle::implementation&, unsigned long long)
:126
33x
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/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_stream_handle: the slot model at offset 0. */ | |||
| 26 | class win_stream_handle_impl final | |||
| 27 | : public win_stream_handle::implementation | |||
| 28 | , public intrusive_list<win_stream_handle_impl>::node | |||
| 29 | { | |||
| 30 | std::shared_ptr<win_slot_handle> internal_; | |||
| 31 | ||||
| 32 | public: | |||
| 33 | 35x | explicit win_stream_handle_impl( | ||
| 34 | std::shared_ptr<win_slot_handle> internal) noexcept | |||
| 35 | 35x | : internal_(std::move(internal)) | ||
| 36 | { | |||
| 37 | 35x | } | ||
| 38 | ||||
| 39 | 31x | void close_internal() noexcept | ||
| 40 | { | |||
| 41 |
1/2✓ Branch 3 → 4 taken 31 times.
✗ Branch 3 → 7 not taken.
|
31x | if (internal_) | |
| 42 | { | |||
| 43 | 31x | internal_->close_handle(); | ||
| 44 | 31x | internal_.reset(); | ||
| 45 | } | |||
| 46 | 31x | } | ||
| 47 | ||||
| 48 | 83x | win_slot_handle* get_internal() const noexcept | ||
| 49 | { | |||
| 50 | 83x | return internal_.get(); | ||
| 51 | } | |||
| 52 | ||||
| 53 | 23x | std::coroutine_handle<> read_some( | ||
| 54 | std::coroutine_handle<> h, | |||
| 55 | capy::executor_ref ex, | |||
| 56 | buffer_param buf, | |||
| 57 | std::stop_token token, | |||
| 58 | std::error_code* ec, | |||
| 59 | std::size_t* bytes) override | |||
| 60 | { | |||
| 61 |
1/1✓ Branch 5 → 6 taken 23 times.
|
23x | return internal_->read_some(h, ex, buf, std::move(token), ec, bytes); | |
| 62 | } | |||
| 63 | ||||
| 64 | 6x | std::coroutine_handle<> write_some( | ||
| 65 | std::coroutine_handle<> h, | |||
| 66 | capy::executor_ref ex, | |||
| 67 | buffer_param buf, | |||
| 68 | std::stop_token token, | |||
| 69 | std::error_code* ec, | |||
| 70 | std::size_t* bytes) override | |||
| 71 | { | |||
| 72 |
1/1✓ Branch 5 → 6 taken 6 times.
|
6x | return internal_->write_some(h, ex, buf, std::move(token), ec, bytes); | |
| 73 | } | |||
| 74 | ||||
| 75 | 91x | native_handle_type native_handle() const noexcept override | ||
| 76 | { | |||
| 77 | 91x | return reinterpret_cast<native_handle_type>(internal_->native_handle()); | ||
| 78 | } | |||
| 79 | ||||
| 80 | 7x | native_handle_type release_handle() override | ||
| 81 | { | |||
| 82 | 7x | return internal_->release(); | ||
| 83 | } | |||
| 84 | ||||
| 85 | 1x | void cancel() noexcept override | ||
| 86 | { | |||
| 87 | 1x | internal_->cancel(); | ||
| 88 | 1x | } | ||
| 89 | }; | |||
| 90 | ||||
| 91 | /** IOCP service that owns the @ref win_stream_handle implementations. */ | |||
| 92 | class BOOST_COROSIO_DECL win_stream_handle_service final | |||
| 93 | : public stream_handle_service | |||
| 94 | { | |||
| 95 | public: | |||
| 96 | 34x | explicit win_stream_handle_service(capy::execution_context& ctx) | ||
| 97 |
2/2✓ Branch 3 → 4 taken 34 times.
✓ Branch 4 → 5 taken 34 times.
|
34x | : sched_(ctx.use_service<win_scheduler>()) | |
| 98 | { | |||
| 99 | 34x | } | ||
| 100 | ||||
| 101 | 35x | io_object::implementation* construct() override | ||
| 102 | { | |||
| 103 | auto internal = std::make_shared<win_slot_handle>( | |||
| 104 |
1/1✓ Branch 3 → 4 taken 35 times.
|
35x | sched_, reg_.states(), /*track_offset=*/false); | |
| 105 |
1/1✓ Branch 4 → 5 taken 35 times.
|
70x | return reg_.add(new win_stream_handle_impl(std::move(internal))); | |
| 106 | 35x | } | ||
| 107 | ||||
| 108 | 31x | void destroy(io_object::implementation* p) override | ||
| 109 | { | |||
| 110 |
1/2✓ Branch 2 → 3 taken 31 times.
✗ Branch 2 → 4 not taken.
|
31x | if (p) | |
| 111 | 31x | reg_.destroy(static_cast<win_stream_handle_impl&>(*p)); | ||
| 112 | 31x | } | ||
| 113 | ||||
| 114 | 50x | void close(io_object::handle& h) override | ||
| 115 | { | |||
| 116 | 50x | static_cast<win_stream_handle_impl&>(*h.get()) | ||
| 117 | .get_internal() | |||
| 118 | 50x | ->close_handle(); | ||
| 119 | 50x | } | ||
| 120 | ||||
| 121 | 34x | void shutdown() override | ||
| 122 | { | |||
| 123 | 34x | reg_.shutdown(); | ||
| 124 | 34x | } | ||
| 125 | ||||
| 126 | 33x | std::error_code assign_stream_handle( | ||
| 127 | win_stream_handle::implementation& impl, | |||
| 128 | native_handle_type h) override | |||
| 129 | { | |||
| 130 | return static_cast<win_stream_handle_impl&>(impl) | |||
| 131 | .get_internal() | |||
| 132 | 33x | ->assign(h, handle_kind::stream_handle); | ||
| 133 | } | |||
| 134 | ||||
| 135 | private: | |||
| 136 | win_scheduler& sched_; | |||
| 137 | BOOST_COROSIO_MSVC_WARNING_PUSH | |||
| 138 | BOOST_COROSIO_MSVC_WARNING_DISABLE(4251) // detail:: members, dll-interface | |||
| 139 | win_handle_registry<win_stream_handle_impl, win_handle_base> reg_; | |||
| 140 | BOOST_COROSIO_MSVC_WARNING_POP | |||
| 141 | }; | |||
| 142 | ||||
| 143 | } // namespace boost::corosio::detail | |||
| 144 | ||||
| 145 | #endif // BOOST_COROSIO_HAS_IOCP | |||
| 146 | ||||
| 147 | #endif | |||
| 148 |