include/boost/corosio/native/detail/iocp/win_stream_file.hpp
100.0% Lines (4 / 4)
-% Branches (0 / 0)
100.0% Functions (1 / 1)
Functions (1)
| 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 | #ifndef BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_STREAM_FILE_HPP | |||
| 11 | #define BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_STREAM_FILE_HPP | |||
| 12 | ||||
| 13 | #include <boost/corosio/detail/platform.hpp> | |||
| 14 | ||||
| 15 | #if BOOST_COROSIO_HAS_IOCP | |||
| 16 | ||||
| 17 | #include <boost/corosio/detail/config.hpp> | |||
| 18 | #include <boost/corosio/stream_file.hpp> | |||
| 19 | #include <boost/corosio/file_base.hpp> | |||
| 20 | #include <boost/capy/continuation.hpp> | |||
| 21 | #include <boost/capy/ex/executor_ref.hpp> | |||
| 22 | #include <boost/corosio/detail/intrusive.hpp> | |||
| 23 | #include <boost/corosio/native/detail/iocp/win_overlapped_handle.hpp> | |||
| 24 | #include <boost/corosio/native/detail/iocp/win_windows.hpp> | |||
| 25 | ||||
| 26 | #include <coroutine> | |||
| 27 | #include <cstdint> | |||
| 28 | #include <memory> | |||
| 29 | ||||
| 30 | namespace boost::corosio::detail { | |||
| 31 | ||||
| 32 | class win_file_service; | |||
| 33 | ||||
| 34 | /** Stream file state: the slot model with a tracked position. */ | |||
| 35 | class win_stream_file_internal : public win_slot_handle | |||
| 36 | { | |||
| 37 | friend class win_file_service; | |||
| 38 | ||||
| 39 | public: | |||
| 40 | 314x | win_stream_file_internal( | ||
| 41 | win_scheduler& sched, | |||
| 42 | io_object::implementation& io, | |||
| 43 | win_file_service& svc) noexcept | |||
| 44 | 314x | : win_slot_handle(sched, io, /*track_offset=*/true) | ||
| 45 | 314x | , svc_(svc) | ||
| 46 | { | |||
| 47 | 314x | } | ||
| 48 | ||||
| 49 | capy::results<std::uint64_t> size() const noexcept; | |||
| 50 | std::error_code resize(std::uint64_t new_size) noexcept; | |||
| 51 | std::error_code sync_data() noexcept; | |||
| 52 | std::error_code sync_all() noexcept; | |||
| 53 | capy::results<std::uint64_t> | |||
| 54 | seek(std::int64_t offset, file_base::seek_basis origin) noexcept; | |||
| 55 | ||||
| 56 | private: | |||
| 57 | win_file_service& svc_; | |||
| 58 | }; | |||
| 59 | ||||
| 60 | /** Stream file implementation for IOCP-based I/O. | |||
| 61 | ||||
| 62 | Embeds its handle state and delegates every virtual call to it. | |||
| 63 | `win_file_service` recycles instances through its pool instead of | |||
| 64 | freeing them on every close. | |||
| 65 | */ | |||
| 66 | class win_stream_file final | |||
| 67 | : public stream_file::implementation | |||
| 68 | , public intrusive_list<win_stream_file>::node | |||
| 69 | { | |||
| 70 | win_file_service& svc_; | |||
| 71 | win_stream_file_internal internal_; | |||
| 72 | ||||
| 73 | public: | |||
| 74 | explicit win_stream_file(win_file_service& svc) noexcept; | |||
| 75 | ||||
| 76 | /// Recycle into the owning service's pool. Defined out-of-line | |||
| 77 | /// after `win_file_service` is complete (needs `svc_.pool_`). | |||
| 78 | void retire() noexcept override; | |||
| 79 | ||||
| 80 | /** Assert the closed state a recycled file starts from. | |||
| 81 | ||||
| 82 | @pre refs_ == 0, handle closed, no op in flight. | |||
| 83 | */ | |||
| 84 | void reuse() noexcept; | |||
| 85 | ||||
| 86 | std::coroutine_handle<> read_some( | |||
| 87 | capy::continuation& cont, | |||
| 88 | capy::executor_ref d, | |||
| 89 | buffer_param buf, | |||
| 90 | std::stop_token token, | |||
| 91 | std::error_code* ec, | |||
| 92 | std::size_t* bytes) override; | |||
| 93 | ||||
| 94 | std::coroutine_handle<> write_some( | |||
| 95 | capy::continuation& cont, | |||
| 96 | capy::executor_ref d, | |||
| 97 | buffer_param buf, | |||
| 98 | std::stop_token token, | |||
| 99 | std::error_code* ec, | |||
| 100 | std::size_t* bytes) override; | |||
| 101 | ||||
| 102 | native_handle_type native_handle() const noexcept override; | |||
| 103 | void cancel() noexcept override; | |||
| 104 | capy::results<std::uint64_t> size() const noexcept override; | |||
| 105 | std::error_code resize(std::uint64_t new_size) noexcept override; | |||
| 106 | std::error_code sync_data() noexcept override; | |||
| 107 | std::error_code sync_all() noexcept override; | |||
| 108 | capy::results<native_handle_type> release() noexcept override; | |||
| 109 | std::error_code assign(native_handle_type handle) noexcept override; | |||
| 110 | capy::results<std::uint64_t> | |||
| 111 | seek(std::int64_t offset, file_base::seek_basis origin) noexcept override; | |||
| 112 | ||||
| 113 | win_stream_file_internal* get_internal() noexcept; | |||
| 114 | }; | |||
| 115 | ||||
| 116 | } // namespace boost::corosio::detail | |||
| 117 | ||||
| 118 | #endif // BOOST_COROSIO_HAS_IOCP | |||
| 119 | ||||
| 120 | #endif // BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_STREAM_FILE_HPP | |||
| 121 |