Skip to content

Commit

Permalink
🚩 zb: Disable UDS support on Windows for tokio
Browse files Browse the repository at this point in the history
Since tokio currently [does not support Unix domain sockets on
Windows][tuds], there is no reason to enable UDS support on Windows+tokio.
This also fixes a build warning against rust nightly:

```rust
error: field `0` is never read
  --> zbus\src\connection\builder.rs:45:16
   |
45 |     UnixStream(UnixStream),
   |     ---------- ^^^^^^^^^^
   |     |
   |     field in this variant
   |
   = note: `-D dead-code` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(dead_code)]`
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
   |
45 |     UnixStream(()),
   |                ~~
```

[tuds]: tokio-rs/tokio#2201
  • Loading branch information
zeenix committed Feb 11, 2024
1 parent be21e19 commit 9f13788
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 7 additions & 1 deletion zbus/src/blocking/connection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::os::unix::net::UnixStream;
use tokio::net::TcpStream;
#[cfg(all(unix, feature = "tokio"))]
use tokio::net::UnixStream;
#[cfg(windows)]
#[cfg(all(windows, not(feature = "tokio")))]
use uds_windows::UnixStream;

use zvariant::{ObjectPath, Str};
Expand Down Expand Up @@ -53,6 +53,12 @@ impl<'a> Builder<'a> {
/// If the default `async-io` feature is disabled, this method will expect
/// [`tokio::net::UnixStream`](https://docs.rs/tokio/latest/tokio/net/struct.UnixStream.html)
/// argument.
///
/// Since tokio currently [does not support Unix domain sockets][tuds] on Windows, this method
/// is not available when the `tokio` feature is enabled and building for Windows target.
///
/// [tuds]: https://github.com/tokio-rs/tokio/issues/2201
#[cfg(any(unix, not(feature = "tokio")))]
pub fn unix_stream(stream: UnixStream) -> Self {
Self(crate::connection::Builder::unix_stream(stream))
}
Expand Down
11 changes: 8 additions & 3 deletions zbus/src/connection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::net::TcpStream;
use tokio::net::UnixStream;
#[cfg(feature = "tokio-vsock")]
use tokio_vsock::VsockStream;
#[cfg(windows)]
#[cfg(all(windows, not(feature = "tokio")))]
use uds_windows::UnixStream;
#[cfg(all(feature = "vsock", not(feature = "tokio")))]
use vsock::VsockStream;
Expand All @@ -42,6 +42,7 @@ const DEFAULT_MAX_QUEUED: usize = 64;

#[derive(Debug)]
enum Target {
#[cfg(any(unix, not(feature = "tokio")))]
UnixStream(UnixStream),
TcpStream(TcpStream),
#[cfg(any(
Expand Down Expand Up @@ -138,6 +139,12 @@ impl<'a> Builder<'a> {
/// If the default `async-io` feature is disabled, this method will expect
/// [`tokio::net::UnixStream`](https://docs.rs/tokio/latest/tokio/net/struct.UnixStream.html)
/// argument.
///
/// Since tokio currently [does not support Unix domain sockets][tuds] on Windows, this method
/// is not available when the `tokio` feature is enabled and building for Windows target.
///
/// [tuds]: https://github.com/tokio-rs/tokio/issues/2201
#[cfg(any(unix, not(feature = "tokio")))]
pub fn unix_stream(stream: UnixStream) -> Self {
Self::new(Target::UnixStream(stream))
}
Expand Down Expand Up @@ -485,8 +492,6 @@ impl<'a> Builder<'a> {
Target::UnixStream(stream) => Async::new(stream)?.into(),
#[cfg(all(unix, feature = "tokio"))]
Target::UnixStream(stream) => stream.into(),
#[cfg(all(not(unix), feature = "tokio"))]
Target::UnixStream(_) => return Err(Error::Unsupported),
#[cfg(not(feature = "tokio"))]
Target::TcpStream(stream) => Async::new(stream)?.into(),
#[cfg(feature = "tokio")]
Expand Down

0 comments on commit 9f13788

Please sign in to comment.