Skip to content

Commit

Permalink
Fix conditions for vsock
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander V. Nikolaev <[email protected]>
  • Loading branch information
avnik committed Sep 12, 2024
1 parent d2ff11d commit 4191836
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
30 changes: 15 additions & 15 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)"),
Expand All @@ -57,7 +57,7 @@ pub(crate) enum ConnectionImpl {
#[pin] tokio::io::Stdout,
Option<Sender<()>>,
),
#[cfg(all(feature = "vsock", target_os = "linux"))]
#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))]
Vsock(#[pin] VsockStream),
}

Expand Down Expand Up @@ -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<VsockStream, Self> {
if let ConnectionImpl::Vsock(vsock) = self.0 {
Ok(vsock)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -161,8 +161,8 @@ impl From<(Stdin, Stdout, Option<Sender<()>>)> 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<VsockStream> for Connection {
fn from(s: VsockStream) ->Self {
Connection(ConnectionImpl::Vsock(s))
Expand All @@ -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),
}
}
Expand All @@ -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),
}
}
Expand All @@ -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),
}
}
Expand Down Expand Up @@ -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),
}
}
Expand All @@ -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),
}
}
Expand All @@ -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(),
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -168,7 +168,7 @@ fn listen_abstract(a: &String, usr_opts: &UserOptions) -> Result<ListenerImpl, s
}))
}

#[cfg(all(target_os = "linux", feature = "vsock"))]
#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "macos"), feature = "vsock"))]
fn listen_vsock((cid, port): &(u32, u32)) -> Result<ListenerImpl, std::io::Error> {
use tokio_vsock::{VsockAddr, VsockListener};
let vs = VsockAddr::new(*cid, *port);
Expand Down Expand Up @@ -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)]
_ => {
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -662,7 +662,7 @@ pub(crate) struct ListenerImplUnix {
send_buffer_size: Option<usize>,
}

#[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,
}
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/listener_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<tokio_vsock::VsockAddr> for ListenerAddress {
fn from(vs: tokio_vsock::VsockAddr) -> Self {
ListenerAddress::Vsock((vs.cid(), vs.port()))
Expand Down
14 changes: 7 additions & 7 deletions src/some_socket_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))]
Expand All @@ -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),
Expand All @@ -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,
Expand All @@ -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")))]
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/tokioutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?))
},
Expand Down

0 comments on commit 4191836

Please sign in to comment.