src/corosio/src/win_stream_handle.cpp

93.1% Lines (27/29) 100.0% List of functions (7/7) 83.3% Branches (10/12)
win_stream_handle.cpp
f(x) Functions (7)
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 #include <boost/corosio/win_stream_handle.hpp>
11
12 #include <boost/corosio/detail/platform.hpp>
13
14 #if BOOST_COROSIO_HAS_IOCP
15
16 #include <boost/corosio/detail/except.hpp>
17 #include <boost/corosio/detail/win_handle_service.hpp>
18 #include <boost/corosio/error.hpp>
19
20 #include "src/detail/use_backend_service.hpp"
21
22 namespace boost::corosio {
23
24 31x win_stream_handle::~win_stream_handle()
25 {
26 31x close();
27 31x }
28
29 34x win_stream_handle::win_stream_handle(capy::execution_context& ctx)
30 34x : io_object(handle(
31 ctx,
32 detail::use_backend_service<
33 detail::stream_handle_service_of,
34
2/2
✓ Branch 2 → 3 taken 34 times.
✓ Branch 3 → 4 taken 34 times.
68x detail::stream_handle_service>(ctx)))
35 {
36 34x }
37
38 std::error_code
39 35x win_stream_handle::assign(native_handle_type h) noexcept
40 {
41
2/2
✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 33 times.
35x if (is_open())
42 2x return make_error_code(error::already_open);
43 33x auto& svc = static_cast<detail::stream_handle_service&>(h_.service());
44 33x return svc.assign_stream_handle(get(), h);
45 }
46
47 native_handle_type
48 8x win_stream_handle::release()
49 {
50
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 6 taken 7 times.
8x if (!is_open())
51 1x detail::throw_system_error(
52 1x make_error_code(std::errc::bad_file_descriptor),
53 "win_stream_handle::release");
54 7x return get().release_handle();
55 }
56
57 void
58 31x win_stream_handle::close() noexcept
59 {
60
2/2
✓ Branch 3 → 4 taken 12 times.
✓ Branch 3 → 5 taken 19 times.
31x if (!is_open())
61 12x return;
62 19x h_.service().close(h_);
63 }
64
65 native_handle_type
66 6x win_stream_handle::native_handle() const noexcept
67 {
68
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 6 times.
6x if (!h_)
69 ✗ return ~native_handle_type{};
70 6x return get().native_handle();
71 }
72
73 void
74 1x win_stream_handle::cancel() noexcept
75 {
76
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 1 time.
1x if (!is_open())
77 ✗ return;
78 1x get().cancel();
79 }
80
81 } // namespace boost::corosio
82
83 #endif // BOOST_COROSIO_HAS_IOCP
84