From edc180a455f3fef83dcf7a891e70e3113fc6b7c4 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Fri, 14 Jun 2024 11:58:29 +0200 Subject: [PATCH] Add Haiku support Uses the poll(2) implementation for Poll and the pipe(2) based implementation for Waker. Perhaps we can do better, but I can't find any proper manuals for the OS outside of a reference to the Posix standard. Hence I only uses APIs available in said standard. Closes #1472 Updates #1702 --- .github/workflows/ci.yml | 1 + README.md | 2 -- src/poll.rs | 3 +++ src/sys/unix/mod.rs | 7 ++++--- src/sys/unix/net.rs | 6 +++++- src/sys/unix/pipe.rs | 2 ++ src/sys/unix/selector/mod.rs | 3 +++ src/sys/unix/tcp.rs | 1 + src/sys/unix/uds/listener.rs | 2 ++ src/sys/unix/uds/mod.rs | 2 ++ src/sys/unix/waker.rs | 7 +++++++ 11 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a15663bbe..80483f854 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,6 +162,7 @@ jobs: - x86_64-pc-windows-msvc - x86_64-unknown-dragonfly - x86_64-unknown-freebsd + - x86_64-unknown-haiku - x86_64-unknown-hermit - x86_64-unknown-illumos - x86_64-unknown-linux-gnu diff --git a/README.md b/README.md index 190e7243c..d7f97da3d 100644 --- a/README.md +++ b/README.md @@ -152,11 +152,9 @@ This uses the Windows AFD system to access socket readiness events. ### Unsupported -* Haiku, see [issue #1472] * Solaris, see [issue #1152] * Wine, see [issue #1444] -[issue #1472]: https://github.com/tokio-rs/mio/issues/1472 [issue #1152]: https://github.com/tokio-rs/mio/issues/1152 [issue #1444]: https://github.com/tokio-rs/mio/issues/1444 diff --git a/src/poll.rs b/src/poll.rs index bf91bfed7..d83739818 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -3,6 +3,7 @@ not(mio_unsupported_force_poll_poll), not(any( target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", @@ -438,6 +439,7 @@ impl Poll { not(mio_unsupported_force_poll_poll), not(any( target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", @@ -735,6 +737,7 @@ impl fmt::Debug for Registry { not(mio_unsupported_force_poll_poll), not(any( target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", diff --git a/src/sys/unix/mod.rs b/src/sys/unix/mod.rs index ad411a625..99cbc8e8b 100644 --- a/src/sys/unix/mod.rs +++ b/src/sys/unix/mod.rs @@ -36,7 +36,7 @@ cfg_os_poll! { cfg_io_source! { // Both `kqueue` and `epoll` don't need to hold any user space state. - #[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "nto", target_os = "solaris", target_os = "vita")))] + #[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", target_os = "vita")))] mod stateless_io_source { use std::io; use std::os::fd::RawFd; @@ -88,10 +88,10 @@ cfg_os_poll! { } } - #[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "nto", target_os = "solaris", target_os = "vita")))] + #[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", target_os = "vita")))] pub(crate) use self::stateless_io_source::IoSourceState; - #[cfg(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "nto", target_os = "solaris", target_os = "vita"))] + #[cfg(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", target_os = "vita"))] pub(crate) use self::selector::IoSourceState; } @@ -102,6 +102,7 @@ cfg_os_poll! { mio_unsupported_force_waker_pipe, target_os = "aix", target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "nto", diff --git a/src/sys/unix/net.rs b/src/sys/unix/net.rs index 0298d0b38..907e3b005 100644 --- a/src/sys/unix/net.rs +++ b/src/sys/unix/net.rs @@ -105,14 +105,17 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ sin_family: libc::AF_INET as libc::sa_family_t, sin_port: addr.port().to_be(), sin_addr, - #[cfg(not(target_os = "vita"))] + #[cfg(not(any(target_os = "haiku", target_os = "vita")))] sin_zero: [0; 8], + #[cfg(target_os = "haiku")] + sin_zero: [0; 24], #[cfg(target_os = "vita")] sin_zero: [0; 6], #[cfg(any( target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -147,6 +150,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ target_os = "aix", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", diff --git a/src/sys/unix/pipe.rs b/src/sys/unix/pipe.rs index b15cd5132..ea7b9947f 100644 --- a/src/sys/unix/pipe.rs +++ b/src/sys/unix/pipe.rs @@ -28,6 +28,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> { #[cfg(any( target_os = "aix", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "tvos", @@ -61,6 +62,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> { target_os = "android", target_os = "dragonfly", target_os = "freebsd", + target_os = "haiku", target_os = "illumos", target_os = "ios", target_os = "linux", diff --git a/src/sys/unix/selector/mod.rs b/src/sys/unix/selector/mod.rs index 676b69a53..8243d38f2 100644 --- a/src/sys/unix/selector/mod.rs +++ b/src/sys/unix/selector/mod.rs @@ -23,6 +23,7 @@ pub(crate) use self::epoll::{event, Event, Events, Selector}; #[cfg(any( mio_unsupported_force_poll_poll, target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", @@ -33,6 +34,7 @@ mod poll; #[cfg(any( mio_unsupported_force_poll_poll, target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", @@ -44,6 +46,7 @@ cfg_io_source! { #[cfg(any( mio_unsupported_force_poll_poll, target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index fa3f58de7..be3598cdb 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -89,6 +89,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, // set `CLOEXEC`. #[cfg(any( target_os = "aix", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "redox", diff --git a/src/sys/unix/uds/listener.rs b/src/sys/unix/uds/listener.rs index b23e79e11..bab5099e9 100644 --- a/src/sys/unix/uds/listener.rs +++ b/src/sys/unix/uds/listener.rs @@ -35,6 +35,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So #[cfg(not(any( target_os = "aix", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", @@ -62,6 +63,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So #[cfg(any( target_os = "aix", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "netbsd", diff --git a/src/sys/unix/uds/mod.rs b/src/sys/unix/uds/mod.rs index 074d06f53..7a1a91de5 100644 --- a/src/sys/unix/uds/mod.rs +++ b/src/sys/unix/uds/mod.rs @@ -87,6 +87,7 @@ where { #[cfg(not(any( target_os = "aix", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "nto", @@ -110,6 +111,7 @@ where // there is an error, the file descriptors are closed. #[cfg(any( target_os = "aix", + target_os = "haiku", target_os = "ios", target_os = "macos", target_os = "nto", diff --git a/src/sys/unix/waker.rs b/src/sys/unix/waker.rs index ac9838211..c53b6c049 100644 --- a/src/sys/unix/waker.rs +++ b/src/sys/unix/waker.rs @@ -13,6 +13,7 @@ )), not(any( target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", @@ -74,6 +75,7 @@ mod fdbased { )), not(any( target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", @@ -239,6 +241,7 @@ pub use self::kqueue::Waker; mio_unsupported_force_waker_pipe, target_os = "aix", target_os = "dragonfly", + target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "nto", @@ -294,6 +297,7 @@ mod pipe { #[cfg(any( mio_unsupported_force_poll_poll, target_os = "espidf", + target_os = "haiku", target_os = "nto", target_os = "solaris", target_os = "vita", @@ -335,6 +339,7 @@ mod pipe { target_os = "redox", ) ), + target_os = "haiku", target_os = "nto", target_os = "solaris", target_os = "vita", @@ -344,6 +349,7 @@ pub(crate) use self::pipe::WakerInternal; #[cfg(any( mio_unsupported_force_poll_poll, target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris", @@ -377,6 +383,7 @@ mod poll { #[cfg(any( mio_unsupported_force_poll_poll, target_os = "espidf", + target_os = "haiku", target_os = "hermit", target_os = "nto", target_os = "solaris",