Starts a file read operation, reading bytes from a file (or pipe). More...
#include <Async.h>
Classes | |
| struct | CompletionData |
| struct | Result |
Public Member Functions | |
| uint64_t | getOffset () const |
| The file/pipe descriptor handle to read data from. | |
| void | setOffset (uint64_t fileOffset) |
| Sets the offset in bytes at which start reading. | |
| Result | start (AsyncEventLoop &eventLoop) |
| Shortcut for AsyncEventLoop::start. | |
Public Member Functions inherited from SC::AsyncRequest | |
| void | setDebugName (const char *newDebugName) |
| void | executeOn (AsyncSequence &sequence) |
| Adds the request to be executed on a specific AsyncSequence. | |
| Result | executeOn (AsyncTaskSequence &task, ThreadPool &pool) |
| Adds the request to be executed on a specific AsyncTaskSequence. | |
| void | disableThreadPool () |
| Disables the thread-pool usage for this request. | |
| AsyncRequest (Type type) | |
| Constructs a free async request of given type. | |
| Result | stop (AsyncEventLoop &eventLoop, Function< void(AsyncResult &)> *afterStopped=nullptr) |
| Ask to stop current async operation. | |
| bool | isFree () const |
Returns true if this request is free. | |
| bool | isCancelling () const |
Returns true if this request is being cancelled. | |
| bool | isActive () const |
Returns true if this request is active or being reactivated. | |
| Type | getType () const |
| Returns request type. | |
| Result | start (AsyncEventLoop &eventLoop) |
| Shortcut for AsyncEventLoop::start. | |
| void | setUserFlags (uint16_t externalFlags) |
| Sets user flags, holding some meaningful data for the caller. | |
| uint16_t | getUserFlags () const |
| Gets user flags, holding some meaningful data for the caller. | |
| Function< void(AsyncResult &)> * | getCloseCallback () |
| Returns currently set close callback (if any) passed to AsyncRequest::stop. | |
| const Function< void(AsyncResult &)> * | getCloseCallback () const |
Public Attributes | |
| Function< void(Result &)> | callback |
| Span< char > | buffer |
| Callback called when some data has been read from the file into the buffer. | |
| FileDescriptor::Handle | handle |
| The writeable span of memory where to data will be written. | |
Public Attributes inherited from SC::AsyncRequest | |
| AsyncRequest * | next = nullptr |
| AsyncRequest * | prev = nullptr |
Friends | |
| struct | AsyncEventLoop |
Additional Inherited Members | |
Public Types inherited from SC::AsyncRequest | |
| enum class | Type : uint8_t { LoopTimeout , LoopWakeUp , LoopWork , ProcessExit , SocketAccept , SocketConnect , SocketSend , SocketSendTo , SocketReceive , SocketReceiveFrom , FileRead , FileWrite , FilePoll , FileSystemOperation } |
| Type of async request. More... | |
Protected Member Functions inherited from SC::AsyncRequest | |
| Result | checkState () |
| void | queueSubmission (AsyncEventLoop &eventLoop) |
| AsyncTaskSequence * | getTask () |
Protected Attributes inherited from SC::AsyncRequest | |
| AsyncSequence * | sequence = 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::executeOn 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:
io_uring backend will not use thread pool because that API allows proper async file read/writes
|
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.
| Result SC::AsyncRequest::start | ( | AsyncEventLoop & | eventLoop | ) |
Shortcut for AsyncEventLoop::start.
| Span<char> SC::AsyncFileRead::buffer |
Callback called when some data has been read from the file into the buffer.
| FileDescriptor::Handle SC::AsyncFileRead::handle |
The writeable span of memory where to data will be written.