Skip to content

Commit

Permalink
Drop Windows support.
Browse files Browse the repository at this point in the history
Windows has a different `FD_SET` representation. Supporting it might be
possible, though the documentation is ambiguous about whether it supports
arbitrary `FD_SETSIZE` values. But even if so, it would require a more
elaborate abstraction, so just drop it for now.
  • Loading branch information
sunfishcode committed Sep 16, 2024
1 parent be71be7 commit 680ec5e
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/backend/libc/event/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub(crate) unsafe fn select(
Some(timeout) => {
// Convert from `Timespec` to `c::timeval`.
timeout_data = c::timeval {
tv_sec: timeout.tv_sec.try_into().map_err(|_| io::Errno::OVERFLOW)?,
tv_sec: timeout.tv_sec,
tv_usec: ((timeout.tv_nsec + 999) / 1000) as _,
};
&timeout_data
Expand Down
63 changes: 1 addition & 62 deletions src/backend/libc/event/windows_syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

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

pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usize> {
Expand All @@ -15,63 +14,3 @@ pub(crate) fn poll(fds: &mut [PollFd<'_>], timeout: c::c_int) -> io::Result<usiz
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 len = crate::event::fd_set_num_elements(nfds as RawFd);

let readfds = match readfds {
Some(readfds) => {
assert!(readfds.len() >= len);
readfds.as_mut_ptr()
}
None => null_mut(),
};
let writefds = match writefds {
Some(writefds) => {
assert!(writefds.len() >= len);
writefds.as_mut_ptr()
}
None => null_mut(),
};
let exceptfds = match exceptfds {
Some(exceptfds) => {
assert!(exceptfds.len() >= len);
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,
))
}
}
6 changes: 0 additions & 6 deletions src/backend/libc/winsock_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,3 @@ pub(crate) use WinSock::{
WSAEWOULDBLOCK as EWOULDBLOCK, WSAEWOULDBLOCK as EAGAIN, WSAPOLLFD as pollfd,
WSA_E_CANCELLED as ECANCELED, *,
};

pub struct timespec {
pub tv_sec: time_t,
pub tv_nsec: i64,
}
pub type time_t = i64;
4 changes: 2 additions & 2 deletions src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod pause;
mod poll;
#[cfg(solarish)]
pub mod port;
#[cfg(any(bsd, linux_kernel, windows))]
#[cfg(any(bsd, linux_kernel))]
mod select;

#[cfg(any(
Expand All @@ -29,5 +29,5 @@ pub use eventfd::{eventfd, EventfdFlags};
#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))]
pub use pause::*;
pub use poll::{poll, PollFd, PollFlags};
#[cfg(any(bsd, linux_kernel, windows))]
#[cfg(any(bsd, linux_kernel))]
pub use select::*;
5 changes: 3 additions & 2 deletions src/event/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub type FdSetElement = u32;
/// this platform always has an `FD_SETSIZE` limitation, following POSIX. This
/// platform's documentation recommends using [`poll`] instead.
///
/// On Windows, this function is not defined because the `select` function on
/// this platform doesn't use bitvectors for file descriptor sets.
///
/// [`poll`]: crate::event::poll()
///
/// # Safety
Expand All @@ -61,7 +64,6 @@ pub type FdSetElement = u32;
/// - [NetBSD]
/// - [OpenBSD]
/// - [DragonFly BSD]
/// - [Winsock]
/// - [glibc]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/select.html
Expand All @@ -71,7 +73,6 @@ pub type FdSetElement = u32;
/// [NetBSD]: https://man.netbsd.org/select.2
/// [OpenBSD]: https://man.openbsd.org/select.2
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=select&section=2
/// [Winsock]: https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Waiting-for-I_002fO.html#index-select
pub unsafe fn select(
nfds: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,14 @@ mod prctl;
#[cfg(not(any(windows, target_os = "espidf", target_os = "wasi")))]
#[cfg(any(feature = "process", feature = "runtime", all(bsd, feature = "event")))]
mod signal;
#[cfg(not(windows))]
#[cfg(any(
feature = "fs",
feature = "process",
feature = "runtime",
feature = "thread",
feature = "time",
all(feature = "event", any(bsd, linux_kernel, windows)),
all(feature = "event", any(bsd, linux_kernel)),
all(
linux_raw,
not(feature = "use-libc-auxv"),
Expand Down
2 changes: 1 addition & 1 deletion tests/event/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ mod epoll;
#[cfg(not(target_os = "wasi"))]
mod eventfd;
mod poll;
#[cfg(any(bsd, linux_kernel, windows))]
#[cfg(any(bsd, linux_kernel))]
mod select;
3 changes: 0 additions & 3 deletions tests/event/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rustix::event::{
};
use rustix::fd::RawFd;
#[cfg(feature = "pipe")]
#[cfg(not(windows))]
use {
rustix::event::{select, Timespec},
rustix::fd::{AsRawFd, FromRawFd, OwnedFd},
Expand All @@ -13,7 +12,6 @@ use {
};

#[cfg(feature = "pipe")]
#[cfg(not(windows))]
#[test]
fn test_select() {
use rustix::io::{read, write};
Expand Down Expand Up @@ -84,7 +82,6 @@ fn test_select() {
}

#[cfg(feature = "pipe")]
#[cfg(not(windows))]
#[test]
fn test_select_with_great_fds() {
use core::cmp::max;
Expand Down

0 comments on commit 680ec5e

Please sign in to comment.