Skip to content

Commit ea0a55a

Browse files
committed
feat: implement TCP transport using wasi:sockets
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent 9cf6742 commit ea0a55a

16 files changed

Lines changed: 678 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 27 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ tracing = { version = "0.1", default-features = false }
127127
tracing-subscriber = { version = "0.3", default-features = false }
128128
url = { version = "2" }
129129
uuid = { version = "1", default-features = false }
130+
wasi = { version = "0.13", default-features = false }
130131
wasi-preview1-component-adapter-provider = { version = "25", default-features = false }
131132
wasm-tokio = { version = "0.6", default-features = false }
132133
wasmparser = { version = "0.218", default-features = false }

crates/transport/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ tracing = { workspace = true, features = ["attributes"] }
2727
send-future = { workspace = true }
2828
wasm-tokio = { workspace = true, features = ["tracing"] }
2929

30+
[target.'cfg(target_family = "wasm")'.dependencies]
31+
wasi = { workspace = true, features = ["std"] }
32+
3033
[dev-dependencies]
3134
test-log = { workspace = true, features = ["color", "log", "trace"] }
3235
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

crates/transport/src/frame/conn/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,5 +477,6 @@ async fn egress(
477477
trace!(?frame, "writing egress frame");
478478
tx.write_all_buf(&mut frame).await?;
479479
}
480-
Ok(())
480+
trace!("shutting down outgoing stream");
481+
tx.shutdown().await
481482
}

crates/transport/src/frame/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use bytes::Bytes;
77
mod codec;
88
mod conn;
99

10-
#[cfg(feature = "net")]
10+
#[cfg(any(target_family = "wasm", feature = "net"))]
1111
pub mod tcp;
12+
1213
#[cfg(all(unix, feature = "net"))]
1314
pub mod unix;
1415

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! wRPC TCP transport
2+
3+
#[cfg(feature = "net")]
4+
pub mod tokio;
5+
#[cfg(feature = "net")]
6+
pub use tokio::*;
7+
8+
#[cfg(target_family = "wasm")]
9+
pub mod wasi;
10+
#[cfg(all(target_family = "wasm", not(feature = "net")))]
11+
pub use wasi::*;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! TCP transport
1+
//! wRPC TCP transport using [tokio]
22
33
use core::net::SocketAddr;
44

@@ -17,16 +17,16 @@ use crate::Invoke;
1717
/// repeated calls with return an error
1818
pub struct Invocation(std::sync::Mutex<Option<TcpStream>>);
1919

20-
/// [Invoke] implementation of a TCP transport
20+
/// [Invoke] implementation of a TCP transport using [tokio]
2121
#[derive(Clone, Debug)]
2222
pub struct Client<T>(T);
2323

2424
impl<T> From<T> for Client<T>
2525
where
2626
T: ToSocketAddrs + Clone,
2727
{
28-
fn from(path: T) -> Self {
29-
Self(path)
28+
fn from(addr: T) -> Self {
29+
Self(addr)
3030
}
3131
}
3232

0 commit comments

Comments
 (0)