| ... | ... | @@ -1020,9 +1020,43 @@ pub const Loop = struct { |
| 1020 | 1020 | } |
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | /// Performs an async `os.pwrite` using a separate thread. |
| 1024 | /// `fd` must block and not return EAGAIN. |
| 1025 | pub fn pwrite(self: *Loop, fd: os.fd_t, bytes: []const u8, offset: u64, simulate_evented: bool) os.PWriteError!usize { |
| 1026 | if (simulate_evented) { |
| 1027 | var req_node = Request.Node{ |
| 1028 | .data = .{ |
| 1029 | .msg = .{ |
| 1030 | .pwrite = .{ |
| 1031 | .fd = fd, |
| 1032 | .bytes = bytes, |
| 1033 | .offset = offset, |
| 1034 | .result = undefined, |
| 1035 | }, |
| 1036 | }, |
| 1037 | .finish = .{ .TickNode = .{ .data = @frame() } }, |
| 1038 | }, |
| 1039 | }; |
| 1040 | suspend { |
| 1041 | self.posixFsRequest(&req_node); |
| 1042 | } |
| 1043 | return req_node.data.msg.pwrite.result; |
| 1044 | } else { |
| 1045 | while (true) { |
| 1046 | return os.pwrite(fd, bytes, offset) catch |err| switch (err) { |
| 1047 | error.WouldBlock => { |
| 1048 | self.waitUntilFdWritable(fd); |
| 1049 | continue; |
| 1050 | }, |
| 1051 | else => return err, |
| 1052 | }; |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1023 | 1057 | /// Performs an async `os.pwritev` using a separate thread. |
| 1024 | 1058 | /// `fd` must block and not return EAGAIN. |
| 1025 | | pub fn pwritev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const, offset: u64) os.WriteError!usize { |
| 1059 | pub fn pwritev(self: *Loop, fd: os.fd_t, iov: []const os.iovec_const, offset: u64) os.PWriteError!usize { |
| 1026 | 1060 | var req_node = Request.Node{ |
| 1027 | 1061 | .data = .{ |
| 1028 | 1062 | .msg = .{ |
| ... | ... | @@ -1194,6 +1228,9 @@ pub const Loop = struct { |
| 1194 | 1228 | .writev => |*msg| { |
| 1195 | 1229 | msg.result = os.writev(msg.fd, msg.iov); |
| 1196 | 1230 | }, |
| 1231 | .pwrite => |*msg| { |
| 1232 | msg.result = os.pwrite(msg.fd, msg.bytes, msg.offset); |
| 1233 | }, |
| 1197 | 1234 | .pwritev => |*msg| { |
| 1198 | 1235 | msg.result = os.pwritev(msg.fd, msg.iov, msg.offset); |
| 1199 | 1236 | }, |
| ... | ... | @@ -1263,6 +1300,7 @@ pub const Loop = struct { |
| 1263 | 1300 | readv: ReadV, |
| 1264 | 1301 | write: Write, |
| 1265 | 1302 | writev: WriteV, |
| 1303 | pwrite: PWrite, |
| 1266 | 1304 | pwritev: PWriteV, |
| 1267 | 1305 | pread: PRead, |
| 1268 | 1306 | preadv: PReadV, |
| ... | ... | @@ -1306,6 +1344,15 @@ pub const Loop = struct { |
| 1306 | 1344 | pub const Error = os.WriteError; |
| 1307 | 1345 | }; |
| 1308 | 1346 | |
| 1347 | pub const PWrite = struct { |
| 1348 | fd: os.fd_t, |
| 1349 | bytes: []const u8, |
| 1350 | offset: usize, |
| 1351 | result: Error!usize, |
| 1352 | |
| 1353 | pub const Error = os.PWriteError; |
| 1354 | }; |
| 1355 | |
| 1309 | 1356 | pub const PWriteV = struct { |
| 1310 | 1357 | fd: os.fd_t, |
| 1311 | 1358 | iov: []const os.iovec_const, |