I/O
Introduction
xpp::io provides reactive async I/O for non-blocking file descriptors, plus a structured error type shared across all I/O modules (net, fs, etc.).
#include <xpp/io/async_fd.h>
#include <xpp/io/error.h>
xpp::EventLoop loop;
xpp::WaitScope scope(loop);
int sv[2];
socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, sv);
xpp::io::AsyncFd io(sv[0]);
write(sv[1], "hello", 5);
char buf[64] = {};
ssize_t n = xpp::io::read(io, buf, sizeof(buf)).await();
Modules
-
AsyncFd — Reactive I/O wrapper: register fd once,
readable()/writable()asPromise<void>, fast-pathread()/write(). -
I/O Error —
io::Error: niche-optimized (4-byte) error type withErrorKind,raw_os_error(),raw_xerrno(). Mirrors Rust'sstd::io::Error. -
Utilities —
read_allandcopy: duck-typed template functions. Coroutine loops with 8KB stack buffers (C++20) or struct+move fallback (C++11). -
BufReader —
BufReader<R>: buffered async reader. Reduces per-call Promise overhead for small reads. -
Split —
BufWriter<W>: buffered async writer. Coalesces small writes, explicitflush().