boost::corosio::random_access_file
An asynchronous random‐access file for coroutine I/O.
Synopsis
class random_access_file
: public io_object
Description
Provides asynchronous read and write operations at explicit byte offsets, without maintaining an implicit file position.
On POSIX platforms, file I/O is dispatched to a thread pool (blocking preadv/`pwritev`) with completion posted back to the scheduler. On Windows, true overlapped I/O is used via IOCP.
Thread Safety
Distinct objects: Safe. Shared objects: Unsafe. Multiple concurrent reads and writes are supported from coroutines sharing the same file object, but external synchronization is required for non‐async operations (open, close, size, resize, etc.).
Example
io_context ioc;
random_access_file f(ioc);
f.open("data.bin", file_base::read_only);
char buf[4096];
auto [ec, n] = co_await f.read_some_at(
0, capy::mutable_buffer(buf, sizeof(buf)));
Types
Name |
Description |
RAII wrapper for I/O object implementation lifetime. |
|
Platform‐specific random‐access file implementation interface. |
|
Service interface for I/O object lifecycle management. |
|
Awaitable for async read‐at operations. |
|
Awaitable for async write‐at operations. |
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Move assignment operator. |
Adopt an existing native handle. |
|
Cancel pending asynchronous operations. |
|
Close the file. |
|
Return the execution context. |
|
Check if the file is open. |
|
Get the native file descriptor or handle. |
|
Open a file. |
|
Read data at the given offset. |
|
Release ownership of the native handle. |
|
Resize the file. |
|
Return the file size in bytes. |
|
Synchronize file data and metadata to stable storage. |
|
Synchronize file data to stable storage. |
|
Write data at the given offset. |
Protected Member Functions
Name |
Description |
|
Construct from a pre‐built handle (for native_random_access_file). |
|
Move assign from another I/O object. |
Protected Static Member Functions
Name |
Description |
Create a handle bound to a service found in the context. |
Derived Classes
Name |
Description |
A random‐access file with devirtualized async I/O operations. |
Created with MrDocs