I’m working on a project which needs libwayland bindings, and I’m trying to figure out the most idiomatic way to poll the Wayland display socket for events. I’m honestly completely lost. I don’t want to use the POSIX API because that’s planned for removal, so that removes the option to just mirror the poll-based example code from the Wayland docs. I also can’t find anything in std.Io which seems appropriate to check if a Unix socket has any readable data without actually reading it (libwayland leaves polling to the user, but it encapsulates all the actual reading). I’m not all too familiar with anything that I’m working with right now, so gentle help would be appreciated; I’m pretty confident that I’m missing something obvious.
P.S. Apologies for not providing a lot of detail, it’s late where I’m at and I’m awfully tired; I’ll add some more info in the morning.
std.Io does not provide a readiness API, not all platforms support them, and a readiness wrapper around a completion based (blocking) API is a lot harder compared to a completion based wrapper around a readiness API.
Perhaps that might change in the future, but I (personally) doubt it.
It sounds like what you want is concurrency, or at least asynchrony, between reading the socket and your other code. This fits nicely with io.async/io.concurrent.
I think a good solution would be creating a task that reads events and pushes them over a std.Io.Queue, which you can get from at your leisure.
I’m not entirely sure if Wayland’s API will cooperate with wl_display_read_events being called without any data on the socket, but I suppose there’s no other way to find out besides trying! Thanks for the advice.