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