diff options
| author | Timon Kruiper <Timon Kruiper@LAPTOP-3V2IS54Q> | 2020-03-26 13:41:53 +0100 |
|---|---|---|
| committer | Timon Kruiper <Timon Kruiper@LAPTOP-3V2IS54Q> | 2020-03-27 17:03:06 +0100 |
| commit | 67e51311c3352ab4b2a381bd90dc386032254058 (patch) | |
| tree | 1b3b6ccc54f22f4ed56dc8a3126054741ecda9e6 /lib/std/fs | |
| parent | f7f563ea53cf58c772003a46624b87dad9c4311d (diff) | |
| download | zig-67e51311c3352ab4b2a381bd90dc386032254058.tar.gz zig-67e51311c3352ab4b2a381bd90dc386032254058.zip | |
fix behavior test with --test-evented-io on windows
also make simple file operations work asynchronously on windows
Diffstat (limited to 'lib/std/fs')
| -rw-r--r-- | lib/std/fs/file.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index c4991a81ff..6161c2348c 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -251,6 +251,10 @@ pub const File = struct { pub const PReadError = os.PReadError; pub fn read(self: File, buffer: []u8) ReadError!usize { + if (builtin.os.tag == .windows) { + const enable_async_io = std.io.is_async and !self.async_block_allowed; + return windows.ReadFile(self.handle, buffer, null, enable_async_io); + } if (need_async_thread and self.io_mode == .blocking and !self.async_block_allowed) { return std.event.Loop.instance.?.read(self.handle, buffer); } else { @@ -271,6 +275,10 @@ pub const File = struct { } pub fn pread(self: File, buffer: []u8, offset: u64) PReadError!usize { + if (builtin.os.tag == .windows) { + const enable_async_io = std.io.is_async and !self.async_block_allowed; + return windows.ReadFile(self.handle, buffer, offset, enable_async_io); + } if (need_async_thread and self.io_mode == .blocking and !self.async_block_allowed) { return std.event.Loop.instance.?.pread(self.handle, buffer, offset); } else { @@ -362,6 +370,10 @@ pub const File = struct { pub const PWriteError = os.PWriteError; pub fn write(self: File, bytes: []const u8) WriteError!usize { + if (builtin.os.tag == .windows) { + const enable_async_io = std.io.is_async and !self.async_block_allowed; + return windows.WriteFile(self.handle, bytes, null, enable_async_io); + } if (need_async_thread and self.io_mode == .blocking and !self.async_block_allowed) { return std.event.Loop.instance.?.write(self.handle, bytes); } else { @@ -377,6 +389,10 @@ pub const File = struct { } pub fn pwrite(self: File, bytes: []const u8, offset: u64) PWriteError!usize { + if (builtin.os.tag == .windows) { + const enable_async_io = std.io.is_async and !self.async_block_allowed; + return windows.WriteFile(self.handle, bytes, offset, enable_async_io); + } if (need_async_thread and self.io_mode == .blocking and !self.async_block_allowed) { return std.event.Loop.instance.?.pwrite(self.handle, bytes, offset); } else { |
