src/corosio/src/stream_file.cpp
100.0% Lines (53 / 53)
100.0% Branches (24 / 24)
100.0% Functions (13 / 13)
Functions (13)
Function
Calls
Lines
Branches
Blocks
boost::corosio::stream_file::~stream_file()
:24
316x
0.0%
–
100.0%
boost::corosio::stream_file::stream_file(boost::capy::execution_context&)
:29
307x
100.0%
100.0%
100.0%
boost::corosio::stream_file::open(std::filesystem::__cxx11::path const&, boost::corosio::file_base::flags)
:44
326x
100.0%
100.0%
100.0%
boost::corosio::stream_file::close()
:54
576x
100.0%
100.0%
100.0%
boost::corosio::stream_file::cancel()
:62
2x
100.0%
100.0%
100.0%
boost::corosio::stream_file::native_handle() const
:70
8x
100.0%
100.0%
100.0%
boost::corosio::stream_file::size() const
:84
8x
100.0%
100.0%
100.0%
boost::corosio::stream_file::resize(unsigned long long)
:92
6x
100.0%
100.0%
100.0%
boost::corosio::stream_file::sync_data()
:100
5x
100.0%
100.0%
100.0%
boost::corosio::stream_file::sync_all()
:108
4x
100.0%
100.0%
100.0%
boost::corosio::stream_file::release()
:116
6x
100.0%
100.0%
100.0%
boost::corosio::stream_file::assign(unsigned long long)
:126
211x
100.0%
100.0%
100.0%
boost::corosio::stream_file::seek(long long, boost::corosio::file_base::seek_basis)
:134
218x
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/stream_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_file_service.hpp> | |||
| 16 | #else | |||
| 17 | #include <boost/corosio/detail/file_service.hpp> | |||
| 18 | #endif | |||
| 19 | ||||
| 20 | #include "src/detail/use_backend_service.hpp" | |||
| 21 | ||||
| 22 | namespace boost::corosio { | |||
| 23 | ||||
| 24 | 316x | stream_file::~stream_file() | ||
| 25 | { | |||
| 26 | 316x | close(); | ||
| 27 | 316x | } | ||
| 28 | ||||
| 29 | 307x | stream_file::stream_file(capy::execution_context& ctx) | ||
| 30 | 307x | : io_object(handle( | ||
| 31 | ctx, | |||
| 32 | detail::use_backend_service< | |||
| 33 | detail::stream_file_service_of, | |||
| 34 | #if BOOST_COROSIO_HAS_IOCP | |||
| 35 | detail::win_file_service | |||
| 36 | #else | |||
| 37 | detail::file_service | |||
| 38 | #endif | |||
| 39 |
2/2✓ Branch 2 → 3 taken 307 times.
✓ Branch 3 → 4 taken 307 times.
|
614x | >(ctx))) | |
| 40 | { | |||
| 41 | 307x | } | ||
| 42 | ||||
| 43 | std::error_code | |||
| 44 | 326x | stream_file::open( | ||
| 45 | std::filesystem::path const& path, file_base::flags mode) noexcept | |||
| 46 | { | |||
| 47 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 325 times.
|
326x | if (is_open()) | |
| 48 | 1x | close(); | ||
| 49 | 326x | auto& svc = static_cast<detail::file_service&>(h_.service()); | ||
| 50 | 326x | return svc.open_file(get(), path, mode); | ||
| 51 | } | |||
| 52 | ||||
| 53 | void | |||
| 54 | 576x | stream_file::close() noexcept | ||
| 55 | { | |||
| 56 |
2/2✓ Branch 3 → 4 taken 81 times.
✓ Branch 3 → 5 taken 495 times.
|
576x | if (!is_open()) | |
| 57 | 81x | return; | ||
| 58 | 495x | h_.service().close(h_); | ||
| 59 | } | |||
| 60 | ||||
| 61 | void | |||
| 62 | 2x | stream_file::cancel() noexcept | ||
| 63 | { | |||
| 64 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 1 time.
|
2x | if (!is_open()) | |
| 65 | 1x | return; | ||
| 66 | 1x | get().cancel(); | ||
| 67 | } | |||
| 68 | ||||
| 69 | native_handle_type | |||
| 70 | 8x | stream_file::native_handle() const noexcept | ||
| 71 | { | |||
| 72 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 7 times.
|
8x | if (!is_open()) | |
| 73 | { | |||
| 74 | #if BOOST_COROSIO_HAS_IOCP | |||
| 75 | 1x | return static_cast<native_handle_type>(~0ull); | ||
| 76 | #else | |||
| 77 | return -1; | |||
| 78 | #endif | |||
| 79 | } | |||
| 80 | 7x | return get().native_handle(); | ||
| 81 | } | |||
| 82 | ||||
| 83 | capy::results<std::uint64_t> | |||
| 84 | 8x | stream_file::size() const noexcept | ||
| 85 | { | |||
| 86 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 7 taken 7 times.
|
8x | if (!is_open()) | |
| 87 | 1x | return {make_error_code(std::errc::bad_file_descriptor), 0}; | ||
| 88 | 7x | return get().size(); | ||
| 89 | } | |||
| 90 | ||||
| 91 | std::error_code | |||
| 92 | 6x | stream_file::resize(std::uint64_t new_size) noexcept | ||
| 93 | { | |||
| 94 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 5 times.
|
6x | if (!is_open()) | |
| 95 | 1x | return make_error_code(std::errc::bad_file_descriptor); | ||
| 96 | 5x | return get().resize(new_size); | ||
| 97 | } | |||
| 98 | ||||
| 99 | std::error_code | |||
| 100 | 5x | stream_file::sync_data() noexcept | ||
| 101 | { | |||
| 102 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 4 times.
|
5x | if (!is_open()) | |
| 103 | 1x | return make_error_code(std::errc::bad_file_descriptor); | ||
| 104 | 4x | return get().sync_data(); | ||
| 105 | } | |||
| 106 | ||||
| 107 | std::error_code | |||
| 108 | 4x | stream_file::sync_all() noexcept | ||
| 109 | { | |||
| 110 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 3 times.
|
4x | if (!is_open()) | |
| 111 | 1x | return make_error_code(std::errc::bad_file_descriptor); | ||
| 112 | 3x | return get().sync_all(); | ||
| 113 | } | |||
| 114 | ||||
| 115 | capy::results<native_handle_type> | |||
| 116 | 6x | stream_file::release() noexcept | ||
| 117 | { | |||
| 118 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 7 taken 5 times.
|
6x | if (!is_open()) | |
| 119 | return { | |||
| 120 | 2x | make_error_code(std::errc::bad_file_descriptor), | ||
| 121 | 1x | detail::invalid_native_handle}; | ||
| 122 | 5x | return get().release(); | ||
| 123 | } | |||
| 124 | ||||
| 125 | std::error_code | |||
| 126 | 211x | stream_file::assign(native_handle_type handle) noexcept | ||
| 127 | { | |||
| 128 |
2/2✓ Branch 3 → 4 taken 3 times.
✓ Branch 3 → 5 taken 208 times.
|
211x | if (is_open()) | |
| 129 | 3x | return make_error_code(error::already_open); | ||
| 130 | 208x | return get().assign(handle); | ||
| 131 | } | |||
| 132 | ||||
| 133 | capy::results<std::uint64_t> | |||
| 134 | 218x | stream_file::seek(std::int64_t offset, file_base::seek_basis origin) noexcept | ||
| 135 | { | |||
| 136 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 7 taken 217 times.
|
218x | if (!is_open()) | |
| 137 | 1x | return {make_error_code(std::errc::bad_file_descriptor), 0}; | ||
| 138 | 217x | return get().seek(offset, origin); | ||
| 139 | } | |||
| 140 | ||||
| 141 | } // namespace boost::corosio | |||
| 142 |