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 {
855855
856856 /// Performs an async `os.readv` using a separate thread.
857857 /// `fd` must block and not return EAGAIN.
858 pub fn readv(self: *Loop, fd: os.fd_t, iov: []const os.iovec) os.ReadError!usize {
859 var req_node = Request.Node{
860 .data = .{
861 .msg = .{
862 .readv = .{
863 .fd = fd,
864 .iov = iov,
865 .result = undefined,
858 pub fn readv(self: *Loop, fd: os.fd_t, iov: []const os.iovec, simulate_evented: bool) os.ReadError!usize {
859 if (simulate_evented) {
860 var req_node = Request.Node{
861 .data = .{
862 .msg = .{
863 .readv = .{
864 .fd = fd,
865 .iov = iov,
866 .result = undefined,
867 },
866868 },
869 .finish = .{ .TickNode = .{ .data = @frame() } },
867870 },
868 .finish = .{ .TickNode = .{ .data = @frame() } },
869 },
870 };
871 suspend {
872 self.posixFsRequest(&req_node);
871 };
872 suspend {
873 self.posixFsRequest(&req_node);
874 }
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 }
873886 }
874 return req_node.data.msg.readv.result;
875887 }
876888
877889 /// Performs an async `os.pread` using a separate thread.
lib/std/fs/file.zig+5-3
......@@ -463,10 +463,12 @@ pub const File = struct {
463463 if (iovecs.len == 0) return @as(usize, 0);
464464 const first = iovecs[0];
465465 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) {
467 return std.event.Loop.instance.?.readv(self.handle, iovecs);
468 } else {
466 }
467
468 if (self.intended_io_mode == .blocking) {
469469 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);
470472 }
471473 }
472474
lib/std/os.zig+1-6
......@@ -423,12 +423,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
423423 EINTR => continue,
424424 EINVAL => unreachable,
425425 EFAULT => unreachable,
426 EAGAIN => if (std.event.Loop.instance) |loop| {
427 loop.waitUntilFdReadable(fd);
428 continue;
429 } else {
430 return error.WouldBlock;
431 },
426 EAGAIN => return error.WouldBlock,
432427 EBADF => return error.NotOpenForReading, // can be a race condition
433428 EIO => return error.InputOutput,
434429 EISDIR => return error.IsDir,