uds-stream-windows is a Rust library that provides a Tokio-compatible Unix Domain Socket (UDS) implementation for Windows, offering UdsListener and UdsStream types that implement AsyncRead and AsyncWrite. It leverages the native AF_UNIX support introduced in recent Windows versions, making it easy to work with Unix Domain Sockets on Windows just as you would on Unix-like systems.
- AsyncRead/AsyncWrite:
uds-stream-windowsprovidesUdsStreamandUdsListenerthat integrate seamlessly with thetokioecosystem, allowing you to use standardAsyncReadExtandAsyncWriteExtmethods. - Native Windows Support: Specifically designed for Windows, utilizing
WSAEventSelectand registration for asynchronous I/O completion. - Simple API: The API is designed to be familiar to users of
tokio::net::UnixStreamandtokio::net::UnixListener.
To use uds-stream-windows in your Rust project, add it as a dependency in your Cargo.toml file:
[dependencies]
uds-stream-windows = "0.0.1"Then, you can use it in your Rust code:
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use uds_stream_windows::UdsStream;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let path = "example.sock";
let mut stream = UdsStream::connect(path).await?;
println!("Connected to {}", path);
let msg = "Hello from the Windows UDS client!";
stream.write_all(msg.as_bytes()).await?;
let mut buf = vec![0u8; 1024];
let n = stream.read(&mut buf).await?;
println!("Received: {}", String::from_utf8_lossy(&buf[..n]));
Ok(())
}use tokio::io::{AsyncReadExt, AsyncWriteExt};
use uds_stream_windows::UdsListener;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let path = "example.sock";
let listener = UdsListener::bind(path)?;
println!("Server listening on {}", path);
loop {
let (mut stream, addr) = listener.accept().await?;
tokio::spawn(async move {
let mut buf = [0u8; 1024];
if let Ok(n) = stream.read(&mut buf).await {
let _ = stream.write_all(&buf[..n]).await;
}
});
}
}Contributions to uds-stream-windows are welcome! If you would like to contribute to the library, please follow the standard Rust community guidelines for contributing, including opening issues, submitting pull requests, and providing feedback.
uds-stream-windows is licensed under the MIT License, which allows for free use, modification, and distribution, subject to the terms and conditions outlined in the license.