| author | |
| committer | |
| log | 18f6629bd8ad8bd13108ddce82c32baf6f53628e |
| tree | 20550ae733e4516a5db6842aa15f3153be1d6146 |
| parent | 9075f8e5a1a788770cc8193d6f54118434e72a4b |
Signed-off-by: Loris Cro <kappaloris@gmail.com>3 files changed, 32 insertions(+), 23 deletions(-)
lib/std/event/loop.zig+26-14| ... | @@ -989,23 +989,35 @@ pub const Loop = struct { | ... | @@ -989,23 +989,35 @@ pub const Loop = struct { |
| 989 | 989 | ||
| 990 | /// Performs an async `os.writev` using a separate thread. | 990 | /// Performs an async `os.writev` using a separate thread. |
| 991 | /// `fd` must block and not return EAGAIN. | 991 | /// `fd` must block and not return EAGAIN. |
| 992 | pub fn writev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const) os.WriteError!usize { | 992 | pub fn writev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const, simulate_evented: bool) os.WriteError!usize { |
| 993 | var req_node = Request.Node{ | 993 | if (simulate_evented) { |
| 994 | .data = .{ | 994 | var req_node = Request.Node{ |
| 995 | .msg = .{ | 995 | .data = .{ |
| 996 | .writev = .{ | 996 | .msg = .{ |
| 997 | .fd = fd, | 997 | .writev = .{ |
| 998 | .iov = iov, | 998 | .fd = fd, |
| 999 | .result = undefined, | 999 | .iov = iov, |
| 1000 | .result = undefined, | ||
| 1001 | }, | ||
| 1000 | }, | 1002 | }, |
| 1003 | .finish = .{ .TickNode = .{ .data = @frame() } }, | ||
| 1001 | }, | 1004 | }, |
| 1002 | .finish = .{ .TickNode = .{ .data = @frame() } }, | 1005 | }; |
| 1003 | }, | 1006 | suspend { |
| 1004 | }; | 1007 | self.posixFsRequest(&req_node); |
| 1005 | suspend { | 1008 | } |
| 1006 | self.posixFsRequest(&req_node); | 1009 | return req_node.data.msg.writev.result; |
| 1010 | } else { | ||
| 1011 | while (true) { | ||
| 1012 | return os.writev(fd, iov) catch |err| switch (err) { | ||
| 1013 | error.WouldBlock => { | ||
| 1014 | self.waitUntilFdWritable(fd); | ||
| 1015 | continue; | ||
| 1016 | }, | ||
| 1017 | else => return err, | ||
| 1018 | }; | ||
| 1019 | } | ||
| 1007 | } | 1020 | } |
| 1008 | return req_node.data.msg.writev.result; | ||
| 1009 | } | 1021 | } |
| 1010 | 1022 | ||
| 1011 | /// Performs an async `os.pwritev` using a separate thread. | 1023 | /// Performs an async `os.pwritev` using a separate thread. |
lib/std/fs/file.zig+5-3| ... | @@ -586,10 +586,12 @@ pub const File = struct { | ... | @@ -586,10 +586,12 @@ pub const File = struct { |
| 586 | if (iovecs.len == 0) return @as(usize, 0); | 586 | if (iovecs.len == 0) return @as(usize, 0); |
| 587 | const first = iovecs[0]; | 587 | const first = iovecs[0]; |
| 588 | return windows.WriteFile(self.handle, first.iov_base[0..first.iov_len], null, self.intended_io_mode); | 588 | return windows.WriteFile(self.handle, first.iov_base[0..first.iov_len], null, self.intended_io_mode); |
| 589 | } else if (self.capable_io_mode != self.intended_io_mode) { | 589 | } |
| 590 | return std.event.Loop.instance.?.writev(self.handle, iovecs); | 590 | |
| 591 | } else { | 591 | if (self.intended_io_mode == .blocking) { |
| 592 | return os.writev(self.handle, iovecs); | 592 | return os.writev(self.handle, iovecs); |
| 593 | } else { | ||
| 594 | return std.event.Loop.instance.?.writev(self.handle, iovecs, self.capable_io_mode != self.intended_io_mode); | ||
| 593 | } | 595 | } |
| 594 | } | 596 | } |
| 595 | 597 |
lib/std/os.zig+1-6| ... | @@ -789,12 +789,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { | ... | @@ -789,12 +789,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { |
| 789 | EINTR => continue, | 789 | EINTR => continue, |
| 790 | EINVAL => unreachable, | 790 | EINVAL => unreachable, |
| 791 | EFAULT => unreachable, | 791 | EFAULT => unreachable, |
| 792 | EAGAIN => if (std.event.Loop.instance) |loop| { | 792 | EAGAIN => return error.WouldBlock, |
| 793 | loop.waitUntilFdWritable(fd); | ||
| 794 | continue; | ||
| 795 | } else { | ||
| 796 | return error.WouldBlock; | ||
| 797 | }, | ||
| 798 | EBADF => return error.NotOpenForWriting, // Can be a race condition. | 793 | EBADF => return error.NotOpenForWriting, // Can be a race condition. |
| 799 | EDESTADDRREQ => unreachable, // `connect` was never called. | 794 | EDESTADDRREQ => unreachable, // `connect` was never called. |
| 800 | EDQUOT => return error.DiskQuota, | 795 | EDQUOT => return error.DiskQuota, |