jay-compositor 1.15.0

The Jay compositor
use crate::utils::pipe::pipe;
use jay_algorithms::oserror::OsError;
use jay_algorithms::oserror::OsErrorExt;
use std::rc::Rc;
use std::slice;
use uapi::OwnedFd;
use uapi::c;

pub struct FdBlocker(#[expect(unused)] pub Rc<OwnedFd>);

pub struct FdBarrier(Rc<OwnedFd>);

pub fn create_fd_blocker() -> Result<(FdBlocker, FdBarrier), OsError> {
    let pipe = pipe()?;
    let blocker = FdBlocker(Rc::new(pipe.read));
    let barrier = FdBarrier(Rc::new(pipe.write));
    Ok((blocker, barrier))
}

impl FdBarrier {
    pub fn wait_blocking(&self) -> Result<(), OsError> {
        loop {
            let mut pollfd = c::pollfd {
                fd: self.0.raw(),
                events: 0,
                revents: 0,
            };
            let res = uapi::poll(slice::from_mut(&mut pollfd), -1).to_os_error();
            if let Err(e) = res {
                if e.0 == c::EINTR {
                    continue;
                }
                return Err(e);
            }
            if pollfd.revents & (c::POLLHUP | c::POLLERR) != 0 {
                return Ok(());
            }
        }
    }
}