dope-uring 0.76.0

Owned io_uring backend for dope
Documentation
use std::os::fd;

use dope_sys::engine::register;

use crate::reactor::{op, ring, sq};

pub(crate) const POLL: op::Code = op::Code::new(ring::ffi::POLL_ADD);
pub(crate) const CANCEL: op::Code = op::Code::new(ring::ffi::ASYNC_CANCEL);

pub(crate) fn poll(source: register::Source<'_>, multi: bool) -> sq::Borrowed<'_> {
    const ROTATE: u32 = if u16::from_ne_bytes([1, 0]) == 1 {
        0
    } else {
        16
    };

    let raw = fd::AsRawFd::as_raw_fd(&source.fd);
    let mut entry = sq::Entry::new(POLL, sq::Descriptor::File(raw));
    let fields = entry.fields();
    if multi {
        fields.command.length = 1;
    }
    let interest = match source.interest {
        register::Interest::Readable => libc::POLLIN,
        register::Interest::Closed => libc::POLLRDHUP,
    };
    fields.command.options = u32::from(interest.unsigned_abs()).rotate_left(ROTATE);
    sq::Borrowed::new(entry)
}