forked from lewissbaker/cppcoro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadable_file.hpp
More file actions
65 lines (58 loc) · 1.95 KB
/
readable_file.hpp
File metadata and controls
65 lines (58 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCORO_READABLE_FILE_HPP_INCLUDED
#define CPPCORO_READABLE_FILE_HPP_INCLUDED
#include <cppcoro/file.hpp>
#include <cppcoro/file_read_operation.hpp>
#include <cppcoro/cancellation_token.hpp>
namespace cppcoro
{
class readable_file : virtual public file
{
public:
/// Read some data from the file.
///
/// Reads \a byteCount bytes from the file starting at \a offset
/// into the specified \a buffer.
///
/// \param offset
/// The offset within the file to start reading from.
/// If the file has been opened using file_buffering_mode::unbuffered
/// then the offset must be a multiple of the file-system's sector size.
///
/// \param buffer
/// The buffer to read the file contents into.
/// If the file has been opened using file_buffering_mode::unbuffered
/// then the address of the start of the buffer must be a multiple of
/// the file-system's sector size.
///
/// \param byteCount
/// The number of bytes to read from the file.
/// If the file has been opeend using file_buffering_mode::unbuffered
/// then the byteCount must be a multiple of the file-system's sector size.
///
/// \param ct
/// An optional cancellation_token that can be used to cancel the
/// read operation before it completes.
///
/// \return
/// An object that represents the read-operation.
/// This object must be co_await'ed to start the read operation.
[[nodiscard]]
file_read_operation read(
std::uint64_t offset,
void* buffer,
std::size_t byteCount) const noexcept;
[[nodiscard]]
file_read_operation_cancellable read(
std::uint64_t offset,
void* buffer,
std::size_t byteCount,
cancellation_token ct) const noexcept;
protected:
using file::file;
};
}
#endif