forked from tokio-rs/mio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add networking for target_os = "wasi"
With * bytecodealliance/wasmtime#3711 * rust-lang/rust#93158 merged, mio can have limited support for networking for the `wasm32-wasi` target. Signed-off-by: Harald Hoyer <harald@profian.com>
- Loading branch information
Showing
5 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,45 @@ | ||
#![allow(dead_code)] | ||
|
||
use std::io; | ||
|
||
/// A lot of function are not support on Wasi, this function returns a | ||
/// consistent error when calling those functions. | ||
fn unsupported() -> io::Error { | ||
io::Error::new(io::ErrorKind::Other, "not supported on wasi") | ||
} | ||
|
||
pub(crate) mod tcp { | ||
use std::io; | ||
use std::net; | ||
|
||
use super::unsupported; | ||
|
||
pub type TcpSocket = wasi::Fd; | ||
|
||
pub(crate) fn new_for_addr(_address: net::SocketAddr) -> io::Result<i32> { | ||
Err(unsupported()) | ||
} | ||
|
||
pub(crate) fn bind(_: &net::TcpListener, _: net::SocketAddr) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn connect(_: &net::TcpStream, _: net::SocketAddr) -> io::Result<net::TcpStream> { | ||
Err(unsupported()) | ||
} | ||
|
||
pub(crate) fn listen(_: &net::TcpListener, _: u32) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn set_reuseaddr(_: &net::TcpListener, _: bool) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
pub(crate) fn accept( | ||
listener: &net::TcpListener, | ||
) -> io::Result<(net::TcpStream, net::SocketAddr)> { | ||
let res = listener.accept(); | ||
res | ||
} | ||
} | ||
|