Crates.io | safina-net |
lib.rs | safina-net |
version | 0.1.9 |
source | src |
created_at | 2020-12-29 08:09:51.761947 |
updated_at | 2024-10-27 23:32:20.966983 |
description | Safe async network functions - ARCHIVED: Code moved to `safina` crate. |
homepage | |
repository | https://gitlab.com/leonhard-llc/safina-rs |
max_upload_size | |
id | 328635 |
size | 49,036 |
This crate is archived and will not be updated.
The code is now at safina::net
in the safina
crate.
This is a safe Rust library for network communication.
It is part of safina
, a safe async runtime.
forbid(unsafe_code)
std
safina-executor
or any async executorAsyncRead
or AsyncWrite
implementations yet.let bind_addr =
std::net::SocketAddr::from(([127, 0, 0, 1], 0));
let mut listener =
safina_net::TcpListener::bind(&bind_addr)
.unwrap();
let addr = listener.inner().local_addr().unwrap();
println!("{}", &addr);
let executor = safina_executor::Executor::default();
executor.spawn(async move {
let mut tcp_stream =
safina_net::TcpStream::connect(addr)
.await
.unwrap();
let mut buf = String::new();
tcp_stream.read_to_string(&mut buf).await.unwrap();
println!("read {:?}", buf);
});
let (mut tcp_stream, _addr)
= listener.accept().await.unwrap();
tcp_stream.write_all(b"response").await.unwrap();
println!("wrote response");
For complete examples, see the integration tests in
tests/
.
async-net
unsafe
async-io
unsafe
tokio
unsafe
tcp-stream
unsafe
codesafina-executor
v0.3.1.safina-executor
v0.3.safina-executor
v0.2.EPROTOTYPE
errors on macOS.TcpStream
: peek
, read_vectored
, flush
, and write_vectored
.