#io

socketpair

Cross-platform socketpair functionality

27 releases (breaking)

0.18.0 Nov 26, 2022
0.16.0 Jun 16, 2022
0.15.0 Mar 16, 2022
0.13.0 Dec 16, 2021
0.6.1 Mar 4, 2021

#226 in Rust patterns

Download history 49/week @ 2022-10-07 13/week @ 2022-10-14 28/week @ 2022-10-21 42/week @ 2022-10-28 134/week @ 2022-11-04 64/week @ 2022-11-11 67/week @ 2022-11-18 94/week @ 2022-11-25 33/week @ 2022-12-02 87/week @ 2022-12-09 50/week @ 2022-12-16 66/week @ 2022-12-23 17/week @ 2022-12-30 36/week @ 2023-01-06 15/week @ 2023-01-13 47/week @ 2023-01-20

126 downloads per month
Used in 6 crates (4 directly)

Apache-2.0…

46KB
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

~0.3–6.5MB
~109K SLoC