aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-05-01 23:17:15 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-05-01 23:17:28 -0400
commit45bce27b8fecda4fba1c22dd191030af29ccbc6f (patch)
tree946b5080cbe75dd1ef150ac830522a1ce40c526b /lib/std/os
parent988031c07c1959b05682f007ed3bc848a75a43d0 (diff)
downloadzig-45bce27b8fecda4fba1c22dd191030af29ccbc6f.tar.gz
zig-45bce27b8fecda4fba1c22dd191030af29ccbc6f.zip
cleanup and fixes. behavior tests passing with evented I/O
Diffstat (limited to 'lib/std/os')
-rw-r--r--lib/std/os/windows.zig35
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index 7f273c141a..3e55a825de 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -110,7 +110,7 @@ pub const OpenFileOptions = struct {
share_access: ULONG = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
share_access_nonblocking: bool = false,
creation: ULONG,
- enable_async_io: bool = std.io.is_async,
+ io_mode: std.io.ModeOverride,
};
/// TODO when share_access_nonblocking is false, this implementation uses
@@ -145,7 +145,7 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN
var delay: usize = 1;
while (true) {
- const blocking_flag: ULONG = if (!options.enable_async_io) FILE_SYNCHRONOUS_IO_NONALERT else 0;
+ const blocking_flag: ULONG = if (options.io_mode == .blocking) FILE_SYNCHRONOUS_IO_NONALERT else 0;
const rc = ntdll.NtCreateFile(
&result,
options.access_mask,
@@ -451,11 +451,11 @@ pub const ReadFileError = error{
/// If buffer's length exceeds what a Windows DWORD integer can hold, it will be broken into
/// multiple non-atomic reads.
-pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, enable_async_io: bool) ReadFileError!usize {
- if (std.event.Loop.instance != null and enable_async_io) {
+pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.ModeOverride) ReadFileError!usize {
+ if (io_mode != .blocking) {
const loop = std.event.Loop.instance.?;
- // TODO support async ReadFile with no offset
- const off = if (offset == null) 0 else offset.?;
+ // TODO make getting the file position non-blocking
+ const off = if (offset) |o| o else try SetFilePointerEx_CURRENT_get(in_hFile);
var resume_node = std.event.Loop.ResumeNode.Basic{
.base = .{
.id = .Basic,
@@ -486,6 +486,11 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, enable_async_io: b
else => |err| return unexpectedError(err),
}
}
+ if (offset == null) {
+ // TODO make setting the file position non-blocking
+ const new_off = off + bytes_transferred;
+ try SetFilePointerEx_CURRENT(in_hFile, @bitCast(i64, new_off));
+ }
return @as(usize, bytes_transferred);
} else {
var index: usize = 0;
@@ -525,11 +530,16 @@ pub const WriteFileError = error{
Unexpected,
};
-pub fn WriteFile(handle: HANDLE, bytes: []const u8, offset: ?u64, enable_async_io: bool) WriteFileError!usize {
- if (std.event.Loop.instance != null and enable_async_io) {
+pub fn WriteFile(
+ handle: HANDLE,
+ bytes: []const u8,
+ offset: ?u64,
+ io_mode: std.io.ModeOverride,
+) WriteFileError!usize {
+ if (std.event.Loop.instance != null and io_mode != .blocking) {
const loop = std.event.Loop.instance.?;
- // TODO support async WriteFile with no offset
- const off = if (offset == null) 0 else offset.?;
+ // TODO make getting the file position non-blocking
+ const off = if (offset) |o| o else try SetFilePointerEx_CURRENT_get(handle);
var resume_node = std.event.Loop.ResumeNode.Basic{
.base = .{
.id = .Basic,
@@ -562,6 +572,11 @@ pub fn WriteFile(handle: HANDLE, bytes: []const u8, offset: ?u64, enable_async_i
else => |err| return unexpectedError(err),
}
}
+ if (offset == null) {
+ // TODO make setting the file position non-blocking
+ const new_off = off + bytes_transferred;
+ try SetFilePointerEx_CURRENT(handle, @bitCast(i64, new_off));
+ }
return bytes_transferred;
} else {
var bytes_written: DWORD = undefined;