Polling in new I/O interface

Hello! I am looking into integrating some external C libraries into Zig I/O. Specifically, libsystemd systemd/sd-bus.h, which is a D-Bus library.

(Before anyone asks or suggests, I am not looking for alternative D-Bus implementations in Zig for practical reasons)

The relevant function is: sd_bus_get_fd, sd_bus_get_events, sd_bus_get_timeout. The library gives the event loop an fd to watch for, POLL events to watch for, and timeout.

I would like to do poll(), or something like io_uring_prep_poll_add

I see Io.operate merged recently and the Io.poll issue is closed, but seems like there is no equivalent to poll/epoll/readiness API. I see there is only completioness API, e.g Io.Operation. Is it going to be something added to the std later?

If this is not something Zig not going to support, is one supposed to give up on using Zig I/O for doing those I/O poll operations, or is std.Io: introduce API for calling uncooperative functions is intended for this? Like, just spawn and do all the low level platform specific stuff, either poll or just pure io_uring there.

Thanks!

1 Like

The Io implementation deals with those details internally, and provides a higher-level uniform API.

But it does support select and batch operations, which on Io.Threaded are lowered to polling: https://codeberg.org/ziglang/zig/pulls/30743

And Io.Evented (currently not useable) will use io_uring/kqueue/windows equivalent.

I don’t think Io can expose a readiness based API (?)
Not all platforms support it, and it’s easy to adapt a readiness API into a completion API, but the reverse is far from easy/not possible.

1 Like