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