diff --git a/src/interest.rs b/src/interest.rs index 50d1bf047..06b163225 100644 --- a/src/interest.rs +++ b/src/interest.rs @@ -37,6 +37,8 @@ impl Interest { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] pub const AIO: Interest = Interest(unsafe { NonZeroU8::new_unchecked(AIO) }); @@ -153,6 +155,8 @@ impl fmt::Debug for Interest { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] { if self.is_aio() { diff --git a/src/sys/unix/net.rs b/src/sys/unix/net.rs index 2396ab9eb..e93918c72 100644 --- a/src/sys/unix/net.rs +++ b/src/sys/unix/net.rs @@ -27,7 +27,12 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R let socket = syscall!(socket(domain, socket_type, 0))?; // Mimick `libstd` and set `SO_NOSIGPIPE` on apple systems. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ))] if let Err(err) = syscall!(setsockopt( socket, libc::SOL_SOCKET, @@ -40,7 +45,12 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R } // Darwin doesn't have SOCK_NONBLOCK or SOCK_CLOEXEC. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ))] { if let Err(err) = syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK)) { let _ = syscall!(close(socket)); @@ -93,6 +103,8 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "tvos", + target_os = "watchos", ))] sin_len: 0, }; @@ -117,6 +129,8 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_ target_os = "macos", target_os = "netbsd", target_os = "openbsd", + target_os = "tvos", + target_os = "watchos", ))] sin6_len: 0, #[cfg(target_os = "illumos")] diff --git a/src/sys/unix/pipe.rs b/src/sys/unix/pipe.rs index 7b7e4db7c..c2654ad59 100644 --- a/src/sys/unix/pipe.rs +++ b/src/sys/unix/pipe.rs @@ -163,7 +163,12 @@ pub fn new() -> io::Result<(Sender, Receiver)> { } } - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ))] unsafe { // For platforms that don't have `pipe2(2)` we need to manually set the // correct flags on the file descriptor. @@ -195,6 +200,8 @@ pub fn new() -> io::Result<(Sender, Receiver)> { target_os = "netbsd", target_os = "openbsd", target_os = "redox", + target_os = "tvos", + target_os = "watchos", )))] compile_error!("unsupported target for `mio::unix::pipe`"); diff --git a/src/sys/unix/selector/kqueue.rs b/src/sys/unix/selector/kqueue.rs index 1eedec04f..4b0c63163 100644 --- a/src/sys/unix/selector/kqueue.rs +++ b/src/sys/unix/selector/kqueue.rs @@ -21,7 +21,12 @@ type Count = libc::size_t; // Type of the `filter` field in the `kevent` structure. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] type Filter = libc::c_short; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" +))] type Filter = i16; #[cfg(target_os = "netbsd")] type Filter = u32; @@ -29,7 +34,12 @@ type Filter = u32; // Type of the `flags` field in the `kevent` structure. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] type Flags = libc::c_ushort; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" +))] type Flags = u16; #[cfg(target_os = "netbsd")] type Flags = u32; @@ -210,7 +220,13 @@ impl Selector { } // Used by `Waker`. - #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] pub fn setup_waker(&self, token: Token) -> io::Result<()> { // First attempt to accept user space notifications. let mut kevent = kevent!( @@ -230,7 +246,13 @@ impl Selector { } // Used by `Waker`. - #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] pub fn wake(&self, token: Token) -> io::Result<()> { let mut kevent = kevent!( 0, @@ -361,14 +383,26 @@ pub mod event { pub fn is_readable(event: &Event) -> bool { event.filter == libc::EVFILT_READ || { - #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] // Used by the `Awakener`. On platforms that use `eventfd` or a unix // pipe it will emit a readable event so we'll fake that here as // well. { event.filter == libc::EVFILT_USER } - #[cfg(not(any(target_os = "freebsd", target_os = "ios", target_os = "macos")))] + #[cfg(not(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + )))] { false } @@ -406,6 +440,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] { event.filter == libc::EVFILT_AIO @@ -415,6 +451,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", )))] { false @@ -451,6 +489,8 @@ pub mod event { target_os = "dragonfly", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::EVFILT_FS, #[cfg(target_os = "freebsd")] @@ -460,6 +500,8 @@ pub mod event { target_os = "dragonfly", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::EVFILT_USER, #[cfg(target_os = "freebsd")] @@ -468,9 +510,19 @@ pub mod event { libc::EVFILT_EMPTY, #[cfg(target_os = "dragonfly")] libc::EVFILT_EXCEPT, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::EVFILT_MACHPORT, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::EVFILT_VM, ); @@ -495,11 +547,26 @@ pub mod event { libc::EV_ERROR, libc::EV_EOF, libc::EV_SYSFLAGS, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::EV_FLAG0, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::EV_POLL, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::EV_OOBAND, #[cfg(target_os = "dragonfly")] libc::EV_NODATA, @@ -517,6 +584,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::NOTE_TRIGGER, #[cfg(any( @@ -524,6 +593,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::NOTE_FFNOP, #[cfg(any( @@ -531,6 +602,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::NOTE_FFAND, #[cfg(any( @@ -538,6 +611,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::NOTE_FFOR, #[cfg(any( @@ -545,6 +620,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::NOTE_FFCOPY, #[cfg(any( @@ -552,6 +629,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::NOTE_FFCTRLMASK, #[cfg(any( @@ -559,6 +638,8 @@ pub mod event { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] libc::NOTE_FFLAGSMASK, libc::NOTE_LOWAT, @@ -568,24 +649,49 @@ pub mod event { libc::NOTE_OOB, #[cfg(target_os = "openbsd")] libc::NOTE_EOF, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_EXTEND, libc::NOTE_ATTRIB, libc::NOTE_LINK, libc::NOTE_RENAME, libc::NOTE_REVOKE, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_NONE, #[cfg(any(target_os = "openbsd"))] libc::NOTE_TRUNCATE, libc::NOTE_EXIT, libc::NOTE_FORK, libc::NOTE_EXEC, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_SIGNAL, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_EXITSTATUS, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_EXIT_DETAIL, libc::NOTE_PDATAMASK, libc::NOTE_PCTRLMASK, @@ -610,37 +716,115 @@ pub mod event { target_os = "openbsd", ))] libc::NOTE_CHILD, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_EXIT_DETAIL_MASK, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_EXIT_DECRYPTFAIL, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_EXIT_MEMORY, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_EXIT_CSERROR, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_VM_PRESSURE, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_VM_PRESSURE_TERMINATE, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_VM_PRESSURE_SUDDEN_TERMINATE, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_VM_ERROR, - #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_SECONDS, #[cfg(any(target_os = "freebsd"))] libc::NOTE_MSECONDS, - #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_USECONDS, - #[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_NSECONDS, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_ABSOLUTE, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_LEEWAY, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_CRITICAL, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos" + ))] libc::NOTE_BACKGROUND, ); diff --git a/src/sys/unix/selector/mod.rs b/src/sys/unix/selector/mod.rs index c06c7b18c..3ccbdeadf 100644 --- a/src/sys/unix/selector/mod.rs +++ b/src/sys/unix/selector/mod.rs @@ -17,20 +17,24 @@ pub(crate) use self::epoll::{event, Event, Events, Selector}; #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", target_os = "ios", target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "tvos", + target_os = "watchos", ))] mod kqueue; #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", target_os = "ios", target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "tvos", + target_os = "watchos", ))] pub(crate) use self::kqueue::{event, Event, Events, Selector}; diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index 9513cc096..48cf8d9ef 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -85,6 +85,8 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, target_os = "ios", target_os = "macos", target_os = "redox", + target_os = "tvos", + target_os = "watchos", all(target_arch = "x86", target_os = "android"), ))] let stream = { diff --git a/src/sys/unix/uds/listener.rs b/src/sys/unix/uds/listener.rs index 3e33b3040..52387a544 100644 --- a/src/sys/unix/uds/listener.rs +++ b/src/sys/unix/uds/listener.rs @@ -39,6 +39,8 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So target_os = "macos", target_os = "netbsd", target_os = "redox", + target_os = "tvos", + target_os = "watchos", // Android x86's seccomp profile forbids calls to `accept4(2)` // See https://github.com/tokio-rs/mio/issues/1445 for details all(target_arch = "x86", target_os = "android"), @@ -55,10 +57,12 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So }; #[cfg(any( - target_os = "netbsd", - target_os = "redox", target_os = "ios", target_os = "macos", + target_os = "netbsd", + target_os = "redox", + target_os = "tvos", + target_os = "watchos", all(target_arch = "x86", target_os = "android") ))] let socket = syscall!(accept( diff --git a/src/sys/unix/uds/mod.rs b/src/sys/unix/uds/mod.rs index 526bbdfd0..429b8117b 100644 --- a/src/sys/unix/uds/mod.rs +++ b/src/sys/unix/uds/mod.rs @@ -77,7 +77,12 @@ cfg_os_poll! { fn pair(flags: libc::c_int) -> io::Result<(T, T)> where T: FromRawFd, { - #[cfg(not(any(target_os = "ios", target_os = "macos")))] + #[cfg(not(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + )))] let flags = flags | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC; let mut fds = [-1; 2]; @@ -90,7 +95,12 @@ cfg_os_poll! { // performed. If a `fnctl` fails after the sockets have been created, // the file descriptors will leak. Creating `pair` above ensures that if // there is an error, the file descriptors are closed. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + ))] { syscall!(fcntl(fds[0], libc::F_SETFL, libc::O_NONBLOCK))?; syscall!(fcntl(fds[0], libc::F_SETFD, libc::FD_CLOEXEC))?; diff --git a/src/sys/unix/waker.rs b/src/sys/unix/waker.rs index d8764c212..0044cd06d 100644 --- a/src/sys/unix/waker.rs +++ b/src/sys/unix/waker.rs @@ -58,7 +58,13 @@ mod eventfd { #[cfg(any(target_os = "linux", target_os = "android"))] pub use self::eventfd::Waker; -#[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] +#[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", +))] mod kqueue { use crate::sys::Selector; use crate::Token; @@ -90,7 +96,13 @@ mod kqueue { } } -#[cfg(any(target_os = "freebsd", target_os = "ios", target_os = "macos"))] +#[cfg(any( + target_os = "freebsd", + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", +))] pub use self::kqueue::Waker; #[cfg(any( diff --git a/tests/interest.rs b/tests/interest.rs index 7814789f8..ae3e2b8cb 100644 --- a/tests/interest.rs +++ b/tests/interest.rs @@ -30,6 +30,8 @@ fn fmt_debug() { target_os = "freebsd", target_os = "ios", target_os = "macos", + target_os = "tvos", + target_os = "watchos", ))] { assert_eq!(format!("{:?}", Interest::AIO), "AIO"); diff --git a/tests/tcp_stream.rs b/tests/tcp_stream.rs index 26a5b4706..1fe99980c 100644 --- a/tests/tcp_stream.rs +++ b/tests/tcp_stream.rs @@ -297,6 +297,8 @@ fn shutdown_read() { target_os = "macos", target_os = "netbsd", target_os = "openbsd" + target_os = "tvos", + target_os = "watchos", ))] { let mut buf = [0; 20]; @@ -385,6 +387,8 @@ fn shutdown_both() { target_os = "macos", target_os = "netbsd", target_os = "openbsd" + target_os = "tvos", + target_os = "watchos", ))] { let mut buf = [0; 20]; diff --git a/tests/unix_stream.rs b/tests/unix_stream.rs index 79b7c3d4b..90fca2d0f 100644 --- a/tests/unix_stream.rs +++ b/tests/unix_stream.rs @@ -186,6 +186,8 @@ fn unix_stream_shutdown_read() { target_os = "macos", target_os = "netbsd", target_os = "openbsd" + target_os = "tvos", + target_os = "watchos", ))] { let mut buf = [0; DEFAULT_BUF_SIZE]; @@ -233,6 +235,8 @@ fn unix_stream_shutdown_write() { target_os = "macos", target_os = "netbsd", target_os = "openbsd" + target_os = "tvos", + target_os = "watchos", ))] expect_events( &mut poll, @@ -295,6 +299,8 @@ fn unix_stream_shutdown_both() { target_os = "macos", target_os = "netbsd", target_os = "openbsd" + target_os = "tvos", + target_os = "watchos", ))] { let mut buf = [0; DEFAULT_BUF_SIZE]; diff --git a/tests/util/mod.rs b/tests/util/mod.rs index b1e04e22d..6bc34669f 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -249,9 +249,19 @@ pub fn set_linger_zero(socket: &TcpStream) { libc::setsockopt( socket.as_raw_fd(), libc::SOL_SOCKET, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(any( + target_os = "ios", + target_os = "macos" + target_os = "tvos", + target_os = "watchos", + ))] libc::SO_LINGER_SEC, - #[cfg(not(any(target_os = "ios", target_os = "macos")))] + #[cfg(not(any( + target_os = "ios", + target_os = "macos", + target_os = "tvos", + target_os = "watchos", + )))] libc::SO_LINGER, &val as *const libc::linger as *const libc::c_void, size_of::() as libc::socklen_t,