Starts a file read operation, reading bytes from a file (or pipe). More...
#include <Async.h>
Classes | |
struct | CompletionData |
Completion data for AsyncFileRead. More... | |
struct | Result |
Callback result for AsyncFileRead. More... | |
Public Types | |
using | Task = AsyncTaskOf< AsyncFileRead > |
Public Types inherited from SC::AsyncRequest | |
enum class | Type : uint8_t { LoopTimeout , LoopWakeUp , LoopWork , ProcessExit , SocketAccept , SocketConnect , SocketSend , SocketReceive , SocketClose , FileRead , FileWrite , FileClose , FilePoll } |
Type of async request. More... | |
Public Member Functions | |
SC::Result | start (AsyncEventLoop &eventLoop) |
Starts a file receive operation, that completes when data has been read from file / pipe. More... | |
uint64_t | getOffset () const |
The file/pipe descriptor handle to read data from. More... | |
void | setOffset (uint64_t fileOffset) |
Sets the offset in bytes at which start reading. More... | |
Public Member Functions inherited from SC::AsyncRequest | |
void | setDebugName (const char *newDebugName) |
AsyncEventLoop * | getEventLoop () const |
Get the event loop associated with this AsyncRequest. More... | |
void | cacheInternalEventLoop (AsyncEventLoop &loop) |
Caches the event loop associated with this AsyncRequest. More... | |
Result | setThreadPoolAndTask (ThreadPool &pool, AsyncTask &task) |
Sets the thread pool and task to use for this request. More... | |
void | resetThreadPoolAndTask () |
Resets anything previously set with setThreadPoolAndTask. More... | |
AsyncRequest (Type type) | |
Constructs a free async request of given type. More... | |
Result | stop () |
Stops the async operation. More... | |
bool | isFree () const |
Public Attributes | |
Function< void(Result &)> | callback |
Span< char > | buffer |
Callback called when some data has been read from the file into the buffer. More... | |
FileDescriptor::Handle | fileDescriptor |
The writeable span of memory where to data will be written. More... | |
Public Attributes inherited from SC::AsyncRequest | |
AsyncRequest * | next = nullptr |
AsyncRequest * | prev = nullptr |
Friends | |
struct | AsyncEventLoop |
Additional Inherited Members | |
Protected Member Functions inherited from SC::AsyncRequest | |
Result | validateAsync () |
void | queueSubmission (AsyncEventLoop &eventLoop) |
Protected Attributes inherited from SC::AsyncRequest | |
AsyncEventLoop * | eventLoop = nullptr |
AsyncTask * | asyncTask = nullptr |
Starts a file read operation, reading bytes from a file (or pipe).
Callback will be called when the data read from the file (or pipe) is available.
Call AsyncRequest::setThreadPoolAndTask to set a thread pool if this is a buffered file and not a pipe. This is important on APIs with blocking behaviour on buffered file I/O (all apis with the exception of io_uring
).
File library can be used to open the file and obtain a file (or pipe) descriptor handle.
O_DIRECT
or Windows FILE_FLAG_WRITE_THROUGH
& FILE_FLAG_NO_BUFFERING
should instead avoid using the Task
parameter for best performance.When not using the Task
remember to:
false
)Additional notes:
|
inline |
The file/pipe descriptor handle to read data from.
Use SC::FileDescriptor or SC::PipeDescriptor to open it.
Returns the last offset set with AsyncFileRead::setOffset
|
inline |
Sets the offset in bytes at which start reading.
SC::Result SC::AsyncFileRead::start | ( | AsyncEventLoop & | eventLoop | ) |
Starts a file receive operation, that completes when data has been read from file / pipe.
eventLoop | The EventLoop to run this operation on |
O_DIRECT
/ FILE_FLAG_WRITE_THROUGH
& FILE_FLAG_NO_BUFFERING
) can be used in non-blocking mode (OpenOptions::blocking
== false
) without a thread pool and SC::AsyncEventLoop::associateExternallyCreatedFileDescriptor must have been called on the passed in handle.io_uring
backend will not use thread pool because that API allows proper async file read/writes. Span<char> SC::AsyncFileRead::buffer |
Callback called when some data has been read from the file into the buffer.
FileDescriptor::Handle SC::AsyncFileRead::fileDescriptor |
The writeable span of memory where to data will be written.