feature. See also
. The project being documented here (as the example) is the Zig library itself.
Threaded.fileReadStreamingWindows
fn fileReadStreamingWindows(file: File, data: []const []u8) File.ReadStreamingError!usize
File
Code
fn fileReadStreamingWindows(file: File, data: []const []u8) File.ReadStreamingError!usize {
var iosb: windows.IO_STATUS_BLOCK = undefined;
var index: usize = 0;
while (data.len - index != 0 and data[index].len == 0) index += 1;
if (data.len - index == 0) return 0;
const buffer = data[index];
const short_buffer_len = std.math.lossyCast(u32, buffer.len);
if (file.flags.nonblocking) {
var done: bool = false;
switch (windows.ntdll.NtReadFile(
file.handle,
null,
flagApc,
&done,
&iosb,
buffer.ptr,
short_buffer_len,
null,
null,
)) {
.PENDING, .SUCCESS => while (!done) {
// operation completes, thereby releasing reference to the iosb.
const alertable_syscall = AlertableSyscall.start() catch |err| switch (err) {
error.Canceled => |e| {
var cancel_iosb: windows.IO_STATUS_BLOCK = undefined;
_ = windows.ntdll.NtCancelIoFileEx(file.handle, &iosb, &cancel_iosb);
while (!done) waitForApcOrAlert();
return e;
},
};
waitForApcOrAlert();
alertable_syscall.finish();
},
else => |status| iosb.u.Status = status,
}
} else {
const syscall: Syscall = try .start();
while (true) switch (windows.ntdll.NtReadFile(
file.handle,
null,
null,
null,
&iosb,
buffer.ptr,
short_buffer_len,
null,
null,
)) {
.PENDING => unreachable,
.CANCELLED => {
try syscall.checkCancel();
continue;
},
else => |status| {
syscall.finish();
iosb.u.Status = status;
break;
},
};
}
return ntReadFileResult(&iosb);
}