nix icon indicating copy to clipboard operation
nix copied to clipboard

Consider making ControlMessageOwned::decode_from public

Open redbaron opened this issue 8 months ago • 0 comments
trafficstars

My IO layer is built around io_uring, where multishot results gives access to control messages buffer as raw bytes and it is up to the app to parse it.

I could get by with libc to iterate over headers:

        let hdr: RecvMsgOut = io_uring::types::RecvMsgOut::parse(buf)?;

        // Fake msghdr to iterate over control messages
        let mut mhdr = new_msghdr();
        mhdr.msg_controllen = hdr.control_data().len() as _;
        mhdr.msg_control = hdr.control_data().as_ptr() as _;

        // SAFETY: msghdr.msg_controllen and msghdr.msg_control are valid
        unsafe {
            let mut cmsghdr = libc::CMSG_FIRSTHDR(std::ptr::addr_of!(mhdr));
            while !cmsghdr.is_null() {
                let cmsg = &*cmsghdr;
                // ControlMessageOwned::decode_from();
                cmsghdr = libc::CMSG_NXTHDR(&mhdr as *const _, cmsghdr);
            }
        }

but interpreting each header remains fairly low level. This crate contains most complete ergonomic handler for each individual control message type I could find, but it doesn't expose it publically. Maybe you could change ControlMessageOwned::decode_from to pub?

redbaron avatar Mar 04 '25 16:03 redbaron