| ... | @@ -478,7 +478,7 @@ pub const IO_Uring = struct { | ... | @@ -478,7 +478,7 @@ pub const IO_Uring = struct { |
| 478 | self: *IO_Uring, | 478 | self: *IO_Uring, |
| 479 | user_data: u64, | 479 | user_data: u64, |
| 480 | fd: os.fd_t, | 480 | fd: os.fd_t, |
| 481 | buffer: []u8, | 481 | buffer: []const u8, |
| 482 | flags: u32 | 482 | flags: u32 |
| 483 | ) !*io_uring_sqe { | 483 | ) !*io_uring_sqe { |
| 484 | const sqe = try self.get_sqe(); | 484 | const sqe = try self.get_sqe(); |
| ... | @@ -852,7 +852,7 @@ test "nop" { | ... | @@ -852,7 +852,7 @@ test "nop" { |
| 852 | testing.expectEqual(@as(os.fd_t, -1), ring.fd); | 852 | testing.expectEqual(@as(os.fd_t, -1), ring.fd); |
| 853 | } | 853 | } |
| 854 | | 854 | |
| 855 | var sqe = try ring.nop(0xaaaaaaaa); | 855 | const sqe = try ring.nop(0xaaaaaaaa); |
| 856 | testing.expectEqual(io_uring_sqe { | 856 | testing.expectEqual(io_uring_sqe { |
| 857 | .opcode = .NOP, | 857 | .opcode = .NOP, |
| 858 | .flags = 0, | 858 | .flags = 0, |
| ... | @@ -891,7 +891,7 @@ test "nop" { | ... | @@ -891,7 +891,7 @@ test "nop" { |
| 891 | testing.expectEqual(@as(u32, 1), ring.cq.head.*); | 891 | testing.expectEqual(@as(u32, 1), ring.cq.head.*); |
| 892 | testing.expectEqual(@as(u32, 0), ring.cq_ready()); | 892 | testing.expectEqual(@as(u32, 0), ring.cq_ready()); |
| 893 | | 893 | |
| 894 | var sqe_barrier = try ring.nop(0xbbbbbbbb); | 894 | const sqe_barrier = try ring.nop(0xbbbbbbbb); |
| 895 | sqe_barrier.flags |= linux.IOSQE_IO_DRAIN; | 895 | sqe_barrier.flags |= linux.IOSQE_IO_DRAIN; |
| 896 | testing.expectEqual(@as(u32, 1), try ring.submit()); | 896 | testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 897 | testing.expectEqual(io_uring_cqe { | 897 | testing.expectEqual(io_uring_cqe { |
| ... | @@ -931,7 +931,7 @@ test "readv" { | ... | @@ -931,7 +931,7 @@ test "readv" { |
| 931 | | 931 | |
| 932 | var buffer = [_]u8{42} ** 128; | 932 | var buffer = [_]u8{42} ** 128; |
| 933 | var iovecs = [_]os.iovec{ os.iovec { .iov_base = &buffer, .iov_len = buffer.len } }; | 933 | var iovecs = [_]os.iovec{ os.iovec { .iov_base = &buffer, .iov_len = buffer.len } }; |
| 934 | var sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0); | 934 | const sqe = try ring.readv(0xcccccccc, fd_index, iovecs[0..], 0); |
| 935 | testing.expectEqual(linux.IORING_OP.READV, sqe.opcode); | 935 | testing.expectEqual(linux.IORING_OP.READV, sqe.opcode); |
| 936 | sqe.flags |= linux.IOSQE_FIXED_FILE; | 936 | sqe.flags |= linux.IOSQE_FIXED_FILE; |
| 937 | | 937 | |
| ... | @@ -963,8 +963,8 @@ test "writev/fsync/readv" { | ... | @@ -963,8 +963,8 @@ test "writev/fsync/readv" { |
| 963 | defer std.fs.cwd().deleteFile(path) catch {}; | 963 | defer std.fs.cwd().deleteFile(path) catch {}; |
| 964 | const fd = file.handle; | 964 | const fd = file.handle; |
| 965 | | 965 | |
| 966 | var buffer_write = [_]u8{42} ** 128; | 966 | const buffer_write = [_]u8{42} ** 128; |
| 967 | var iovecs_write = [_]os.iovec_const { | 967 | const iovecs_write = [_]os.iovec_const { |
| 968 | os.iovec_const { .iov_base = &buffer_write, .iov_len = buffer_write.len } | 968 | os.iovec_const { .iov_base = &buffer_write, .iov_len = buffer_write.len } |
| 969 | }; | 969 | }; |
| 970 | var buffer_read = [_]u8{0} ** 128; | 970 | var buffer_read = [_]u8{0} ** 128; |
| ... | @@ -972,17 +972,17 @@ test "writev/fsync/readv" { | ... | @@ -972,17 +972,17 @@ test "writev/fsync/readv" { |
| 972 | os.iovec { .iov_base = &buffer_read, .iov_len = buffer_read.len } | 972 | os.iovec { .iov_base = &buffer_read, .iov_len = buffer_read.len } |
| 973 | }; | 973 | }; |
| 974 | | 974 | |
| 975 | var sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17); | 975 | const sqe_writev = try ring.writev(0xdddddddd, fd, iovecs_write[0..], 17); |
| 976 | testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode); | 976 | testing.expectEqual(linux.IORING_OP.WRITEV, sqe_writev.opcode); |
| 977 | testing.expectEqual(@as(u64, 17), sqe_writev.off); | 977 | testing.expectEqual(@as(u64, 17), sqe_writev.off); |
| 978 | sqe_writev.flags |= linux.IOSQE_IO_LINK; | 978 | sqe_writev.flags |= linux.IOSQE_IO_LINK; |
| 979 | | 979 | |
| 980 | var sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0); | 980 | const sqe_fsync = try ring.fsync(0xeeeeeeee, fd, 0); |
| 981 | testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode); | 981 | testing.expectEqual(linux.IORING_OP.FSYNC, sqe_fsync.opcode); |
| 982 | testing.expectEqual(fd, sqe_fsync.fd); | 982 | testing.expectEqual(fd, sqe_fsync.fd); |
| 983 | sqe_fsync.flags |= linux.IOSQE_IO_LINK; | 983 | sqe_fsync.flags |= linux.IOSQE_IO_LINK; |
| 984 | | 984 | |
| 985 | var sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17); | 985 | const sqe_readv = try ring.readv(0xffffffff, fd, iovecs_read[0..], 17); |
| 986 | testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode); | 986 | testing.expectEqual(linux.IORING_OP.READV, sqe_readv.opcode); |
| 987 | testing.expectEqual(@as(u64, 17), sqe_readv.off); | 987 | testing.expectEqual(@as(u64, 17), sqe_readv.off); |
| 988 | | 988 | |
| ... | @@ -1031,19 +1031,19 @@ test "write/read" { | ... | @@ -1031,19 +1031,19 @@ test "write/read" { |
| 1031 | defer std.fs.cwd().deleteFile(path) catch {}; | 1031 | defer std.fs.cwd().deleteFile(path) catch {}; |
| 1032 | const fd = file.handle; | 1032 | const fd = file.handle; |
| 1033 | | 1033 | |
| 1034 | var buffer_write = [_]u8{97} ** 20; | 1034 | const buffer_write = [_]u8{97} ** 20; |
| 1035 | var buffer_read = [_]u8{98} ** 20; | 1035 | var buffer_read = [_]u8{98} ** 20; |
| 1036 | var sqe_write = try ring.write(123, fd, buffer_write[0..], 10); | 1036 | const sqe_write = try ring.write(123, fd, buffer_write[0..], 10); |
| 1037 | testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); | 1037 | testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); |
| 1038 | testing.expectEqual(@as(u64, 10), sqe_write.off); | 1038 | testing.expectEqual(@as(u64, 10), sqe_write.off); |
| 1039 | sqe_write.flags |= linux.IOSQE_IO_LINK; | 1039 | sqe_write.flags |= linux.IOSQE_IO_LINK; |
| 1040 | var sqe_read = try ring.read(456, fd, buffer_read[0..], 10); | 1040 | const sqe_read = try ring.read(456, fd, buffer_read[0..], 10); |
| 1041 | testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode); | 1041 | testing.expectEqual(linux.IORING_OP.READ, sqe_read.opcode); |
| 1042 | testing.expectEqual(@as(u64, 10), sqe_read.off); | 1042 | testing.expectEqual(@as(u64, 10), sqe_read.off); |
| 1043 | testing.expectEqual(@as(u32, 2), try ring.submit()); | 1043 | testing.expectEqual(@as(u32, 2), try ring.submit()); |
| 1044 | | 1044 | |
| 1045 | var cqe_write = try ring.copy_cqe(); | 1045 | const cqe_write = try ring.copy_cqe(); |
| 1046 | var cqe_read = try ring.copy_cqe(); | 1046 | const cqe_read = try ring.copy_cqe(); |
| 1047 | // Prior to Linux Kernel 5.6 this is the only way to test for read/write support: | 1047 | // Prior to Linux Kernel 5.6 this is the only way to test for read/write support: |
| 1048 | // https://lwn.net/Articles/809820/ | 1048 | // https://lwn.net/Articles/809820/ |
| 1049 | if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest; | 1049 | if (cqe_write.res == -linux.EINVAL) return error.SkipZigTest; |
| ... | @@ -1076,7 +1076,7 @@ test "openat/close" { | ... | @@ -1076,7 +1076,7 @@ test "openat/close" { |
| 1076 | | 1076 | |
| 1077 | const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT; | 1077 | const flags: u32 = os.O_CLOEXEC | os.O_RDWR | os.O_CREAT; |
| 1078 | const mode: os.mode_t = 0o666; | 1078 | const mode: os.mode_t = 0o666; |
| 1079 | var sqe_openat = try ring.openat(789, linux.AT_FDCWD, path, flags, mode); | 1079 | const sqe_openat = try ring.openat(789, linux.AT_FDCWD, path, flags, mode); |
| 1080 | testing.expectEqual(io_uring_sqe { | 1080 | testing.expectEqual(io_uring_sqe { |
| 1081 | .opcode = .OPENAT, | 1081 | .opcode = .OPENAT, |
| 1082 | .flags = 0, | 1082 | .flags = 0, |
| ... | @@ -1094,7 +1094,7 @@ test "openat/close" { | ... | @@ -1094,7 +1094,7 @@ test "openat/close" { |
| 1094 | }, sqe_openat.*); | 1094 | }, sqe_openat.*); |
| 1095 | testing.expectEqual(@as(u32, 1), try ring.submit()); | 1095 | testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1096 | | 1096 | |
| 1097 | var cqe_openat = try ring.copy_cqe(); | 1097 | const cqe_openat = try ring.copy_cqe(); |
| 1098 | testing.expectEqual(@as(u64, 789), cqe_openat.user_data); | 1098 | testing.expectEqual(@as(u64, 789), cqe_openat.user_data); |
| 1099 | if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest; | 1099 | if (cqe_openat.res == -linux.EINVAL) return error.SkipZigTest; |
| 1100 | // AT_FDCWD is not fully supported before kernel 5.6: | 1100 | // AT_FDCWD is not fully supported before kernel 5.6: |
| ... | @@ -1107,12 +1107,12 @@ test "openat/close" { | ... | @@ -1107,12 +1107,12 @@ test "openat/close" { |
| 1107 | testing.expect(cqe_openat.res > 0); | 1107 | testing.expect(cqe_openat.res > 0); |
| 1108 | testing.expectEqual(@as(u32, 0), cqe_openat.flags); | 1108 | testing.expectEqual(@as(u32, 0), cqe_openat.flags); |
| 1109 | | 1109 | |
| 1110 | var sqe_close = try ring.close(1011, cqe_openat.res); | 1110 | const sqe_close = try ring.close(1011, cqe_openat.res); |
| 1111 | testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode); | 1111 | testing.expectEqual(linux.IORING_OP.CLOSE, sqe_close.opcode); |
| 1112 | testing.expectEqual(cqe_openat.res, sqe_close.fd); | 1112 | testing.expectEqual(cqe_openat.res, sqe_close.fd); |
| 1113 | testing.expectEqual(@as(u32, 1), try ring.submit()); | 1113 | testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1114 | | 1114 | |
| 1115 | var cqe_close = try ring.copy_cqe(); | 1115 | const cqe_close = try ring.copy_cqe(); |
| 1116 | if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest; | 1116 | if (cqe_close.res == -linux.EINVAL) return error.SkipZigTest; |
| 1117 | testing.expectEqual(linux.io_uring_cqe { | 1117 | testing.expectEqual(linux.io_uring_cqe { |
| 1118 | .user_data = 1011, | 1118 | .user_data = 1011, |
| ... | @@ -1131,7 +1131,7 @@ test "accept/connect/send/recv" { | ... | @@ -1131,7 +1131,7 @@ test "accept/connect/send/recv" { |
| 1131 | }; | 1131 | }; |
| 1132 | defer ring.deinit(); | 1132 | defer ring.deinit(); |
| 1133 | | 1133 | |
| 1134 | var address = try net.Address.parseIp4("127.0.0.1", 3131); | 1134 | const address = try net.Address.parseIp4("127.0.0.1", 3131); |
| 1135 | const kernel_backlog = 1; | 1135 | const kernel_backlog = 1; |
| 1136 | const server = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0); | 1136 | const server = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0); |
| 1137 | defer os.close(server); | 1137 | defer os.close(server); |
| ... | @@ -1139,17 +1139,17 @@ test "accept/connect/send/recv" { | ... | @@ -1139,17 +1139,17 @@ test "accept/connect/send/recv" { |
| 1139 | try os.bind(server, &address.any, address.getOsSockLen()); | 1139 | try os.bind(server, &address.any, address.getOsSockLen()); |
| 1140 | try os.listen(server, kernel_backlog); | 1140 | try os.listen(server, kernel_backlog); |
| 1141 | | 1141 | |
| 1142 | var buffer_send = [_]u8{1,0,1,0,1,0,1,0,1,0}; | 1142 | const buffer_send = [_]u8{ 1,0,1,0,1,0,1,0,1,0 }; |
| 1143 | var buffer_recv = [_]u8{0,1,0,1,0}; | 1143 | var buffer_recv = [_]u8{ 0,1,0,1,0 }; |
| 1144 | | 1144 | |
| 1145 | var accept_addr: os.sockaddr = undefined; | 1145 | var accept_addr: os.sockaddr = undefined; |
| 1146 | var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr)); | 1146 | var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr)); |
| 1147 | var accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0); | 1147 | const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0); |
| 1148 | testing.expectEqual(@as(u32, 1), try ring.submit()); | 1148 | testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1149 | | 1149 | |
| 1150 | const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0); | 1150 | const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0); |
| 1151 | defer os.close(client); | 1151 | defer os.close(client); |
| 1152 | var connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen()); | 1152 | const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen()); |
| 1153 | testing.expectEqual(@as(u32, 1), try ring.submit()); | 1153 | testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1154 | | 1154 | |
| 1155 | var cqe_accept = try ring.copy_cqe(); | 1155 | var cqe_accept = try ring.copy_cqe(); |
| ... | @@ -1159,8 +1159,8 @@ test "accept/connect/send/recv" { | ... | @@ -1159,8 +1159,8 @@ test "accept/connect/send/recv" { |
| 1159 | | 1159 | |
| 1160 | // The accept/connect CQEs may arrive in any order, the connect CQE will sometimes come first: | 1160 | // The accept/connect CQEs may arrive in any order, the connect CQE will sometimes come first: |
| 1161 | if (cqe_accept.user_data == 0xcccccccc and cqe_connect.user_data == 0xaaaaaaaa) { | 1161 | if (cqe_accept.user_data == 0xcccccccc and cqe_connect.user_data == 0xaaaaaaaa) { |
| 1162 | var a = cqe_accept; | 1162 | const a = cqe_accept; |
| 1163 | var b = cqe_connect; | 1163 | const b = cqe_connect; |
| 1164 | cqe_accept = b; | 1164 | cqe_accept = b; |
| 1165 | cqe_connect = a; | 1165 | cqe_connect = a; |
| 1166 | } | 1166 | } |
| ... | @@ -1175,12 +1175,12 @@ test "accept/connect/send/recv" { | ... | @@ -1175,12 +1175,12 @@ test "accept/connect/send/recv" { |
| 1175 | .flags = 0, | 1175 | .flags = 0, |
| 1176 | }, cqe_connect); | 1176 | }, cqe_connect); |
| 1177 | | 1177 | |
| 1178 | var send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0); | 1178 | const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0); |
| 1179 | send.flags |= linux.IOSQE_IO_LINK; | 1179 | send.flags |= linux.IOSQE_IO_LINK; |
| 1180 | var recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0); | 1180 | const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0); |
| 1181 | testing.expectEqual(@as(u32, 2), try ring.submit()); | 1181 | testing.expectEqual(@as(u32, 2), try ring.submit()); |
| 1182 | | 1182 | |
| 1183 | var cqe_send = try ring.copy_cqe(); | 1183 | const cqe_send = try ring.copy_cqe(); |
| 1184 | if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest; | 1184 | if (cqe_send.res == -linux.EINVAL) return error.SkipZigTest; |
| 1185 | testing.expectEqual(linux.io_uring_cqe { | 1185 | testing.expectEqual(linux.io_uring_cqe { |
| 1186 | .user_data = 0xeeeeeeee, | 1186 | .user_data = 0xeeeeeeee, |
| ... | @@ -1188,7 +1188,7 @@ test "accept/connect/send/recv" { | ... | @@ -1188,7 +1188,7 @@ test "accept/connect/send/recv" { |
| 1188 | .flags = 0, | 1188 | .flags = 0, |
| 1189 | }, cqe_send); | 1189 | }, cqe_send); |
| 1190 | | 1190 | |
| 1191 | var cqe_recv = try ring.copy_cqe(); | 1191 | const cqe_recv = try ring.copy_cqe(); |
| 1192 | if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest; | 1192 | if (cqe_recv.res == -linux.EINVAL) return error.SkipZigTest; |
| 1193 | testing.expectEqual(linux.io_uring_cqe { | 1193 | testing.expectEqual(linux.io_uring_cqe { |
| 1194 | .user_data = 0xffffffff, | 1194 | .user_data = 0xffffffff, |