Skip to content

narrowlink/uds-stream-windows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UDS-STREAM-WINDOWS

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.

FEATURES

  • AsyncRead/AsyncWrite: uds-stream-windows provides UdsStream and UdsListener that integrate seamlessly with the tokio ecosystem, allowing you to use standard AsyncReadExt and AsyncWriteExt methods.
  • Native Windows Support: Specifically designed for Windows, utilizing WSAEventSelect and registration for asynchronous I/O completion.
  • Simple API: The API is designed to be familiar to users of tokio::net::UnixStream and tokio::net::UnixListener.

USAGE

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:

Client Example

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(())
}

Server Example

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;
            }
        });
    }
}

CONTRIBUTING

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.

LICENSE

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.

About

Tokio-based Unix Domain Socket (UDS) for Windows with AsyncRead/AsyncWrite support

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages