#cross-platform #seqpacket #io

socketpair

Cross-platform socketpair functionality

35 releases (19 breaking)

0.19.8 May 15, 2025
0.19.6 Mar 7, 2025
0.19.5 Mar 29, 2024
0.19.4 Dec 30, 2023
0.6.1 Mar 4, 2021

#528 in Rust patterns

Download history 2187/week @ 2025-10-15 4362/week @ 2025-10-22 4022/week @ 2025-10-29 3262/week @ 2025-11-05 3375/week @ 2025-11-12 3522/week @ 2025-11-19 3341/week @ 2025-11-26 4174/week @ 2025-12-03 5117/week @ 2025-12-10 3803/week @ 2025-12-17 2137/week @ 2025-12-24 2741/week @ 2025-12-31 4284/week @ 2026-01-07 4735/week @ 2026-01-14 3237/week @ 2026-01-21 4074/week @ 2026-01-28

17,009 downloads per month
Used in 29 crates (7 directly)

Apache-2.0…

51KB
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
~187K SLoC