src/corosio/src/win_random_access_handle.cpp

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