Crates.io | winpipe |
lib.rs | winpipe |
version | 0.1.1 |
source | src |
created_at | 2024-10-06 14:51:58.781979 |
updated_at | 2024-10-16 09:19:57.82398 |
description | Blocking rust wrapper for Windows named pipes with very similar api to UnixStream/UnixListen. |
homepage | |
repository | https://github.com/AlexanderSchuetz97/winpipe |
max_upload_size | |
id | 1399133 |
size | 90,414 |
Blocking rust wrapper for Windows named pipes with very similar api to UnixStream/UnixListen.
use winpipe::WinListener;
use std::io;
use std::io::{Read, Write};
use std::time::Duration;
fn listen_for_pipes() -> io::Result<()>{
let listener = WinListener::bind("\\\\.\\pipe\\my_pipe_is_cool")?;
loop {
let (mut stream, _addr) = listener.accept()?;
stream.set_write_timeout(Some(Duration::from_millis(5000)))?;
stream.set_read_timeout(Some(Duration::from_millis(5000)))?;
stream.write("Hello World".as_bytes())?;
let mut buffer = vec![0u8; 64];
let received = stream.read(buffer.as_mut_slice())?;
println!("Received {:?}", &buffer[..received])
//DROPPING Closes the pipe
}
}
use winpipe::WinStream;
use std::io;
use std::io::{Read, Write};
use std::time::Duration;
fn connect_pipe() -> io::Result<()>{
let mut stream = WinStream::connect("\\\\.\\pipe\\my_pipe_is_cool")?;
stream.set_write_timeout(Some(Duration::from_millis(5000)))?;
stream.set_read_timeout(Some(Duration::from_millis(5000)))?;
stream.write("Hello World".as_bytes())?;
let mut buffer = vec![0u8; 64];
let received = stream.read(buffer.as_mut_slice())?;
println!("Received {:?}", &buffer[..received]);
//DROPPING Closes the pipe
Ok(())
}
Create type aliases for UnixListen, UnixStream and unix::SocketAddress. On Unix targets let the alias point to the implementations of the stdlib. On Windows targets let the alias point to WinListen, WinStream and WinPipeSocketAddress.
You should only require very few conditional compilation blocks as long as you do not use the advanced features of Unix Sockets (such as for example sharing file descriptors).
WinStream::connect_with_timeout
. At least 1 attempt to connect will always be made!log
crate to log all system calls using the trace! macro.