src/corosio/src/win_random_access_handle.cpp

86.2% Lines (25/29) 100.0% List of functions (7/7) 75.0% Branches (9/12)
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/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 23x win_random_access_handle::~win_random_access_handle()
25 {
26 23x close();
27 23x }
28
29 23x win_random_access_handle::win_random_access_handle(capy::execution_context& ctx)
30 23x : io_object(handle(
31 ctx,
32 detail::use_backend_service<
33 detail::random_access_handle_service_of,
34
2/2
✓ Branch 2 → 3 taken 23 times.
✓ Branch 3 → 4 taken 23 times.
23x detail::random_access_handle_service>(ctx)))
35 {
36 23x }
37
38 std::error_code
39 26x win_random_access_handle::assign(native_handle_type h) noexcept
40 {
41
2/2
✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 24 times.
26x if (is_open())
42 2x return make_error_code(error::already_open);
43 24x auto& svc = static_cast<detail::random_access_handle_service&>(h_.service());
44 24x return svc.assign_random_access_handle(get(), h);
45 }
46
47 native_handle_type
48 4x win_random_access_handle::release()
49 {
50
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 4 times.
4x if (!is_open())
51 ✗ detail::throw_system_error(
52 ✗ make_error_code(std::errc::bad_file_descriptor),
53 "win_random_access_handle::release");
54 4x return get().release_handle();
55 }
56
57 void
58 23x win_random_access_handle::close() noexcept
59 {
60
2/2
✓ Branch 3 → 4 taken 7 times.
✓ Branch 3 → 5 taken 16 times.
23x if (!is_open())
61 7x return;
62 16x h_.service().close(h_);
63 }
64
65 native_handle_type
66 7x win_random_access_handle::native_handle() const noexcept
67 {
68
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 7 times.
7x if (!h_)
69 ✗ return ~native_handle_type{};
70 7x return get().native_handle();
71 }
72
73 void
74 1x win_random_access_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