From 1d85cc184bad2206ad4b5f3d9beb5b20b95912ef Mon Sep 17 00:00:00 2001 From: Morgan Gallant Date: Sat, 9 Mar 2024 11:41:53 -0800 Subject: [PATCH 1/2] bump zig version after breaking std changes Signed-off-by: Morgan Gallant --- build.zig.zon | 1 + src/backend/epoll.zig | 10 ++--- src/backend/io_uring.zig | 84 ++++++++++++++-------------------------- src/backend/iocp.zig | 8 ++-- src/backend/kqueue.zig | 6 +-- src/linux/timerfd.zig | 10 ++--- 6 files changed, 47 insertions(+), 72 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 01ecaa4..0881bdb 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,6 @@ .{ .name = "libxev", + .minimum_zig_version = "0.12.0-dev.3191+9cf28d1e9", .paths = .{""}, .version = "0.0.0", } diff --git a/src/backend/epoll.zig b/src/backend/epoll.zig index 7516b4e..76d8adf 100644 --- a/src/backend/epoll.zig +++ b/src/backend/epoll.zig @@ -56,7 +56,7 @@ pub const Loop = struct { pub fn init(options: xev.Options) !Loop { var res: Loop = .{ - .fd = try std.os.epoll_create1(std.os.O.CLOEXEC), + .fd = try std.os.epoll_create1(std.posix.linux.EPOLL.CLOEXEC), .thread_pool = options.thread_pool, .thread_pool_completions = undefined, .cached_now = undefined, @@ -1540,9 +1540,9 @@ test "epoll: timerfd" { // We'll try with a simple timerfd const Timerfd = @import("../linux/timerfd.zig").Timerfd; - var t = try Timerfd.init(.monotonic, 0); + var t = try Timerfd.init(.monotonic, .{}); defer t.deinit(); - try t.set(0, &.{ .value = .{ .nanoseconds = 1 } }, null); + try t.set(.{}, &.{ .value = .{ .nanoseconds = 1 } }, null); // Add the timer var called = false; @@ -1591,7 +1591,7 @@ test "epoll: socket accept/connect/send/recv/close" { const address = try net.Address.parseIp4("127.0.0.1", 3131); const kernel_backlog = 1; var ln = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); - errdefer os.closeSocket(ln); + errdefer os.close(ln); try os.setsockopt(ln, os.SOL.SOCKET, os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try os.bind(ln, &address.any, address.getOsSockLen()); try os.listen(ln, kernel_backlog); @@ -1602,7 +1602,7 @@ test "epoll: socket accept/connect/send/recv/close" { os.SOCK.NONBLOCK | os.SOCK.STREAM | os.SOCK.CLOEXEC, 0, ); - errdefer os.closeSocket(client_conn); + errdefer os.close(client_conn); // Accept var server_conn: os.socket_t = 0; diff --git a/src/backend/io_uring.zig b/src/backend/io_uring.zig index 7fb63fd..308f64e 100644 --- a/src/backend/io_uring.zig +++ b/src/backend/io_uring.zig @@ -5,7 +5,7 @@ const queue = @import("../queue.zig"); const xev = @import("../main.zig").IO_Uring; pub const Loop = struct { - ring: linux.IO_Uring, + ring: linux.IoUring, /// The number of active completions. This DOES NOT include completions that /// are queued in the submissions queue. @@ -41,7 +41,7 @@ pub const Loop = struct { // TODO(mitchellh): add an init_advanced function or something // for people using the io_uring API directly to be able to set // the flags for this. - .ring = try linux.IO_Uring.init(entries, 0), + .ring = try linux.IoUring.init(entries, 0), }; result.update_now(); @@ -363,35 +363,25 @@ pub const Loop = struct { return; }, - .accept => |*v| linux.io_uring_prep_accept( - sqe, + .accept => |*v| sqe.prep_accept( v.socket, &v.addr, &v.addr_size, v.flags, ), - .close => |v| linux.io_uring_prep_close( - sqe, - v.fd, - ), + .close => |v| sqe.prep_close(v.fd), - .connect => |*v| linux.io_uring_prep_connect( - sqe, + .connect => |*v| sqe.prep_connect( v.socket, &v.addr.any, v.addr.getOsSockLen(), ), - .poll => |v| linux.io_uring_prep_poll_add( - sqe, - v.fd, - v.events, - ), + .poll => |v| sqe.prep_poll_add(v.fd, v.events), .read => |*v| switch (v.buffer) { - .array => |*buf| linux.io_uring_prep_read( - sqe, + .array => |*buf| sqe.prep_read( v.fd, buf, @@ -400,8 +390,7 @@ pub const Loop = struct { @bitCast(@as(i64, -1)), ), - .slice => |buf| linux.io_uring_prep_read( - sqe, + .slice => |buf| sqe.prep_read( v.fd, buf, @@ -412,15 +401,13 @@ pub const Loop = struct { }, .pread => |*v| switch (v.buffer) { - .array => |*buf| linux.io_uring_prep_read( - sqe, + .array => |*buf| sqe.prep_read( v.fd, buf, v.offset, ), - .slice => |buf| linux.io_uring_prep_read( - sqe, + .slice => |buf| sqe.prep_read( v.fd, buf, v.offset, @@ -428,15 +415,13 @@ pub const Loop = struct { }, .recv => |*v| switch (v.buffer) { - .array => |*buf| linux.io_uring_prep_recv( - sqe, + .array => |*buf| sqe.prep_recv( v.fd, buf, 0, ), - .slice => |buf| linux.io_uring_prep_recv( - sqe, + .slice => |buf| sqe.prep_recv( v.fd, buf, 0, @@ -444,8 +429,7 @@ pub const Loop = struct { }, .recvmsg => |*v| { - linux.io_uring_prep_recvmsg( - sqe, + sqe.prep_recvmsg( v.fd, v.msghdr, 0, @@ -453,15 +437,13 @@ pub const Loop = struct { }, .send => |*v| switch (v.buffer) { - .array => |*buf| linux.io_uring_prep_send( - sqe, + .array => |*buf| sqe.prep_send( v.fd, buf.array[0..buf.len], 0, ), - .slice => |buf| linux.io_uring_prep_send( - sqe, + .slice => |buf| sqe.prep_send( v.fd, buf, 0, @@ -473,16 +455,14 @@ pub const Loop = struct { @panic("TODO: sendmsg with buffer"); } - linux.io_uring_prep_sendmsg( - sqe, + sqe.prep_sendmsg( v.fd, v.msghdr, 0, ); }, - .shutdown => |v| linux.io_uring_prep_shutdown( - sqe, + .shutdown => |v| sqe.prep_shutdown( v.socket, switch (v.how) { .both => linux.SHUT.RDWR, @@ -491,22 +471,19 @@ pub const Loop = struct { }, ), - .timer => |*v| linux.io_uring_prep_timeout( - sqe, + .timer => |*v| sqe.prep_timeout( &v.next, 0, linux.IORING_TIMEOUT_ABS, ), - .timer_remove => |v| linux.io_uring_prep_timeout_remove( - sqe, + .timer_remove => |v| sqe.prep_timeout_remove( @intFromPtr(v.timer), 0, ), .write => |*v| switch (v.buffer) { - .array => |*buf| linux.io_uring_prep_write( - sqe, + .array => |*buf| sqe.prep_write( v.fd, buf.array[0..buf.len], @@ -515,8 +492,7 @@ pub const Loop = struct { @bitCast(@as(i64, -1)), ), - .slice => |buf| linux.io_uring_prep_write( - sqe, + .slice => |buf| sqe.prep_write( v.fd, buf, @@ -527,22 +503,20 @@ pub const Loop = struct { }, .pwrite => |*v| switch (v.buffer) { - .array => |*buf| linux.io_uring_prep_write( - sqe, + .array => |*buf| sqe.prep_write( v.fd, buf.array[0..buf.len], v.offset, ), - .slice => |buf| linux.io_uring_prep_write( - sqe, + .slice => |buf| sqe.prep_write( v.fd, buf, v.offset, ), }, - .cancel => |v| linux.io_uring_prep_cancel(sqe, @intCast(@intFromPtr(v.c)), 0), + .cancel => |v| sqe.prep_cancel(@intCast(@intFromPtr(v.c)), 0), } // Our sqe user data always points back to the completion. @@ -1164,9 +1138,9 @@ test "io_uring: timerfd" { // We'll try with a simple timerfd const Timerfd = @import("../linux/timerfd.zig").Timerfd; - var t = try Timerfd.init(.monotonic, 0); + var t = try Timerfd.init(.monotonic, .{}); defer t.deinit(); - try t.set(0, &.{ .value = .{ .nanoseconds = 1 } }, null); + try t.set(.{}, &.{ .value = .{ .nanoseconds = 1 } }, null); // Add the timer var called = false; @@ -1394,14 +1368,14 @@ test "io_uring: socket accept/connect/send/recv/close" { const address = try net.Address.parseIp4("127.0.0.1", 3131); const kernel_backlog = 1; var ln = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); - errdefer os.closeSocket(ln); + errdefer os.close(ln); try os.setsockopt(ln, os.SOL.SOCKET, os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try os.bind(ln, &address.any, address.getOsSockLen()); try os.listen(ln, kernel_backlog); // Create a TCP client socket var client_conn = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); - errdefer os.closeSocket(client_conn); + errdefer os.close(client_conn); // Accept var server_conn: os.socket_t = 0; @@ -1717,7 +1691,7 @@ test "io_uring: socket read cancellation" { // Create a UDP server socket const address = try net.Address.parseIp4("127.0.0.1", 3131); const socket = try os.socket(address.any.family, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0); - errdefer os.closeSocket(socket); + errdefer os.close(socket); try os.setsockopt(socket, os.SOL.SOCKET, os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try os.bind(socket, &address.any, address.getOsSockLen()); diff --git a/src/backend/iocp.zig b/src/backend/iocp.zig index 682ef24..508a7f2 100644 --- a/src/backend/iocp.zig +++ b/src/backend/iocp.zig @@ -1955,7 +1955,7 @@ test "iocp: socket accept/connect/send/recv/close" { const address = try net.Address.parseIp4("127.0.0.1", 3131); const kernel_backlog = 1; const ln = try windows.WSASocketW(std.os.AF.INET, std.os.SOCK.STREAM, std.os.IPPROTO.TCP, null, 0, windows.ws2_32.WSA_FLAG_OVERLAPPED); - errdefer std.os.closeSocket(ln); + errdefer std.os.close(ln); try std.os.setsockopt(ln, std.os.SOL.SOCKET, std.os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try std.os.bind(ln, &address.any, address.getOsSockLen()); @@ -1963,7 +1963,7 @@ test "iocp: socket accept/connect/send/recv/close" { // Create a TCP client socket const client_conn = try windows.WSASocketW(std.os.AF.INET, std.os.SOCK.STREAM, std.os.IPPROTO.TCP, null, 0, windows.ws2_32.WSA_FLAG_OVERLAPPED); - errdefer std.os.closeSocket(client_conn); + errdefer std.os.close(client_conn); var server_conn_result: Result = undefined; var c_accept: Completion = .{ @@ -2221,7 +2221,7 @@ test "iocp: recv cancellation" { // Create a TCP server socket const address = try net.Address.parseIp4("127.0.0.1", 3131); const socket = try windows.WSASocketW(std.os.AF.INET, std.os.SOCK.DGRAM, std.os.IPPROTO.UDP, null, 0, windows.ws2_32.WSA_FLAG_OVERLAPPED); - errdefer std.os.closeSocket(socket); + errdefer std.os.close(socket); try std.os.setsockopt(socket, std.os.SOL.SOCKET, std.os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try std.os.bind(socket, &address.any, address.getOsSockLen()); @@ -2294,7 +2294,7 @@ test "iocp: accept cancellation" { const address = try net.Address.parseIp4("127.0.0.1", 3131); const kernel_backlog = 1; const ln = try windows.WSASocketW(std.os.AF.INET, std.os.SOCK.STREAM, std.os.IPPROTO.TCP, null, 0, windows.ws2_32.WSA_FLAG_OVERLAPPED); - errdefer std.os.closeSocket(ln); + errdefer std.os.close(ln); try std.os.setsockopt(ln, std.os.SOL.SOCKET, std.os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try std.os.bind(ln, &address.any, address.getOsSockLen()); diff --git a/src/backend/kqueue.zig b/src/backend/kqueue.zig index 5bee2b5..cfe669a 100644 --- a/src/backend/kqueue.zig +++ b/src/backend/kqueue.zig @@ -2133,7 +2133,7 @@ test "kqueue: socket accept/connect/send/recv/close" { const address = try net.Address.parseIp4("127.0.0.1", 3131); const kernel_backlog = 1; var ln = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); - errdefer os.closeSocket(ln); + errdefer os.close(ln); try os.setsockopt(ln, os.SOL.SOCKET, os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try os.bind(ln, &address.any, address.getOsSockLen()); try os.listen(ln, kernel_backlog); @@ -2144,7 +2144,7 @@ test "kqueue: socket accept/connect/send/recv/close" { os.SOCK.NONBLOCK | os.SOCK.STREAM | os.SOCK.CLOEXEC, 0, ); - errdefer os.closeSocket(client_conn); + errdefer os.close(client_conn); // Accept var server_conn: os.socket_t = 0; @@ -2583,7 +2583,7 @@ test "kqueue: socket accept/cancel cancellation should decrease active count" { const address = try net.Address.parseIp4("127.0.0.1", 3131); const kernel_backlog = 1; var ln = try os.socket(address.any.family, os.SOCK.STREAM | os.SOCK.CLOEXEC, 0); - errdefer os.closeSocket(ln); + errdefer os.close(ln); try os.setsockopt(ln, os.SOL.SOCKET, os.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); try os.bind(ln, &address.any, address.getOsSockLen()); try os.listen(ln, kernel_backlog); diff --git a/src/linux/timerfd.zig b/src/linux/timerfd.zig index d5cf042..3df7a79 100644 --- a/src/linux/timerfd.zig +++ b/src/linux/timerfd.zig @@ -13,7 +13,7 @@ pub const Timerfd = struct { fd: i32, /// timerfd_create - pub fn init(clock: Clock, flags: u32) !Timerfd { + pub fn init(clock: Clock, flags: linux.TFD) !Timerfd { const res = linux.timerfd_create(@intFromEnum(clock), flags); return switch (linux.getErrno(res)) { .SUCCESS => .{ .fd = @as(i32, @intCast(res)) }, @@ -28,7 +28,7 @@ pub const Timerfd = struct { /// timerfd_settime pub fn set( self: *const Timerfd, - flags: u32, + flags: linux.TFD.TIMER, new_value: *const Spec, old_value: ?*Spec, ) !void { @@ -83,15 +83,15 @@ pub const Timerfd = struct { test Timerfd { const testing = std.testing; - var t = try Timerfd.init(.monotonic, 0); + var t = try Timerfd.init(.monotonic, .{}); defer t.deinit(); // Set - try t.set(0, &.{ .value = .{ .seconds = 60 } }, null); + try t.set(.{}, &.{ .value = .{ .seconds = 60 } }, null); try testing.expect((try t.get()).value.seconds > 0); // Disarm var old: Timerfd.Spec = undefined; - try t.set(0, &.{ .value = .{ .seconds = 0 } }, &old); + try t.set(.{}, &.{ .value = .{ .seconds = 0 } }, &old); try testing.expect(old.value.seconds > 0); } From 3796c6c397b88bb9efa758b7247464277d50ede8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 9 Mar 2024 15:54:07 -0800 Subject: [PATCH 2/2] update nix in flake --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index aab81d3..bd00f7d 100644 --- a/flake.lock +++ b/flake.lock @@ -126,11 +126,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1704500574, - "narHash": "sha256-Ockm1D5QsxdVZZoD0Yf5Kg4FupbVnk3X0RLkc6geRIE=", + "lastModified": 1710028389, + "narHash": "sha256-NjtsA9aTb9qgzmuuXJabVL0LeNw8ae3BXpF/+UCT2yc=", "owner": "mitchellh", "repo": "zig-overlay", - "rev": "e056aafd8db157ff7519518a026c5ba7040522cf", + "rev": "7e2da66bd83f27441d2a3244ebdc7d0b4d20c3c4", "type": "github" }, "original": {