boost::corosio::stream_file
An asynchronous sequential file for coroutine I/O.
Synopsis
Declared in <boost/corosio/stream_file.hpp>
class stream_file
: public io_stream
Description
Provides asynchronous read and write operations on a regular file with an implicit position that advances after each operation.
Inherits from io_stream, so read_some and write_some are available and work with any algorithm that accepts an io_stream&.
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. Only one asynchronous operation may be in flight at a time.
Example
io_context ioc;
stream_file f(ioc);
f.open("data.bin", file_base::read_only);
char buf[4096];
auto [ec, n] = co_await f.read_some(
capy::mutable_buffer(buf, sizeof(buf)));
if (ec == capy::cond::eof)
// end of file
Types
Name |
Description |
RAII wrapper for I/O object implementation lifetime. |
|
Platform‐specific file implementation interface. |
|
Service interface for I/O object lifecycle management. |
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. |
|
Asynchronously read data from the stream. |
|
Release ownership of the native handle. |
|
Resize the file to |
|
Move the file position. |
|
Return the file size in bytes. |
|
Synchronize file data and metadata to stable storage. |
|
Synchronize file data to stable storage. |
|
Asynchronously write data to the stream. |
Protected Types
Name |
Description |
Awaitable for async read operations. |
|
Awaitable for async write operations. |
Protected Member Functions
Name |
Description |
|
Constructors |
|
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 sequential file with devirtualized async I/O operations. |
Created with MrDocs