eve.rt.fiber.file

Fiber-File — Blocking-Style File I/O on Top of Eve's AsyncFile

This module provides FiberFile, a struct wrapper around Eve's callback-driven AsyncFile that turns every I/O operation into a fiber yield point. From the caller's perspective the API looks blocking; from the event loop's perspective it is just more callbacks.

Must be used from within a fiber that is managed by a FiberScheduler attached to an EventLoop.

Example (inside a fiber):

auto f = FiberFile.create(sched, loop);
scope (exit) f.dispose();
f.open("/etc/hostname", O_RDONLY);
auto content = f.read(0, 4096);
f.close();

struct FiberFile

Types 1

structFiberFile

A fiber-friendly async file handle.

Wraps an AsyncFile. Read and write operations yield the current fiber and resume when the operation completes or fails.

Concurrency: AsyncFile supports at most one pending operation at a time. Do not call read() or write() concurrently from multiple fibers on the same FiberFile.

Open is synchronous: open() calls the OS open() syscall directly and does not yield the fiber. Only read() and write() yield.

Fields
private AsyncFile _file
private FiberScheduler _sched
private EventLoop * _loop
Methods
FiberFile create(FiberScheduler sched, ref EventLoop loop) static @trustedCreate a `FiberFile` bound to the given scheduler and event loop.
OpenResult open(scope const(char)[] path, int flags) @trustedOpen a file. Synchronous — does not yield the fiber.
ubyte[] read(ulong offset, size_t maxBytes = 4096) @trustedRead up to `maxBytes` starting at `offset`. Yields until the read completes.
size_t readInto(ubyte[] buffer, ulong offset) @trustedRead into a caller-supplied buffer starting at `offset`. Yields until the read completes.
size_t write(scope const(ubyte)[] data, ulong offset) @trustedWrite data at the given offset. Yields until the write completes.
void close() @trustedClose the file handle. Synchronous — does not yield.
void dispose() @trustedRelease all resources held by this file handle.
bool isOpen() @property const @safe nothrow @nogcCheck whether the file is open.
bool usingIoUring() @property const @safe nothrow @nogcCheck whether the file is using io_uring (Linux only).