Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/sunfishcode/socketpair
- Owner: sunfishcode
- License: other
- Created: 2021-01-12T16:49:54.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-29T20:41:49.000Z (8 months ago)
- Last Synced: 2024-10-25T00:18:23.066Z (20 days ago)
- Topics: library, rust
- Language: Rust
- Homepage:
- Size: 111 KB
- Stars: 15
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
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