-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement the tcp interface of wasi-sockets.
#6837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sunfishcode
merged 16 commits into
bytecodealliance:main
from
sunfishcode:sunfishcode/sockets
Aug 23, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
008e550
Implement the `tcp` interface of wasi-sockets.
sunfishcode bd3fe3e
Minor cleanups.
sunfishcode c6765e5
Update to the latest upstream wasi-sockets.
sunfishcode 73cbde9
Address review feedback.
sunfishcode 58b5b08
Handle zero-length reads and writes, and other cleanups.
sunfishcode 7c11589
Fix compilation on macOS.
sunfishcode eca3cc6
Fix compilation on Windows.
sunfishcode 151f80a
Update all the copies of wasi-socket wit files.
sunfishcode bffaf9d
Sync up more wit files.
sunfishcode 1ca4763
Fix the errno code for non-blocking `connect` on Windows.
sunfishcode 1c746b1
Tolerate `NOTCONN` errors when cleaning up with `shutdown`.
sunfishcode c2f07c1
Simplify the polling mechanism.
sunfishcode ebe48ca
Downgrade to tokio 1.29.1 for now.
sunfishcode 9aaa507
Move `tcp_state` out of the `Arc`.
sunfishcode 4efaaa9
`accept` doesn't need a write lock.
sunfishcode c696aa8
Remove `tcp_state`'s `RwLock`.
sunfishcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| #![cfg(all(feature = "test_programs", not(skip_wasi_sockets_tests)))] | ||
| use cap_std::ambient_authority; | ||
| use wasmtime::component::Linker; | ||
| use wasmtime::{Config, Engine, Store}; | ||
| use wasmtime_wasi::preview2::{self, command::Command, Table, WasiCtx, WasiCtxBuilder, WasiView}; | ||
|
|
||
| lazy_static::lazy_static! { | ||
| static ref ENGINE: Engine = { | ||
| let mut config = Config::new(); | ||
| config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable); | ||
| config.wasm_component_model(true); | ||
| config.async_support(true); | ||
|
|
||
| let engine = Engine::new(&config).unwrap(); | ||
| engine | ||
| }; | ||
| } | ||
| // uses ENGINE, creates a fn get_component(&str) -> Component | ||
| include!(concat!( | ||
| env!("OUT_DIR"), | ||
| "/wasi_sockets_tests_components.rs" | ||
| )); | ||
|
|
||
| struct SocketsCtx { | ||
| table: Table, | ||
| wasi: WasiCtx, | ||
| } | ||
|
|
||
| impl WasiView for SocketsCtx { | ||
| fn table(&self) -> &Table { | ||
| &self.table | ||
| } | ||
| fn table_mut(&mut self) -> &mut Table { | ||
| &mut self.table | ||
| } | ||
| fn ctx(&self) -> &WasiCtx { | ||
| &self.wasi | ||
| } | ||
| fn ctx_mut(&mut self) -> &mut WasiCtx { | ||
| &mut self.wasi | ||
| } | ||
| } | ||
|
|
||
| async fn run(name: &str) -> anyhow::Result<()> { | ||
| let component = get_component(name); | ||
| let mut linker = Linker::new(&ENGINE); | ||
|
|
||
| preview2::bindings::io::streams::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::poll::poll::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::exit::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::stdin::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::stdout::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::stderr::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::terminal_input::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::terminal_output::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::terminal_stdin::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::terminal_stdout::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::terminal_stderr::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::cli::environment::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::filesystem::types::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::filesystem::preopens::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::sockets::tcp::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::sockets::tcp_create_socket::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::sockets::network::add_to_linker(&mut linker, |x| x)?; | ||
| preview2::bindings::sockets::instance_network::add_to_linker(&mut linker, |x| x)?; | ||
|
|
||
| // Create our wasi context. | ||
| let mut table = Table::new(); | ||
| let wasi = WasiCtxBuilder::new() | ||
| .inherit_stdio() | ||
| .inherit_network(ambient_authority()) | ||
| .arg(name) | ||
| .build(&mut table)?; | ||
|
|
||
| let mut store = Store::new(&ENGINE, SocketsCtx { table, wasi }); | ||
|
|
||
| let (command, _instance) = Command::instantiate_async(&mut store, &component, &linker).await?; | ||
| command | ||
| .wasi_cli_run() | ||
| .call_run(&mut store) | ||
| .await? | ||
| .map_err(|()| anyhow::anyhow!("command returned with failing exit status")) | ||
| } | ||
|
|
||
| #[test_log::test(tokio::test(flavor = "multi_thread"))] | ||
| async fn tcp_v4() { | ||
| run("tcp_v4").await.unwrap(); | ||
| } | ||
|
|
||
| #[test_log::test(tokio::test(flavor = "multi_thread"))] | ||
| async fn tcp_v6() { | ||
| run("tcp_v6").await.unwrap(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [package] | ||
| name = "wasi-sockets-tests" | ||
| version = "0.0.0" | ||
| readme = "README.md" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| anyhow = { workspace = true } | ||
| wit-bindgen = { workspace = true, default-features = false, features = ["macros"] } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.