include/boost/corosio/native/detail/iocp/win_random_access_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_RANDOM_ACCESS_FILE_HPP | ||
| 11 | #define BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_RANDOM_ACCESS_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/random_access_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_random_access_file_service; | ||
| 32 | |||
| 33 | /** Random-access file state: the concurrent model. */ | ||
| 34 | class win_random_access_file_internal : public win_concurrent_handle | ||
| 35 | { | ||
| 36 | friend class win_random_access_file_service; | ||
| 37 | |||
| 38 | public: | ||
| 39 | 116x | win_random_access_file_internal( | |
| 40 | win_scheduler& sched, | ||
| 41 | win_state_list<win_handle_base>& list, | ||
| 42 | win_random_access_file_service& svc) noexcept | ||
| 43 | 116x | : win_concurrent_handle(sched, list) | |
| 44 | 116x | , svc_(svc) | |
| 45 | { | ||
| 46 | 116x | } | |
| 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 | |||
| 53 | private: | ||
| 54 | win_random_access_file_service& svc_; | ||
| 55 | }; | ||
| 56 | |||
| 57 | /** Random-access file implementation wrapper for IOCP-based I/O. */ | ||
| 58 | class win_random_access_file final | ||
| 59 | : public random_access_file::implementation | ||
| 60 | , public intrusive_list<win_random_access_file>::node | ||
| 61 | { | ||
| 62 | std::shared_ptr<win_random_access_file_internal> internal_; | ||
| 63 | |||
| 64 | public: | ||
| 65 | explicit win_random_access_file( | ||
| 66 | std::shared_ptr<win_random_access_file_internal> internal) noexcept; | ||
| 67 | |||
| 68 | void close_internal() noexcept; | ||
| 69 | |||
| 70 | std::coroutine_handle<> read_some_at( | ||
| 71 | std::uint64_t offset, | ||
| 72 | capy::continuation& cont, | ||
| 73 | capy::executor_ref d, | ||
| 74 | buffer_param buf, | ||
| 75 | std::stop_token token, | ||
| 76 | std::error_code* ec, | ||
| 77 | std::size_t* bytes) override; | ||
| 78 | |||
| 79 | std::coroutine_handle<> write_some_at( | ||
| 80 | std::uint64_t offset, | ||
| 81 | capy::continuation& cont, | ||
| 82 | capy::executor_ref d, | ||
| 83 | buffer_param buf, | ||
| 84 | std::stop_token token, | ||
| 85 | std::error_code* ec, | ||
| 86 | std::size_t* bytes) override; | ||
| 87 | |||
| 88 | native_handle_type native_handle() const noexcept override; | ||
| 89 | void cancel() noexcept override; | ||
| 90 | std::uint64_t size() const override; | ||
| 91 | std::error_code resize(std::uint64_t new_size) noexcept override; | ||
| 92 | std::error_code sync_data() noexcept override; | ||
| 93 | std::error_code sync_all() noexcept override; | ||
| 94 | native_handle_type release() override; | ||
| 95 | std::error_code assign(native_handle_type handle) noexcept override; | ||
| 96 | |||
| 97 | win_random_access_file_internal* get_internal() const noexcept; | ||
| 98 | }; | ||
| 99 | |||
| 100 | } // namespace boost::corosio::detail | ||
| 101 | |||
| 102 | #endif // BOOST_COROSIO_HAS_IOCP | ||
| 103 | |||
| 104 | #endif // BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_RANDOM_ACCESS_FILE_HPP | ||
| 105 |