src/corosio/src/random_access_file.cpp
87.5% Lines (56/64)
91.7% List of functions (11/12)
75.0% Branches (18/24)
Functions (12)
Function
Calls
Lines
Branches
Blocks
boost::corosio::random_access_file::~random_access_file()
:22
50x
100.0%
50.0%
100.0%
boost::corosio::random_access_file::random_access_file(boost::capy::execution_context&)
:27
48x
100.0%
–
100.0%
boost::corosio::random_access_file::open(std::__1::__fs::filesystem::path const&, boost::corosio::file_base::flags)
:37
19x
87.5%
75.0%
80.0%
boost::corosio::random_access_file::close()
:49
28x
100.0%
100.0%
100.0%
boost::corosio::random_access_file::cancel()
:57
1x
80.0%
50.0%
75.0%
boost::corosio::random_access_file::native_handle() const
:65
0
0.0%
0.0%
0.0%
boost::corosio::random_access_file::size() const
:79
3x
100.0%
100.0%
100.0%
boost::corosio::random_access_file::resize(unsigned long long)
:89
3x
100.0%
100.0%
100.0%
boost::corosio::random_access_file::sync_data()
:99
2x
100.0%
100.0%
100.0%
boost::corosio::random_access_file::sync_all()
:109
2x
100.0%
100.0%
100.0%
boost::corosio::random_access_file::release()
:119
2x
100.0%
100.0%
100.0%
boost::corosio::random_access_file::assign(int)
:129
1x
80.0%
50.0%
66.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 | #include <boost/corosio/random_access_file.hpp> | |||
| 11 | #include <boost/corosio/detail/except.hpp> | |||
| 12 | #include <boost/corosio/detail/platform.hpp> | |||
| 13 | ||||
| 14 | #if BOOST_COROSIO_HAS_IOCP | |||
| 15 | #include <boost/corosio/native/detail/iocp/win_random_access_file_service.hpp> | |||
| 16 | #else | |||
| 17 | #include <boost/corosio/detail/random_access_file_service.hpp> | |||
| 18 | #endif | |||
| 19 | ||||
| 20 | namespace boost::corosio { | |||
| 21 | ||||
| 22 | 50x | random_access_file::~random_access_file() | ||
| 23 | 50x | { | ||
| 24 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25x | close(); | |
| 25 | 50x | } | ||
| 26 | ||||
| 27 | 48x | random_access_file::random_access_file(capy::execution_context& ctx) | ||
| 28 | #if BOOST_COROSIO_HAS_IOCP | |||
| 29 | : io_object(create_handle<detail::win_random_access_file_service>(ctx)) | |||
| 30 | #else | |||
| 31 | 24x | : io_object(create_handle<detail::random_access_file_service>(ctx)) | ||
| 32 | #endif | |||
| 33 | 48x | { | ||
| 34 | 48x | } | ||
| 35 | ||||
| 36 | void | |||
| 37 | 19x | random_access_file::open( | ||
| 38 | std::filesystem::path const& path, file_base::flags mode) | |||
| 39 | { | |||
| 40 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19x | if (is_open()) | |
| 41 | ✗ | close(); | ||
| 42 | 19x | auto& svc = static_cast<detail::random_access_file_service&>(h_.service()); | ||
| 43 | 19x | std::error_code ec = svc.open_file(get(), path, mode); | ||
| 44 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 time.
|
19x | if (ec) | |
| 45 | 1x | detail::throw_system_error(ec, "random_access_file::open"); | ||
| 46 | 18x | } | ||
| 47 | ||||
| 48 | void | |||
| 49 | 28x | random_access_file::close() | ||
| 50 | { | |||
| 51 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 18 times.
|
28x | if (!is_open()) | |
| 52 | 10x | return; | ||
| 53 | 18x | h_.service().close(h_); | ||
| 54 | 28x | } | ||
| 55 | ||||
| 56 | void | |||
| 57 | 1x | random_access_file::cancel() | ||
| 58 | { | |||
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1x | if (!is_open()) | |
| 60 | ✗ | return; | ||
| 61 | 1x | get().cancel(); | ||
| 62 | 1x | } | ||
| 63 | ||||
| 64 | native_handle_type | |||
| 65 | ✗ | random_access_file::native_handle() const noexcept | ||
| 66 | { | |||
| 67 | ✗ | if (!is_open()) | ||
| 68 | { | |||
| 69 | #if BOOST_COROSIO_HAS_IOCP | |||
| 70 | return static_cast<native_handle_type>(~0ull); | |||
| 71 | #else | |||
| 72 | ✗ | return -1; | ||
| 73 | #endif | |||
| 74 | } | |||
| 75 | ✗ | return get().native_handle(); | ||
| 76 | ✗ | } | ||
| 77 | ||||
| 78 | std::uint64_t | |||
| 79 | 3x | random_access_file::size() const | ||
| 80 | { | |||
| 81 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
3x | if (!is_open()) | |
| 82 | 1x | detail::throw_system_error( | ||
| 83 | 1x | make_error_code(std::errc::bad_file_descriptor), | ||
| 84 | "random_access_file::size"); | |||
| 85 | 2x | return get().size(); | ||
| 86 | } | |||
| 87 | ||||
| 88 | void | |||
| 89 | 3x | random_access_file::resize(std::uint64_t new_size) | ||
| 90 | { | |||
| 91 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
3x | if (!is_open()) | |
| 92 | 1x | detail::throw_system_error( | ||
| 93 | 1x | make_error_code(std::errc::bad_file_descriptor), | ||
| 94 | "random_access_file::resize"); | |||
| 95 | 2x | get().resize(new_size); | ||
| 96 | 2x | } | ||
| 97 | ||||
| 98 | void | |||
| 99 | 2x | random_access_file::sync_data() | ||
| 100 | { | |||
| 101 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2x | if (!is_open()) | |
| 102 | 1x | detail::throw_system_error( | ||
| 103 | 1x | make_error_code(std::errc::bad_file_descriptor), | ||
| 104 | "random_access_file::sync_data"); | |||
| 105 | 1x | get().sync_data(); | ||
| 106 | 1x | } | ||
| 107 | ||||
| 108 | void | |||
| 109 | 2x | random_access_file::sync_all() | ||
| 110 | { | |||
| 111 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2x | if (!is_open()) | |
| 112 | 1x | detail::throw_system_error( | ||
| 113 | 1x | make_error_code(std::errc::bad_file_descriptor), | ||
| 114 | "random_access_file::sync_all"); | |||
| 115 | 1x | get().sync_all(); | ||
| 116 | 1x | } | ||
| 117 | ||||
| 118 | native_handle_type | |||
| 119 | 2x | random_access_file::release() | ||
| 120 | { | |||
| 121 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
2x | if (!is_open()) | |
| 122 | 1x | detail::throw_system_error( | ||
| 123 | 1x | make_error_code(std::errc::bad_file_descriptor), | ||
| 124 | "random_access_file::release"); | |||
| 125 | 1x | return get().release(); | ||
| 126 | } | |||
| 127 | ||||
| 128 | void | |||
| 129 | 1x | random_access_file::assign(native_handle_type handle) | ||
| 130 | { | |||
| 131 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1x | if (is_open()) | |
| 132 | ✗ | close(); | ||
| 133 | 1x | get().assign(handle); | ||
| 134 | 1x | } | ||
| 135 | ||||
| 136 | } // namespace boost::corosio | |||
| 137 |