Sha256: 1b682b13c3fd2601fa7dd10a909467a8d9ffebed04f8f6c8bcd7ea8a89769c8c

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

//! Windows system calls in the `event` module.

use crate::backend::c;
use crate::backend::conv::ret_c_int;
use crate::event::{FdSetElement, PollFd};
use crate::io;

pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usize> {
    let nfds = fds
        .len()
        .try_into()
        .map_err(|_convert_err| io::Errno::INVAL)?;

    ret_c_int(unsafe { c::poll(fds.as_mut_ptr().cast(), nfds, timeout) })
        .map(|nready| nready as usize)
}

pub(crate) fn select(
    nfds: i32,
    readfds: Option<&mut [FdSetElement]>,
    writefds: Option<&mut [FdSetElement]>,
    exceptfds: Option<&mut [FdSetElement]>,
    timeout: Option<&crate::timespec::Timespec>,
) -> io::Result<i32> {
    use core::ptr::{null, null_mut};

    let readfds = match readfds {
        Some(readfds) => {
            assert!(readfds.len() >= readfds[0].0 as usize);
            readfds.as_mut_ptr()
        }
        None => null_mut(),
    };
    let writefds = match writefds {
        Some(writefds) => {
            assert!(writefds.len() >= writefds[0].0 as usize);
            writefds.as_mut_ptr()
        }
        None => null_mut(),
    };
    let exceptfds = match exceptfds {
        Some(exceptfds) => {
            assert!(exceptfds.len() >= exceptfds[0].0 as usize);
            exceptfds.as_mut_ptr()
        }
        None => null_mut(),
    };

    let timeout_data;
    let timeout_ptr = match timeout {
        Some(timeout) => {
            // Convert from `Timespec` to `TIMEVAL`.
            timeout_data = c::TIMEVAL {
                tv_sec: timeout
                    .tv_sec
                    .try_into()
                    .map_err(|_| io::Errno::OPNOTSUPP)?,
                tv_usec: ((timeout.tv_nsec + 999) / 1000) as _,
            };
            &timeout_data
        }
        None => null(),
    };

    unsafe {
        ret_c_int(c::select(
            nfds,
            readfds.cast(),
            writefds.cast(),
            exceptfds.cast(),
            timeout_ptr,
        ))
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/rustix-0.38.44/src/backend/libc/event/windows_syscalls.rs
wasmtime-28.0.0 ./ext/cargo-vendor/rustix-0.38.43/src/backend/libc/event/windows_syscalls.rs
wasmtime-27.0.0 ./ext/cargo-vendor/rustix-0.38.41/src/backend/libc/event/windows_syscalls.rs