From 4191836c73a3ba29b90ffa98f595cfd9f0189f13 Mon Sep 17 00:00:00 2001 From: "Alexander V. Nikolaev" Date: Thu, 12 Sep 2024 14:14:43 +0300 Subject: [PATCH] Fix conditions for vsock Signed-off-by: Alexander V. Nikolaev --- src/connection.rs | 30 +++++++++++++++--------------- src/listener.rs | 20 ++++++++++---------- src/listener_address.rs | 2 +- src/some_socket_addr.rs | 14 +++++++------- src/tokioutil.rs | 2 +- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index 261ae7e..6c97160 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -22,7 +22,7 @@ use tracing::{debug, warn}; #[cfg(unix)] use tokio::net::UnixStream; -#[cfg(all(feature = "vsock", target_os = "linux"))] +#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] use tokio_vsock::VsockStream; /// Accepted connection, which can be a TCP socket, AF_UNIX stream socket or a stdin/stdout pair. @@ -37,7 +37,7 @@ impl std::fmt::Debug for Connection { ConnectionImpl::Tcp(_) => f.write_str("Connection(tcp)"), #[cfg(all(feature = "unix", unix))] ConnectionImpl::Unix(_) => f.write_str("Connection(unix)"), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ConnectionImpl::Vsock(_) => f.write_str("Connection(vsock)"), #[cfg(feature = "inetd")] ConnectionImpl::Stdio(_, _, _) => f.write_str("Connection(stdio)"), @@ -57,7 +57,7 @@ pub(crate) enum ConnectionImpl { #[pin] tokio::io::Stdout, Option>, ), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] Vsock(#[pin] VsockStream), } @@ -95,8 +95,8 @@ impl Connection { Err(self) } } - #[cfg(feature = "vsock")] - #[cfg_attr(docsrs_alt, doc(cfg(feature = "vsock")))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] + #[cfg_attr(docsrs_alt, doc(cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))))] pub fn try_into_vsock(self) -> Result { if let ConnectionImpl::Vsock(vsock) = self.0 { Ok(vsock) @@ -130,8 +130,8 @@ impl Connection { None } } - #[cfg(feature = "vsock")] - #[cfg_attr(docsrs_alt, doc(cfg(feature = "vsock")))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] + #[cfg_attr(docsrs_alt, doc(cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))))] pub fn try_borrow_vsock(&self) -> Option<&VsockStream> { if let ConnectionImpl::Vsock(ref vsock) = self.0 { Some(vsock) @@ -161,8 +161,8 @@ impl From<(Stdin, Stdout, Option>)> for Connection { } } -#[cfg(all(feature = "vsock", target_os = "linux"))] -#[cfg_attr(docsrs_alt, doc(cfg(all(feature = "vsock", target_os = "linux"))))] +#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] +#[cfg_attr(docsrs_alt, doc(cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))))] impl From for Connection { fn from(s: VsockStream) ->Self { Connection(ConnectionImpl::Vsock(s)) @@ -183,7 +183,7 @@ impl AsyncRead for Connection { ConnectionImplProj::Unix(s) => s.poll_read(cx, buf), #[cfg(feature = "inetd")] ConnectionImplProj::Stdio(s, _, _) => s.poll_read(cx, buf), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ConnectionImplProj::Vsock(s) => s.poll_read(cx, buf), } } @@ -203,7 +203,7 @@ impl AsyncWrite for Connection { ConnectionImplProj::Unix(s) => s.poll_write(cx, buf), #[cfg(feature = "inetd")] ConnectionImplProj::Stdio(_, s, _) => s.poll_write(cx, buf), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ConnectionImplProj::Vsock(s) => s.poll_write(cx, buf), } } @@ -217,7 +217,7 @@ impl AsyncWrite for Connection { ConnectionImplProj::Unix(s) => s.poll_flush(cx), #[cfg(feature = "inetd")] ConnectionImplProj::Stdio(_, s, _) => s.poll_flush(cx), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ConnectionImplProj::Vsock(s) => s.poll_flush(cx), } } @@ -246,7 +246,7 @@ impl AsyncWrite for Connection { Poll::Ready(ret) } }, - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ConnectionImplProj::Vsock(s) => s.poll_shutdown(cx), } } @@ -264,7 +264,7 @@ impl AsyncWrite for Connection { ConnectionImplProj::Unix(s) => s.poll_write_vectored(cx, bufs), #[cfg(feature = "inetd")] ConnectionImplProj::Stdio(_, s, _) => s.poll_write_vectored(cx, bufs), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ConnectionImplProj::Vsock(s) => s.poll_write_vectored(cx, bufs), } } @@ -277,7 +277,7 @@ impl AsyncWrite for Connection { ConnectionImpl::Unix(s) => s.is_write_vectored(), #[cfg(feature = "inetd")] ConnectionImpl::Stdio(_, s, _) => s.is_write_vectored(), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ConnectionImpl::Vsock(s) => s.is_write_vectored(), } } diff --git a/src/listener.rs b/src/listener.rs index dde9e3e..2a8b754 100644 --- a/src/listener.rs +++ b/src/listener.rs @@ -49,7 +49,7 @@ impl std::fmt::Debug for Listener { ListenerImpl::Unix { .. } => f.write_str("tokio_listener::Listener(unix)"), #[cfg(feature = "inetd")] ListenerImpl::Stdio(_) => f.write_str("tokio_listener::Listener(stdio)"), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ListenerImpl::Vsock(_) => f.write_str("tokio_listener::Listener(vsock)"), #[cfg(feature = "multi-listener")] ListenerImpl::Multi(ref x) => { @@ -168,7 +168,7 @@ fn listen_abstract(a: &String, usr_opts: &UserOptions) -> Result Result { use tokio_vsock::{VsockAddr, VsockListener}; let vs = VsockAddr::new(*cid, *port); @@ -363,7 +363,7 @@ impl Listener { ListenerAddress::FromFdNamed(fdname) => { listen_from_fd_named(usr_opts, fdname, sys_opts)? } - #[cfg(all(target_os = "linux", feature = "vsock"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ListenerAddress::Vsock(vs) => listen_vsock(vs)?, #[allow(unreachable_patterns)] _ => { @@ -424,16 +424,16 @@ impl Listener { } }, ListenerAddress::Vsock(_) => { - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))] { MissingCompileTimeFeature { reason: "use vsock socket", feature: "vsock", } } - #[cfg(not(target_os = "linux"))] + #[cfg(not(any(target_os = "linux", target_os = "android", target_os = "macos")))] { - MissingPlatformSypport { + MissingPlatformSupport { reason: "use vsock socket", feature: "linux platform", } @@ -662,7 +662,7 @@ pub(crate) struct ListenerImplUnix { send_buffer_size: Option, } -#[cfg(all(feature = "vsock", target_os = "linux"))] +#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] pub(crate) struct ListenerImplVsock { pub(crate) s: tokio_vsock::VsockListener, } @@ -678,7 +678,7 @@ pub(crate) enum ListenerImpl { Unix(ListenerImplUnix), #[cfg(feature = "inetd")] Stdio(StdioListener), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] Vsock(ListenerImplVsock), #[cfg(feature = "multi-listener")] Multi(ListenerImplMulti), @@ -695,7 +695,7 @@ impl ListenerImpl { ListenerImpl::Unix(ui) => ui.poll_accept(cx), #[cfg(feature = "inetd")] ListenerImpl::Stdio(x) => x.poll_accept(cx), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] ListenerImpl::Vsock(vs) => vs.poll_accept(cx), #[cfg(feature = "multi-listener")] ListenerImpl::Multi(x) => x.poll_accept(cx), @@ -773,7 +773,7 @@ impl ListenerImplUnix { } } -#[cfg(all(feature = "vsock", target_os = "linux"))] +#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] impl ListenerImplVsock { fn poll_accept( &mut self, diff --git a/src/listener_address.rs b/src/listener_address.rs index e664d28..fe71d16 100644 --- a/src/listener_address.rs +++ b/src/listener_address.rs @@ -163,7 +163,7 @@ pub(crate) fn check_env_for_fd(fdnum: i32) -> Option<()> { Some(()) } -#[cfg(all(unix, feature = "vsock"))] +#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] impl std::convert::From for ListenerAddress { fn from(vs: tokio_vsock::VsockAddr) -> Self { ListenerAddress::Vsock((vs.cid(), vs.port())) diff --git a/src/some_socket_addr.rs b/src/some_socket_addr.rs index 2d9508d..c287e83 100644 --- a/src/some_socket_addr.rs +++ b/src/some_socket_addr.rs @@ -14,8 +14,8 @@ pub enum SomeSocketAddr { #[cfg(feature = "inetd")] #[cfg_attr(docsrs_alt, doc(cfg(feature = "inetd")))] Stdio, - #[cfg(all(feature = "vsock", target_os = "linux"))] - #[cfg_attr(docsrs_alt, doc(cfg(all(feature = "vsock", target_os = "linux"))))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] + #[cfg_attr(docsrs_alt, doc(cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))))] Vsock(tokio_vsock::VsockAddr), #[cfg(feature = "multi-listener")] #[cfg_attr(docsrs_alt, doc(cfg(feature = "multi-listener")))] @@ -30,7 +30,7 @@ impl Display for SomeSocketAddr { SomeSocketAddr::Unix(_x) => "unix".fmt(f), #[cfg(feature = "inetd")] SomeSocketAddr::Stdio => "stdio".fmt(f), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] SomeSocketAddr::Vsock(x) => x.fmt(f), #[cfg(feature = "multi-listener")] SomeSocketAddr::Multiple => "multiple".fmt(f), @@ -49,7 +49,7 @@ impl SomeSocketAddr { SomeSocketAddr::Unix(x) => SomeSocketAddrClonable::Unix(Arc::new(x)), #[cfg(feature = "inetd")] SomeSocketAddr::Stdio => SomeSocketAddrClonable::Stdio, - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] SomeSocketAddr::Vsock(x) => SomeSocketAddrClonable::Vsock(x), #[cfg(feature = "multi-listener")] SomeSocketAddr::Multiple => SomeSocketAddrClonable::Multiple, @@ -69,8 +69,8 @@ pub enum SomeSocketAddrClonable { #[cfg(feature = "inetd")] #[cfg_attr(docsrs_alt, doc(cfg(feature = "inetd")))] Stdio, - #[cfg(all(feature = "vsock", target_os = "linux"))] - #[cfg_attr(docsrs_alt, doc(cfg(all(feature = "vsock", target_os = "linux"))))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] + #[cfg_attr(docsrs_alt, doc(cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))))] Vsock(tokio_vsock::VsockAddr), #[cfg(feature = "multi-listener")] #[cfg_attr(docsrs_alt, doc(cfg(feature = "multi-listener")))] @@ -85,7 +85,7 @@ impl Display for SomeSocketAddrClonable { SomeSocketAddrClonable::Unix(x) => write!(f, "unix:{x:?}"), #[cfg(feature = "inetd")] SomeSocketAddrClonable::Stdio => "stdio".fmt(f), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] SomeSocketAddrClonable::Vsock(x) => x.fmt(f), #[cfg(feature = "multi-listener")] SomeSocketAddrClonable::Multiple => "multiple".fmt(f), diff --git a/src/tokioutil.rs b/src/tokioutil.rs index 36bc857..e786df2 100644 --- a/src/tokioutil.rs +++ b/src/tokioutil.rs @@ -24,7 +24,7 @@ impl tokio_util::net::Listener for crate::Listener { }) => Ok(SomeSocketAddr::Unix(s.local_addr()?)), #[cfg(feature = "inetd")] crate::listener::ListenerImpl::Stdio(_) => Ok(SomeSocketAddr::Stdio), - #[cfg(all(feature = "vsock", target_os = "linux"))] + #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))] crate::listener::ListenerImpl::Vsock(crate::listener::ListenerImplVsock{s}) => { Ok(SomeSocketAddr::Vsock(s.local_addr()?)) },