authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-06-19 23:00:17+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-09-24 22:03:12+02:00
logbc35435ca6e51d0e120538398e3c708ada57f6de
treede167c9e77a13122d68f07262ef0524eea999b6f
parent08364ac773bdc95b9407974b5c761dbdab863f4d

readv

Signed-off-by: Loris Cro <kappaloris@gmail.com>

3 files changed, 32 insertions(+), 23 deletions(-)

lib/std/event/loop.zig+26-14
...@@ -855,23 +855,35 @@ pub const Loop = struct {...@@ -855,23 +855,35 @@ pub const Loop = struct {
855855
856 /// Performs an async `os.readv` using a separate thread.856 /// Performs an async `os.readv` using a separate thread.
857 /// `fd` must block and not return EAGAIN.857 /// `fd` must block and not return EAGAIN.
858 pub fn readv(self: *Loop, fd: os.fd_t, iov: []const os.iovec) os.ReadError!usize {858 pub fn readv(self: *Loop, fd: os.fd_t, iov: []const os.iovec, simulate_evented: bool) os.ReadError!usize {
859 var req_node = Request.Node{859 if (simulate_evented) {
860 .data = .{860 var req_node = Request.Node{
861 .msg = .{861 .data = .{
862 .readv = .{862 .msg = .{
863 .fd = fd,863 .readv = .{
864 .iov = iov,864 .fd = fd,
865 .result = undefined,865 .iov = iov,
866 .result = undefined,
867 },
866 },868 },
869 .finish = .{ .TickNode = .{ .data = @frame() } },
867 },870 },
868 .finish = .{ .TickNode = .{ .data = @frame() } },871 };
869 },872 suspend {
870 };873 self.posixFsRequest(&req_node);
871 suspend {874 }
872 self.posixFsRequest(&req_node);875 return req_node.data.msg.readv.result;
876 } else {
877 while (true) {
878 return os.readv(fd, iov) catch |err| switch (err) {
879 error.WouldBlock => {
880 self.waitUntilFdReadable(fd);
881 continue;
882 },
883 else => return err,
884 };
885 }
873 }886 }
874 return req_node.data.msg.readv.result;
875 }887 }
876888
877 /// Performs an async `os.pread` using a separate thread.889 /// Performs an async `os.pread` using a separate thread.
lib/std/fs/file.zig+5-3
...@@ -463,10 +463,12 @@ pub const File = struct {...@@ -463,10 +463,12 @@ pub const File = struct {
463 if (iovecs.len == 0) return @as(usize, 0);463 if (iovecs.len == 0) return @as(usize, 0);
464 const first = iovecs[0];464 const first = iovecs[0];
465 return windows.ReadFile(self.handle, first.iov_base[0..first.iov_len], null, self.intended_io_mode);465 return windows.ReadFile(self.handle, first.iov_base[0..first.iov_len], null, self.intended_io_mode);
466 } else if (self.capable_io_mode != self.intended_io_mode) {466 }
467 return std.event.Loop.instance.?.readv(self.handle, iovecs);467
468 } else {468 if (self.intended_io_mode == .blocking) {
469 return os.readv(self.handle, iovecs);469 return os.readv(self.handle, iovecs);
470 } else {
471 return std.event.Loop.instance.?.readv(self.handle, iovecs, self.capable_io_mode != self.intended_io_mode);
470 }472 }
471 }473 }
472474
lib/std/os.zig+1-6
...@@ -423,12 +423,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {...@@ -423,12 +423,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
423 EINTR => continue,423 EINTR => continue,
424 EINVAL => unreachable,424 EINVAL => unreachable,
425 EFAULT => unreachable,425 EFAULT => unreachable,
426 EAGAIN => if (std.event.Loop.instance) |loop| {426 EAGAIN => return error.WouldBlock,
427 loop.waitUntilFdReadable(fd);
428 continue;
429 } else {
430 return error.WouldBlock;
431 },
432 EBADF => return error.NotOpenForReading, // can be a race condition427 EBADF => return error.NotOpenForReading, // can be a race condition
433 EIO => return error.InputOutput,428 EIO => return error.InputOutput,
434 EISDIR => return error.IsDir,429 EISDIR => return error.IsDir,