Starts an asynchronous file system operation (open, close, read, write, sendFile, stat, lstat, fstat, etc.) Some operations need a file path and others need a file descriptor. More...
#include <Async.h>
Public Types | |
enum class | Operation { None = 0 , Open , Close , Read , Write , CopyFile } |
using | CompletionData = AsyncFileSystemOperationCompletionData |
using | Result = AsyncResultOf<AsyncFileSystemOperation, CompletionData> |
![]() | |
enum class | Type : uint8_t { LoopTimeout , LoopWakeUp , LoopWork , ProcessExit , SocketAccept , SocketConnect , SocketSend , SocketSendTo , SocketReceive , SocketReceiveFrom , FileRead , FileWrite , FilePoll , FileSystemOperation } |
Type of async request. More... | |
Public Member Functions | |
SC::Result | setThreadPool (ThreadPool &threadPool) |
Sets the thread pool to use for the operation. | |
SC::Result | open (AsyncEventLoop &eventLoop, StringViewData path, FileOpen mode) |
Opens a file asynchronously and returns its corresponding file descriptor. | |
SC::Result | close (AsyncEventLoop &eventLoop, FileDescriptor::Handle handle) |
Closes a file descriptor asynchronously. | |
SC::Result | read (AsyncEventLoop &eventLoop, FileDescriptor::Handle handle, Span< char > buffer, uint64_t offset) |
Reads data from a file descriptor at a given offset. | |
SC::Result | write (AsyncEventLoop &eventLoop, FileDescriptor::Handle handle, Span< const char > buffer, uint64_t offset) |
Writes data to a file descriptor at a given offset. | |
SC::Result | copyFile (AsyncEventLoop &eventLoop, StringViewData path, StringViewData destinationPath, FileSystemCopyFlags copyFlags=FileSystemCopyFlags()) |
Copies a file from one location to another. | |
![]() | |
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 |
Called after the operation is completed, on the event loop thread. | |
![]() | |
AsyncRequest * | next = nullptr |
AsyncRequest * | prev = nullptr |
Friends | |
struct | AsyncEventLoop |
Additional Inherited Members | |
![]() | |
Result | checkState () |
void | queueSubmission (AsyncEventLoop &eventLoop) |
AsyncTaskSequence * | getTask () |
![]() | |
AsyncSequence * | sequence = nullptr |
Starts an asynchronous file system operation (open, close, read, write, sendFile, stat, lstat, fstat, etc.) Some operations need a file path and others need a file descriptor.
Example of async open operation:
Example of async close operation:
Example of async read operation:
SC::Result SC::AsyncFileSystemOperation::close | ( | AsyncEventLoop & | eventLoop, |
FileDescriptor::Handle | handle ) |
Closes a file descriptor asynchronously.
eventLoop | The event loop to use |
handle | The file descriptor to close |
SC::Result SC::AsyncFileSystemOperation::copyFile | ( | AsyncEventLoop & | eventLoop, |
StringViewData | path, | ||
StringViewData | destinationPath, | ||
FileSystemCopyFlags | copyFlags = FileSystemCopyFlags() ) |
Copies a file from one location to another.
eventLoop | The event loop to use |
path | The path to the source file |
destinationPath | The path to the destination file |
copyFlags | Flags to control the copy operation |
SC::Result SC::AsyncFileSystemOperation::open | ( | AsyncEventLoop & | eventLoop, |
StringViewData | path, | ||
FileOpen | mode ) |
Opens a file asynchronously and returns its corresponding file descriptor.
eventLoop | The event loop to use |
path | The path to the file to open (encoded in UTF-8 on Posix and UTF-16 on Windows) |
mode | The mode to open the file in (read, write, read-write, etc.) |
SC::Result SC::AsyncFileSystemOperation::read | ( | AsyncEventLoop & | eventLoop, |
FileDescriptor::Handle | handle, | ||
Span< char > | buffer, | ||
uint64_t | offset ) |
Reads data from a file descriptor at a given offset.
eventLoop | The event loop to use |
handle | The file descriptor to read from |
buffer | The buffer to read into |
offset | The offset in the file to read from |
SC::Result SC::AsyncFileSystemOperation::setThreadPool | ( | ThreadPool & | threadPool | ) |
Sets the thread pool to use for the operation.
SC::Result SC::AsyncFileSystemOperation::write | ( | AsyncEventLoop & | eventLoop, |
FileDescriptor::Handle | handle, | ||
Span< const char > | buffer, | ||
uint64_t | offset ) |
Writes data to a file descriptor at a given offset.
eventLoop | The event loop to use |
handle | The file descriptor to write to |
buffer | The buffer containing data to write |
offset | The offset in the file to write to |
Called after the operation is completed, on the event loop thread.