11# I/O Socket [ ![ Documentation] ( https://img.shields.io/docsrs/io-socket?style=flat&logo=docs.rs&logoColor=white )] ( https://docs.rs/io-socket/latest/io_socket ) [ ![ Matrix] ( https://img.shields.io/badge/chat-%23pimalaya-blue?style=flat&logo=matrix&logoColor=white )] ( https://matrix.to/#/#pimalaya:matrix.org ) [ ![ Mastodon] ( https://img.shields.io/badge/news-%40pimalaya-blue?style=flat&logo=mastodon&logoColor=white )] ( https://fosstodon.org/@pimalaya )
22
3- Set of ** I/O-free** Rust coroutines and runtimes to manage sockets.
3+ ** I/O-free** socket client library written in Rust
44
55This library provides an I/O-agnostic abstraction over sockets — both stream sockets (TCP, Unix) and datagram sockets (UDP) — based on three concepts:
66
@@ -40,16 +40,16 @@ let mut read = ReadSocket::new();
4040let (buf, n) = loop {
4141 match read.resume(arg.take()) {
4242 ReadSocketResult::Ok { buf, n } => break (buf, n),
43+ ReadSocketResult::Io { input } => arg = Some(handle(&mut stream, input).unwrap()),
4344 ReadSocketResult::Eof => break (vec![], 0),
4445 ReadSocketResult::Err { err } => panic!("{err}"),
45- ReadSocketResult::Io { input } => arg = Some(handle(&mut stream, input).unwrap()),
4646 }
4747};
4848
4949let bytes = &buf[..n];
5050```
5151
52- ### Write to a TCP stream (async Tokio )
52+ ### Write on a TCP stream (async)
5353
5454``` rust,ignore
5555use tokio::net::TcpStream;
@@ -67,9 +67,9 @@ let mut write = WriteSocket::new(b"GET / HTTP/1.0\r\n\r\n".to_vec());
6767loop {
6868 match write.resume(arg.take()) {
6969 WriteSocketResult::Ok { .. } => break,
70+ WriteSocketResult::Io { input } => arg = Some(handle(&mut stream, input).await.unwrap()),
7071 WriteSocketResult::Eof => panic!("connection closed"),
7172 WriteSocketResult::Err { err } => panic!("{err}"),
72- WriteSocketResult::Io { input } => arg = Some(handle(&mut stream, input).await.unwrap()),
7373 }
7474}
7575```
8080
8181Have a look at projects built on the top of this library:
8282
83+ - [ io-dns] ( https://github.com/pimalaya/io-dns ) : I/O-free DNS client library
8384- [ io-addressbook] ( https://github.com/pimalaya/io-addressbook ) : Set of I/O-free coroutines to manage contacts
8485- [ io-http] ( https://github.com/pimalaya/io-http ) : Set of I/O-free Rust coroutines to manage HTTP sockets
8586- [ io-oauth] ( https://github.com/pimalaya/io-oauth ) : Set of I/O-free Rust coroutines to manage OAuth flows
0 commit comments