Cloudef / zig-aio

io_uring like asynchronous API and coroutine powered IO tasks for zig
https://cloudef.github.io/zig-aio/
MIT License
175 stars 6 forks source link

aio: add aio.Poll #14

Closed Nyaa97 closed 3 weeks ago

Nyaa97 commented 1 month ago

Add of the poll op described at https://unixism.net/loti/ref-iouring/io_uring_enter.html

Nyaa97 commented 1 month ago

Poll events should be bit map But I don't see myself using a single Pool for several events

pub const Poll = struct {
    pub const Events = packed struct(u32) {
        in: bool = false,
        out: bool = false,
        pri: bool = false,
        _: u29 = 0,
    };

    pub const Error = std.posix.PollError || SharedError;
    fd: std.posix.fd_t,
    events: Events = .{ .in = true },
    out_id: ?*Id = null,
    out_error: ?*Error = null,
    link: Link = .unlinked,
    userdata: usize = 0,
};

aio.Single(aio.Poll{ .fd = fd, .events = .{ .out = true } });

In addition, I don't like the implementation of Readiness.mode which makes it difficult to simply check mode

pub const Readiness = struct {
    fd: std.posix.fd_t = invalid_fd,
    mode: packed struct(i16) {
        in: bool = false,
        out: bool = false,
        pri: bool = false,
        kludge: bool = false,
        _: u12 = 0,
    },
};

I made a draft I am not sure how it should be 🤔

Cloudef commented 1 month ago

The readiness originally was not meant to implement poll. Your changes make sense. The kludge field probably can live outside of the packed struct as bool, as it is not a poll thing. Then I guess Events could be intCast'd to mode.

I'd also be grateful if you can add more tests.

Nyaa97 commented 3 weeks ago

Poll struct must not panic (comptime), or else building on Windows will be impossible

Cloudef commented 3 weeks ago

Thank you