Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:51

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // Copyright (c) Lewis Baker
0003 // Licenced under MIT license. See LICENSE.txt for details.
0004 ///////////////////////////////////////////////////////////////////////////////
0005 #ifndef CPPCORO_FILE_READ_OPERATION_HPP_INCLUDED
0006 #define CPPCORO_FILE_READ_OPERATION_HPP_INCLUDED
0007 
0008 #include <cppcoro/config.hpp>
0009 #include <cppcoro/cancellation_registration.hpp>
0010 #include <cppcoro/cancellation_token.hpp>
0011 
0012 #include <atomic>
0013 #include <optional>
0014 
0015 #if CPPCORO_OS_WINNT
0016 # include <cppcoro/detail/win32.hpp>
0017 # include <cppcoro/detail/win32_overlapped_operation.hpp>
0018 
0019 namespace cppcoro
0020 {
0021     class file_read_operation_impl
0022     {
0023     public:
0024 
0025         file_read_operation_impl(
0026             detail::win32::handle_t fileHandle,
0027             void* buffer,
0028             std::size_t byteCount) noexcept
0029             : m_fileHandle(fileHandle)
0030             , m_buffer(buffer)
0031             , m_byteCount(byteCount)
0032         {}
0033 
0034         bool try_start(cppcoro::detail::win32_overlapped_operation_base& operation) noexcept;
0035         void cancel(cppcoro::detail::win32_overlapped_operation_base& operation) noexcept;
0036 
0037     private:
0038 
0039         detail::win32::handle_t m_fileHandle;
0040         void* m_buffer;
0041         std::size_t m_byteCount;
0042 
0043     };
0044 
0045     class file_read_operation
0046         : public cppcoro::detail::win32_overlapped_operation<file_read_operation>
0047     {
0048     public:
0049 
0050         file_read_operation(
0051             detail::win32::handle_t fileHandle,
0052             std::uint64_t fileOffset,
0053             void* buffer,
0054             std::size_t byteCount) noexcept
0055             : cppcoro::detail::win32_overlapped_operation<file_read_operation>(fileOffset)
0056             , m_impl(fileHandle, buffer, byteCount)
0057         {}
0058 
0059     private:
0060 
0061         friend class cppcoro::detail::win32_overlapped_operation<file_read_operation>;
0062 
0063         bool try_start() noexcept { return m_impl.try_start(*this); }
0064 
0065         file_read_operation_impl m_impl;
0066 
0067     };
0068 
0069     class file_read_operation_cancellable
0070         : public cppcoro::detail::win32_overlapped_operation_cancellable<file_read_operation_cancellable>
0071     {
0072     public:
0073 
0074         file_read_operation_cancellable(
0075             detail::win32::handle_t fileHandle,
0076             std::uint64_t fileOffset,
0077             void* buffer,
0078             std::size_t byteCount,
0079             cancellation_token&& cancellationToken) noexcept
0080             : cppcoro::detail::win32_overlapped_operation_cancellable<file_read_operation_cancellable>(
0081                 fileOffset, std::move(cancellationToken))
0082             , m_impl(fileHandle, buffer, byteCount)
0083         {}
0084 
0085     private:
0086 
0087         friend class cppcoro::detail::win32_overlapped_operation_cancellable<file_read_operation_cancellable>;
0088 
0089         bool try_start() noexcept { return m_impl.try_start(*this); }
0090         void cancel() noexcept { m_impl.cancel(*this); }
0091 
0092         file_read_operation_impl m_impl;
0093 
0094     };
0095 
0096 #endif
0097 }
0098 
0099 #endif