eve.sys.linux.uring

Syscall wrappers and submission helpers for Linux io_uring.

This module builds on top of core.sys.linux.io_uring, which provides the structure definitions and constants from the kernel ABI. This module adds:

There is no compile-time version check. Call io_uring_setup and handle ENOSYS to detect kernel support at runtime.

See Also

Types 3

Result of probing io_uring feature support.

Call probeIoUringFeatures to obtain an instance, then query individual feature support. All fields default to false when io_uring is unavailable or probing fails.

Fields
bool ioUringAvailable
bool sqpoll
bool nativeRead
bool nativeWrite
bool nativeClose
bool splice
bool send
bool recv
bool readFixed
bool writeFixed
bool registeredBuffers
bool registeredFiles
uint kernelVersion
Methods
bool supportsOpcode(ubyte opcode) const @safe pure nothrow @nogcCheck whether a specific io_uring opcode is supported.

Manage registered fixed buffers for zero-copy io_uring I/O.

Registered buffers allow the kernel to perform I/O directly to/from application memory without extra copies. Use io_uring_prep_read_fixed and io_uring_prep_write_fixed to submit operations against registered buffer slots.

Call register to register buffers with the ring, and dispose to release the kernel's references.

Example:

auto table = IoUringBufferTable.create(ringFd);
scope (exit) table.dispose();

ubyte[4096] buf1;
ubyte[4096] buf2;
iovec[2] iov = [
    iovec(cast(void*)buf1.ptr, buf1.length),
    iovec(cast(void*)buf2.ptr, buf2.length),
];
assert(table.register(iov[]));

// Now use io_uring_prep_read_fixed(sqe, fd, buf1.ptr, 4096, 0, 0, userData);
//                                                       buf_index = 0 ^

Fields
int _ringFd
uint _count
Methods
IoUringBufferTable create(int ringFd) static pure @safe nothrow @nogcCreate a buffer table for a given io_uring instance.
bool register(scope const(iovec)[] buffers) @trusted nothrow @nogcRegister an array of buffers with the io_uring instance.
bool unregister() @trusted nothrow @nogcUnregister all buffers from the io_uring instance.
void dispose() @trusted nothrow @nogcRelease the buffer table.
uint count() @property const pure @safe nothrow @nogcNumber of currently registered buffers.
bool isEmpty() @property const pure @safe nothrow @nogcWhether any buffers are registered.

Manage registered fixed file descriptors for io_uring.

Registered files allow the kernel to avoid looking up file descriptors on each operation, reducing overhead in high-concurrency scenarios. Use io_uring_sqe_set_fixed_file to mark an SQE as using a registered file index.

Fields
int _ringFd
uint _count
Methods
IoUringFileTable create(int ringFd) static pure @safe nothrow @nogcCreate a file table for a given io_uring instance.
bool register(scope const(int)[] files) @trusted nothrow @nogcRegister an array of file descriptors with the io_uring instance.
bool unregister() @trusted nothrow @nogcUnregister all files from the io_uring instance.
bool updateFile(uint index, int fd) @trusted nothrow @nogcUpdate a single file descriptor in the registered table.
void dispose() @trusted nothrow @nogcRelease the file table.
uint count() @property const pure @safe nothrow @nogc
bool isEmpty() @property const pure @safe nothrow @nogc

Functions 19

private fnlong syscall(long number, ...) @system nothrow @nogc
fnint io_uring_setup(uint entries, io_uring_params * params) @systemSet up an io_uring instance.
fnint io_uring_enter(int fd, uint to_submit, uint min_complete, uint flags, const sigset_t * sig = null) @systemInitiate and/or complete I/O using the io_uring instance.
fnint io_uring_register(int fd, uint opcode, const void * arg, uint nr_args) @systemRegister files or buffers with the io_uring instance.
fnvoid io_uring_prep_nop(io_uring_sqe * sqe, ulong user_data) pure @safePrepare an SQE for a NOP operation.
fnvoid io_uring_prep_poll_add(io_uring_sqe * sqe, int fd, ushort poll_mask, ulong user_data) pure @safePrepare an SQE for a POLL_ADD operation.
fnvoid io_uring_prep_poll_remove(io_uring_sqe * sqe, ulong target_user_data, ulong user_data) pure @safePrepare an SQE for a POLL_REMOVE operation.
fnvoid io_uring_prep_read(io_uring_sqe * sqe, int fd, void * buf, uint len, ulong offset, ulong user_data) pure @systemPrepare an SQE for a READ operation.
fnvoid io_uring_prep_write(io_uring_sqe * sqe, int fd, const void * buf, uint len, ulong offset, ulong user_data) pure @systemPrepare an SQE for a WRITE operation.
fnvoid io_uring_prep_close(io_uring_sqe * sqe, int fd, ulong user_data) pure @safePrepare an SQE for a CLOSE operation.
fnvoid io_uring_sqe_set_flags(io_uring_sqe * sqe, ubyte flags) pure @safeSet SQE flags on an existing SQE.
fnvoid io_uring_prep_splice(io_uring_sqe * sqe, int fd_in, ulong off_in, int fd_out, ulong off_out, uint len, uint flags, ulong user_data) pure @systemPrepare an SQE for a SPLICE operation.
fnvoid io_uring_prep_send(io_uring_sqe * sqe, int fd, const void * buf, uint len, uint flags, ulong user_data) pure @systemPrepare an SQE for a SEND operation.
fnvoid io_uring_prep_recv(io_uring_sqe * sqe, int fd, void * buf, uint len, uint flags, ulong user_data) pure @systemPrepare an SQE for a RECV operation.
fnvoid io_uring_prep_read_fixed(io_uring_sqe * sqe, int fd, void * buf, uint len, ulong offset, ushort buf_index, ulong user_data) pure @systemPrepare an SQE for a READ_FIXED operation (zero-copy using registered buffer).
fnvoid io_uring_prep_write_fixed(io_uring_sqe * sqe, int fd, const void * buf, uint len, ulong offset, ushort buf_index, ulong user_data) pure @systemPrepare an SQE for a WRITE_FIXED operation (zero-copy using registered buffer).
fnvoid io_uring_sqe_set_fixed_file(io_uring_sqe * sqe) pure @safe nothrow @nogcSet the fixed-file flag on an SQE.
fnIoUringFeatures probeIoUringFeatures() @trusted nothrowProbe the running kernel for io_uring feature support.
private fnsize_t min(size_t a, size_t b) pure @safe nothrow @nogc