a34527617d
Added io_work_scope RAII class to help with scoped lifetime of io_service event loop. Having io_context always increment the ref-count of active I/O operations whenever passed by-value to a function seems like unnecessary atomic operations when compared to selected usages of io_work_scope which generally only need creation for top-level operations.
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
///////////////////////////////////////////////////////////////////////////////
|
|
// Copyright (c) Lewis Baker
|
|
// Licenced under MIT license. See LICENSE.txt for details.
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
#ifndef CPPCORO_READ_ONLY_FILE_HPP_INCLUDED
|
|
#define CPPCORO_READ_ONLY_FILE_HPP_INCLUDED
|
|
|
|
#include <cppcoro/readable_file.hpp>
|
|
#include <cppcoro/file_share_mode.hpp>
|
|
#include <cppcoro/file_buffering_mode.hpp>
|
|
|
|
#include <experimental/filesystem>
|
|
|
|
namespace cppcoro
|
|
{
|
|
class read_only_file : public readable_file
|
|
{
|
|
public:
|
|
|
|
/// Open a file for read-only access.
|
|
///
|
|
/// \param ioContext
|
|
/// The I/O context to use when dispatching I/O completion events.
|
|
/// When asynchronous read operations on this file complete the
|
|
/// completion events will be dispatched to an I/O thread associated
|
|
/// with the I/O context.
|
|
///
|
|
/// \param path
|
|
/// Path of the file to open.
|
|
///
|
|
/// \param shareMode
|
|
/// Specifies the access to be allowed on the file concurrently with this file access.
|
|
///
|
|
/// \param bufferingMode
|
|
/// Specifies the modes/hints to provide to the OS that affects the behaviour
|
|
/// of its file buffering.
|
|
///
|
|
/// \return
|
|
/// An object that can be used to read from the file.
|
|
///
|
|
/// \throw std::system_error
|
|
/// If the file could not be opened for read.
|
|
[[nodiscard]]
|
|
static read_only_file open(
|
|
io_service& ioService,
|
|
const std::experimental::filesystem::path& path,
|
|
file_share_mode shareMode = file_share_mode::read,
|
|
file_buffering_mode bufferingMode = file_buffering_mode::default_);
|
|
|
|
protected:
|
|
|
|
#if CPPCORO_OS_WINNT
|
|
read_only_file(detail::win32::safe_handle&& fileHandle) noexcept;
|
|
#endif
|
|
|
|
};
|
|
}
|
|
|
|
#endif
|