feature. See also
. The project being documented here (as the example) is the Zig library itself.
Uring.preadv
fn preadv(
ev: *Evented,
cancel_region: *CancelRegion,
fd: fd_t,
iov: []const iovec,
offset: ?u64,
) File.Reader.Error!usize
File
Code
fn preadv(
ev: *Evented,
cancel_region: *CancelRegion,
fd: fd_t,
iov: []const iovec,
offset: ?u64,
) File.Reader.Error!usize {
if (iov.len == 0) return 0;
const gather = iov.len > 1 or iov[0].len > 0xfffff000;
while (true) {
const thread = try cancel_region.awaitIoUring();
thread.enqueue().* = .{
.opcode = if (gather) .READV else .READ,
.flags = 0,
.ioprio = 0,
.fd = fd,
.off = offset orelse std.math.maxInt(u64),
.addr = if (gather) @intFromPtr(iov.ptr) else @intFromPtr(iov[0].base),
.len = @intCast(if (gather) iov.len else iov[0].len),
.rw_flags = 0,
.user_data = @intFromPtr(cancel_region.fiber),
.buf_index = 0,
.personality = 0,
.splice_fd_in = 0,
.addr3 = 0,
.resv = 0,
};
ev.yield(null, .nothing);
const completion = cancel_region.completion();
switch (completion.errno()) {
.SUCCESS => return @as(u32, @bitCast(completion.result)),
.INTR, .CANCELED => {},
.INVAL => |err| return errnoBug(err),
.FAULT => |err| return errnoBug(err),
.AGAIN => return error.WouldBlock,
.BADF => |err| return errnoBug(err),
.IO => return error.InputOutput,
.ISDIR => return error.IsDir,
.NOBUFS => return error.SystemResources,
.NOMEM => return error.SystemResources,
.NOTCONN => return error.SocketUnconnected,
.CONNRESET => return error.ConnectionResetByPeer,
else => |err| return unexpectedErrno(err),
}
}
}