| ... | @@ -1020,9 +1020,43 @@ pub const Loop = struct { | ... | @@ -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 | /// Performs an async `os.pwritev` using a separate thread. | 1057 | /// Performs an async `os.pwritev` using a separate thread. |
| 1024 | /// `fd` must block and not return EAGAIN. | 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 | var req_node = Request.Node{ | 1060 | var req_node = Request.Node{ |
| 1027 | .data = .{ | 1061 | .data = .{ |
| 1028 | .msg = .{ | 1062 | .msg = .{ |
| ... | @@ -1194,6 +1228,9 @@ pub const Loop = struct { | ... | @@ -1194,6 +1228,9 @@ pub const Loop = struct { |
| 1194 | .writev => |*msg| { | 1228 | .writev => |*msg| { |
| 1195 | msg.result = os.writev(msg.fd, msg.iov); | 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 | .pwritev => |*msg| { | 1234 | .pwritev => |*msg| { |
| 1198 | msg.result = os.pwritev(msg.fd, msg.iov, msg.offset); | 1235 | msg.result = os.pwritev(msg.fd, msg.iov, msg.offset); |
| 1199 | }, | 1236 | }, |
| ... | @@ -1263,6 +1300,7 @@ pub const Loop = struct { | ... | @@ -1263,6 +1300,7 @@ pub const Loop = struct { |
| 1263 | readv: ReadV, | 1300 | readv: ReadV, |
| 1264 | write: Write, | 1301 | write: Write, |
| 1265 | writev: WriteV, | 1302 | writev: WriteV, |
| | 1303 | pwrite: PWrite, |
| 1266 | pwritev: PWriteV, | 1304 | pwritev: PWriteV, |
| 1267 | pread: PRead, | 1305 | pread: PRead, |
| 1268 | preadv: PReadV, | 1306 | preadv: PReadV, |
| ... | @@ -1306,6 +1344,15 @@ pub const Loop = struct { | ... | @@ -1306,6 +1344,15 @@ pub const Loop = struct { |
| 1306 | pub const Error = os.WriteError; | 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 | pub const PWriteV = struct { | 1356 | pub const PWriteV = struct { |
| 1310 | fd: os.fd_t, | 1357 | fd: os.fd_t, |
| 1311 | iov: []const os.iovec_const, | 1358 | iov: []const os.iovec_const, |