io-uring icon indicating copy to clipboard operation
io-uring copied to clipboard

feat: add support for ReadMulti opcode (6.7+)

Open kp-omer-shamash opened this issue 10 months ago • 3 comments

Simple addition, already have the CODE in the /sys/

kp-omer-shamash avatar Feb 23 '25 11:02 kp-omer-shamash

Right now I'm doing what feels like a crime against humanity by implementing like this and having tons of structures copy-pasta'd from the /sys/ part of the crate, would really appreciate if we can merge so I don't use this abomination :

pub struct ReadMulti {
    fd: i32,
    buf_group: u16,
    flags: i32,
}

impl ReadMulti {
    #[inline]
    pub fn new(fd: i32, buf_group: u16) -> Self {
        ReadMulti {
            fd,
            buf_group,
            flags: 0,
        }
    }

    #[inline]
    pub fn build(self) -> Entry {
        let sqe = CustomSQE {
            opcode: IORING_OP_READ_MULTISHOT as _,
            flags: io_uring::squeue::Flags::BUFFER_SELECT.bits(),
            fd: self.fd,
            buf_index: PackedU16 {
                buf_index: self.buf_group,
            },
            msg_flags: Union3 {
                msg_flags: self.flags as _,
            },
            ..Default::default()
        };

        // Safety: CustomSQE has identical memory layout to io_uring_sqe
        #[allow(unsafe_code)]
        unsafe {
            std::mem::transmute(sqe)
        }
    }
}

kp-omer-shamash avatar Feb 23 '25 11:02 kp-omer-shamash

This looks good, would you like to add a test?

quininer avatar Feb 24 '25 02:02 quininer

@quininer done also, not sure what your release-plans are, but would appreciate if it's possible to bump to 0.7.5 soon after

kp-omer-shamash avatar Feb 25 '25 08:02 kp-omer-shamash