Signed-off-by: Loris Cro <kappaloris@gmail.com>
master
Loris Cro 2020-06-19 23:34:02 +02:00
parent 9075f8e5a1
commit 18f6629bd8
3 changed files with 32 additions and 23 deletions

View File

@ -989,7 +989,8 @@ pub const Loop = struct {
/// Performs an async `os.writev` using a separate thread. /// Performs an async `os.writev` using a separate thread.
/// `fd` must block and not return EAGAIN. /// `fd` must block and not return EAGAIN.
pub fn writev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const) os.WriteError!usize { pub fn writev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const, simulate_evented: bool) os.WriteError!usize {
if (simulate_evented) {
var req_node = Request.Node{ var req_node = Request.Node{
.data = .{ .data = .{
.msg = .{ .msg = .{
@ -1006,6 +1007,17 @@ pub const Loop = struct {
self.posixFsRequest(&req_node); self.posixFsRequest(&req_node);
} }
return req_node.data.msg.writev.result; return req_node.data.msg.writev.result;
} else {
while (true) {
return os.writev(fd, iov) catch |err| switch (err) {
error.WouldBlock => {
self.waitUntilFdWritable(fd);
continue;
},
else => return err,
};
}
}
} }
/// Performs an async `os.pwritev` using a separate thread. /// Performs an async `os.pwritev` using a separate thread.

View File

@ -586,10 +586,12 @@ pub const File = struct {
if (iovecs.len == 0) return @as(usize, 0); if (iovecs.len == 0) return @as(usize, 0);
const first = iovecs[0]; const first = iovecs[0];
return windows.WriteFile(self.handle, first.iov_base[0..first.iov_len], null, self.intended_io_mode); return windows.WriteFile(self.handle, first.iov_base[0..first.iov_len], null, self.intended_io_mode);
} else if (self.capable_io_mode != self.intended_io_mode) { }
return std.event.Loop.instance.?.writev(self.handle, iovecs);
} else { if (self.intended_io_mode == .blocking) {
return os.writev(self.handle, iovecs); return os.writev(self.handle, iovecs);
} else {
return std.event.Loop.instance.?.writev(self.handle, iovecs, self.capable_io_mode != self.intended_io_mode);
} }
} }

View File

@ -789,12 +789,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
EINTR => continue, EINTR => continue,
EINVAL => unreachable, EINVAL => unreachable,
EFAULT => unreachable, EFAULT => unreachable,
EAGAIN => if (std.event.Loop.instance) |loop| { EAGAIN => return error.WouldBlock,
loop.waitUntilFdWritable(fd);
continue;
} else {
return error.WouldBlock;
},
EBADF => return error.NotOpenForWriting, // Can be a race condition. EBADF => return error.NotOpenForWriting, // Can be a race condition.
EDESTADDRREQ => unreachable, // `connect` was never called. EDESTADDRREQ => unreachable, // `connect` was never called.
EDQUOT => return error.DiskQuota, EDQUOT => return error.DiskQuota,