Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sunfishcode/socketpair

Cross-platform socketpair functionality
https://github.com/sunfishcode/socketpair

library rust

Last synced: 5 days ago
JSON representation

Cross-platform socketpair functionality

Awesome Lists containing this project

README

        


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

```rust
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.

[`socketpair`]: https://man7.org/linux/man-pages/man2/socketpair.2.html