Skip to content

Commit

Permalink
feat: implement TCP transport using wasi:sockets
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Oct 18, 2024
1 parent 9cf6742 commit ea0a55a
Show file tree
Hide file tree
Showing 16 changed files with 678 additions and 9 deletions.
29 changes: 27 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
url = { version = "2" }
uuid = { version = "1", default-features = false }
wasi = { version = "0.13", default-features = false }
wasi-preview1-component-adapter-provider = { version = "25", default-features = false }
wasm-tokio = { version = "0.6", default-features = false }
wasmparser = { version = "0.218", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions crates/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tracing = { workspace = true, features = ["attributes"] }
send-future = { workspace = true }
wasm-tokio = { workspace = true, features = ["tracing"] }

[target.'cfg(target_family = "wasm")'.dependencies]
wasi = { workspace = true, features = ["std"] }

[dev-dependencies]
test-log = { workspace = true, features = ["color", "log", "trace"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
3 changes: 2 additions & 1 deletion crates/transport/src/frame/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,6 @@ async fn egress(
trace!(?frame, "writing egress frame");
tx.write_all_buf(&mut frame).await?;
}
Ok(())
trace!("shutting down outgoing stream");
tx.shutdown().await
}
3 changes: 2 additions & 1 deletion crates/transport/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use bytes::Bytes;
mod codec;
mod conn;

#[cfg(feature = "net")]
#[cfg(any(target_family = "wasm", feature = "net"))]
pub mod tcp;

#[cfg(all(unix, feature = "net"))]
pub mod unix;

Expand Down
11 changes: 11 additions & 0 deletions crates/transport/src/frame/tcp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! wRPC TCP transport
#[cfg(feature = "net")]
pub mod tokio;
#[cfg(feature = "net")]
pub use tokio::*;

#[cfg(target_family = "wasm")]
pub mod wasi;
#[cfg(all(target_family = "wasm", not(feature = "net")))]
pub use wasi::*;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! TCP transport
//! wRPC TCP transport using [tokio]
use core::net::SocketAddr;

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

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

impl<T> From<T> for Client<T>
where
T: ToSocketAddrs + Clone,
{
fn from(path: T) -> Self {
Self(path)
fn from(addr: T) -> Self {
Self(addr)
}
}

Expand Down
Loading

0 comments on commit ea0a55a

Please sign in to comment.