dope-kqueue 0.2.3

Thin io_uring adaptor with "Manifolds"
Documentation
use std::io;
use std::os::fd::RawFd;

pub(crate) struct Sock;

impl Sock {
    pub(crate) fn set_nonblocking(fd: RawFd) {
        let flags = unsafe { libc::fcntl(fd, libc::F_GETFL, 0) };
        if flags >= 0 && (flags & libc::O_NONBLOCK) == 0 {
            unsafe {
                libc::fcntl(fd, libc::F_SETFL, flags | libc::O_NONBLOCK);
            }
        }
    }

    pub(crate) fn check_so_error(fd: RawFd) -> io::Result<()> {
        let mut err: libc::c_int = 0;
        let mut len = std::mem::size_of::<libc::c_int>() as libc::socklen_t;
        let rc = unsafe {
            libc::getsockopt(
                fd,
                libc::SOL_SOCKET,
                libc::SO_ERROR,
                (&mut err) as *mut libc::c_int as *mut libc::c_void,
                &mut len,
            )
        };
        if rc < 0 {
            return Err(io::Error::last_os_error());
        }
        if err != 0 {
            Err(io::Error::from_raw_os_error(err))
        } else {
            Ok(())
        }
    }
}