#io #cross-platform #socketpair

socketpair

Cross-platform socketpair functionality

32 releases (19 breaking)

0.19.4 Dec 30, 2023
0.19.3 Jun 28, 2023
0.19.2 Apr 6, 2023
0.19.1 Mar 29, 2023
0.6.1 Mar 4, 2021

#427 in Rust patterns

Download history 749/week @ 2023-10-27 634/week @ 2023-11-03 748/week @ 2023-11-10 503/week @ 2023-11-17 598/week @ 2023-11-24 675/week @ 2023-12-01 814/week @ 2023-12-08 646/week @ 2023-12-15 617/week @ 2023-12-22 410/week @ 2023-12-29 905/week @ 2024-01-05 532/week @ 2024-01-12 605/week @ 2024-01-19 563/week @ 2024-01-26 441/week @ 2024-02-02 510/week @ 2024-02-09

2,268 downloads per month
Used in 9 crates (5 directly)

Apache-2.0…

47KB
1K SLoC

socketpair

Cross-platform socketpair functionality

Github Actions CI Status crates.io page docs.rs docs

This crate wraps socketpair with AF_UNIX platforms, and emulates this interface using CreateNamedPipe on Windows.

It has a "stream" interface, which corresponds to SOCK_STREAM and PIPE_TYPE_BYTE, and a "seqpacket" interface, which corresponds to SOCK_SEQPACKET and PIPE_TYPE_MESSAGE.

Example

let (mut a, mut b) = socketpair_stream()?;

writeln!(a, "hello world")?;

let mut buf = [0_u8; 4096];
let n = b.read(&mut buf)?;
assert_eq!(str::from_utf8(&buf[..n]).unwrap(), "hello world\n");

Support for async-std and tokio is temporarily disabled until those crates contain the needed implementations of the I/O safety traits.

Dependencies

~2–16MB
~189K SLoC