include/boost/corosio/native/detail/iocp/win_stream_file.hpp
100.0% Lines (4/4)
100.0% List of functions (1/1)
-% Branches (0/0)
Functions (1)
| 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 | #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/ex/executor_ref.hpp> | ||
| 21 | #include <boost/corosio/detail/intrusive.hpp> | ||
| 22 | #include <boost/corosio/native/detail/iocp/win_overlapped_handle.hpp> | ||
| 23 | #include <boost/corosio/native/detail/iocp/win_windows.hpp> | ||
| 24 | |||
| 25 | #include <coroutine> | ||
| 26 | #include <cstdint> | ||
| 27 | #include <memory> | ||
| 28 | |||
| 29 | namespace boost::corosio::detail { | ||
| 30 | |||
| 31 | class win_file_service; | ||
| 32 | |||
| 33 | /** Stream file state: the slot model with a tracked position. */ | ||
| 34 | class win_stream_file_internal : public win_slot_handle | ||
| 35 | { | ||
| 36 | friend class win_file_service; | ||
| 37 | |||
| 38 | public: | ||
| 39 | 315x | win_stream_file_internal( | |
| 40 | win_scheduler& sched, | ||
| 41 | win_state_list<win_handle_base>& list, | ||
| 42 | win_file_service& svc) noexcept | ||
| 43 | 315x | : win_slot_handle(sched, list, /*track_offset=*/true) | |
| 44 | 315x | , svc_(svc) | |
| 45 | { | ||
| 46 | 315x | } | |
| 47 | |||
| 48 | std::uint64_t size() const; | ||
| 49 | std::error_code resize(std::uint64_t new_size) noexcept; | ||
| 50 | std::error_code sync_data() noexcept; | ||
| 51 | std::error_code sync_all() noexcept; | ||
| 52 | capy::io_result<std::uint64_t> | ||
| 53 | seek(std::int64_t offset, file_base::seek_basis origin) noexcept; | ||
| 54 | |||
| 55 | private: | ||
| 56 | win_file_service& svc_; | ||
| 57 | }; | ||
| 58 | |||
| 59 | /** Stream file implementation wrapper for IOCP-based I/O. | ||
| 60 | |||
| 61 | Public-facing implementation that holds a shared_ptr to | ||
| 62 | the internal state. Delegates all virtual calls. | ||
| 63 | */ | ||
| 64 | class win_stream_file final | ||
| 65 | : public stream_file::implementation | ||
| 66 | , public intrusive_list<win_stream_file>::node | ||
| 67 | { | ||
| 68 | std::shared_ptr<win_stream_file_internal> internal_; | ||
| 69 | |||
| 70 | public: | ||
| 71 | explicit win_stream_file( | ||
| 72 | std::shared_ptr<win_stream_file_internal> internal) noexcept; | ||
| 73 | |||
| 74 | void close_internal() noexcept; | ||
| 75 | |||
| 76 | std::coroutine_handle<> read_some( | ||
| 77 | std::coroutine_handle<> h, | ||
| 78 | capy::executor_ref d, | ||
| 79 | buffer_param buf, | ||
| 80 | std::stop_token token, | ||
| 81 | std::error_code* ec, | ||
| 82 | std::size_t* bytes) override; | ||
| 83 | |||
| 84 | std::coroutine_handle<> write_some( | ||
| 85 | std::coroutine_handle<> h, | ||
| 86 | capy::executor_ref d, | ||
| 87 | buffer_param buf, | ||
| 88 | std::stop_token token, | ||
| 89 | std::error_code* ec, | ||
| 90 | std::size_t* bytes) override; | ||
| 91 | |||
| 92 | native_handle_type native_handle() const noexcept override; | ||
| 93 | void cancel() noexcept override; | ||
| 94 | std::uint64_t size() const override; | ||
| 95 | std::error_code resize(std::uint64_t new_size) noexcept override; | ||
| 96 | std::error_code sync_data() noexcept override; | ||
| 97 | std::error_code sync_all() noexcept override; | ||
| 98 | native_handle_type release() override; | ||
| 99 | std::error_code assign(native_handle_type handle) noexcept override; | ||
| 100 | capy::io_result<std::uint64_t> | ||
| 101 | seek(std::int64_t offset, file_base::seek_basis origin) noexcept override; | ||
| 102 | |||
| 103 | win_stream_file_internal* get_internal() const noexcept; | ||
| 104 | }; | ||
| 105 | |||
| 106 | } // namespace boost::corosio::detail | ||
| 107 | |||
| 108 | #endif // BOOST_COROSIO_HAS_IOCP | ||
| 109 | |||
| 110 | #endif // BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_STREAM_FILE_HPP | ||
| 111 |