feature. See also
. The project being documented here (as the example) is the Zig library itself.
Dispatch.fileReadStreamingLimit
fn fileReadStreamingLimit(
handle: File.Handle,
data: []const []u8,
limit: Io.Limit,
) File.ReadStreamingError!usize
File
Code
fn fileReadStreamingLimit(
handle: File.Handle,
data: []const []u8,
limit: Io.Limit,
) File.ReadStreamingError!usize {
var iovecs: [max_iovecs_len]iovec = undefined;
var iovlen: iovlen_t = 0;
// in which case the buffer still needs to be drained
var remaining = if (limit == .nothing) .unlimited else limit;
for (data) |buf| addBuf(false, &iovecs, &iovlen, &remaining, buf);
if (iovlen == 0) return 0;
while (true) {
const rc = c.readv(handle, &iovecs, iovlen);
switch (c.errno(rc)) {
.SUCCESS => return if (rc == 0) error.EndOfStream else @intCast(rc),
.INTR => continue,
.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),
}
}
}