Io.EventLoop: select stub

This commit is contained in:
Andrew Kelley 2025-04-03 18:07:46 -07:00
parent 4a3ef0f779
commit b4fb7df140

View file

@ -141,7 +141,7 @@ pub fn io(el: *EventLoop) Io {
.@"async" = @"async", .@"async" = @"async",
.@"await" = @"await", .@"await" = @"await",
.go = go, .go = go,
.select = select,
.cancel = cancel, .cancel = cancel,
.cancelRequested = cancelRequested, .cancelRequested = cancelRequested,
@ -728,6 +728,13 @@ fn @"async"(
return @ptrCast(fiber); return @ptrCast(fiber);
} }
fn select(userdata: ?*anyopaque, futures: []const *Io.AnyFuture) usize {
const el: *EventLoop = @alignCast(@ptrCast(userdata));
_ = el;
_ = futures;
@panic("TODO");
}
const DetachedClosure = struct { const DetachedClosure = struct {
event_loop: *EventLoop, event_loop: *EventLoop,
fiber: *Fiber, fiber: *Fiber,
@ -870,10 +877,10 @@ fn cancelRequested(userdata: ?*anyopaque) bool {
fn createFile( fn createFile(
userdata: ?*anyopaque, userdata: ?*anyopaque,
dir: std.fs.Dir, dir: Io.Dir,
sub_path: []const u8, sub_path: []const u8,
flags: Io.CreateFlags, flags: Io.File.CreateFlags,
) Io.FileOpenError!std.fs.File { ) Io.File.OpenError!Io.File {
const el: *EventLoop = @alignCast(@ptrCast(userdata)); const el: *EventLoop = @alignCast(@ptrCast(userdata));
const thread: *Thread = .current(); const thread: *Thread = .current();
const iou = &thread.io_uring; const iou = &thread.io_uring;
@ -921,7 +928,7 @@ fn createFile(
.opcode = .OPENAT, .opcode = .OPENAT,
.flags = 0, .flags = 0,
.ioprio = 0, .ioprio = 0,
.fd = dir.fd, .fd = dir.handle,
.off = 0, .off = 0,
.addr = @intFromPtr(&sub_path_c), .addr = @intFromPtr(&sub_path_c),
.len = @intCast(flags.mode), .len = @intCast(flags.mode),
@ -972,10 +979,10 @@ fn createFile(
fn openFile( fn openFile(
userdata: ?*anyopaque, userdata: ?*anyopaque,
dir: std.fs.Dir, dir: Io.Dir,
sub_path: []const u8, sub_path: []const u8,
flags: Io.OpenFlags, flags: Io.File.OpenFlags,
) Io.FileOpenError!std.fs.File { ) Io.File.OpenError!Io.File {
const el: *EventLoop = @alignCast(@ptrCast(userdata)); const el: *EventLoop = @alignCast(@ptrCast(userdata));
const thread: *Thread = .current(); const thread: *Thread = .current();
const iou = &thread.io_uring; const iou = &thread.io_uring;
@ -1029,7 +1036,7 @@ fn openFile(
.opcode = .OPENAT, .opcode = .OPENAT,
.flags = 0, .flags = 0,
.ioprio = 0, .ioprio = 0,
.fd = dir.fd, .fd = dir.handle,
.off = 0, .off = 0,
.addr = @intFromPtr(&sub_path_c), .addr = @intFromPtr(&sub_path_c),
.len = 0, .len = 0,
@ -1078,7 +1085,7 @@ fn openFile(
} }
} }
fn closeFile(userdata: ?*anyopaque, file: std.fs.File) void { fn closeFile(userdata: ?*anyopaque, file: Io.File) void {
const el: *EventLoop = @alignCast(@ptrCast(userdata)); const el: *EventLoop = @alignCast(@ptrCast(userdata));
const thread: *Thread = .current(); const thread: *Thread = .current();
const iou = &thread.io_uring; const iou = &thread.io_uring;
@ -1114,7 +1121,7 @@ fn closeFile(userdata: ?*anyopaque, file: std.fs.File) void {
} }
} }
fn pread(userdata: ?*anyopaque, file: std.fs.File, buffer: []u8, offset: std.posix.off_t) Io.FilePReadError!usize { fn pread(userdata: ?*anyopaque, file: Io.File, buffer: []u8, offset: std.posix.off_t) Io.File.PReadError!usize {
const el: *EventLoop = @alignCast(@ptrCast(userdata)); const el: *EventLoop = @alignCast(@ptrCast(userdata));
const thread: *Thread = .current(); const thread: *Thread = .current();
const iou = &thread.io_uring; const iou = &thread.io_uring;
@ -1166,7 +1173,7 @@ fn pread(userdata: ?*anyopaque, file: std.fs.File, buffer: []u8, offset: std.pos
} }
} }
fn pwrite(userdata: ?*anyopaque, file: std.fs.File, buffer: []const u8, offset: std.posix.off_t) Io.FilePWriteError!usize { fn pwrite(userdata: ?*anyopaque, file: Io.File, buffer: []const u8, offset: std.posix.off_t) Io.File.PWriteError!usize {
const el: *EventLoop = @alignCast(@ptrCast(userdata)); const el: *EventLoop = @alignCast(@ptrCast(userdata));
const thread: *Thread = .current(); const thread: *Thread = .current();
const iou = &thread.io_uring; const iou = &thread.io_uring;
@ -1236,7 +1243,7 @@ fn sleep(userdata: ?*anyopaque, clockid: std.posix.clockid_t, deadline: Io.Deadl
try fiber.enterCancelRegion(thread); try fiber.enterCancelRegion(thread);
const deadline_nanoseconds: i96 = switch (deadline) { const deadline_nanoseconds: i96 = switch (deadline) {
.nanoseconds => |nanoseconds| nanoseconds, .duration => |duration| duration.nanoseconds,
.timestamp => |timestamp| @intFromEnum(timestamp), .timestamp => |timestamp| @intFromEnum(timestamp),
}; };
const timespec: std.os.linux.kernel_timespec = .{ const timespec: std.os.linux.kernel_timespec = .{
@ -1252,7 +1259,7 @@ fn sleep(userdata: ?*anyopaque, clockid: std.posix.clockid_t, deadline: Io.Deadl
.addr = @intFromPtr(&timespec), .addr = @intFromPtr(&timespec),
.len = 1, .len = 1,
.rw_flags = @as(u32, switch (deadline) { .rw_flags = @as(u32, switch (deadline) {
.nanoseconds => 0, .duration => 0,
.timestamp => std.os.linux.IORING_TIMEOUT_ABS, .timestamp => std.os.linux.IORING_TIMEOUT_ABS,
}) | @as(u32, switch (clockid) { }) | @as(u32, switch (clockid) {
.REALTIME => std.os.linux.IORING_TIMEOUT_REALTIME, .REALTIME => std.os.linux.IORING_TIMEOUT_REALTIME,