-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
2,484 additions
and
521 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 @@ | ||
[package] | ||
name = "echo-server" | ||
version = "0.1.0" | ||
authors = ["Heyang Zhou <[email protected]>"] | ||
edition = "2018" | ||
|
||
[workspace] | ||
|
||
[dependencies] | ||
kernel-net = { path = "../../lib/kernel-net" } |
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,49 @@ | ||
#![feature(wasi_ext)] | ||
|
||
use kernel_net::{schedule, Epoll, Tcp4Listener, TcpStream}; | ||
use std::sync::Arc; | ||
|
||
fn do_echo(stream: Arc<TcpStream>, buf: Vec<u8>) { | ||
let stream2 = stream.clone(); | ||
stream.read_async(buf, move |result| match result { | ||
Ok(buf) => { | ||
if buf.len() == 0 { | ||
return; | ||
} | ||
let stream = stream2.clone(); | ||
stream2.write_all_async(buf, move |result| match result { | ||
Ok(buf) => { | ||
schedule(|| { | ||
do_echo(stream, buf); | ||
}); | ||
} | ||
Err(code) => { | ||
println!("failed to write; code = {}", code); | ||
} | ||
}); | ||
} | ||
Err(code) => { | ||
println!("failed to read; code = {}", code); | ||
} | ||
}); | ||
} | ||
|
||
fn main() { | ||
let epoll = Arc::new(Epoll::new()); | ||
let listener = Arc::new(Tcp4Listener::new("0.0.0.0", 2001, 128).unwrap()); | ||
|
||
listener.accept_async(epoll.clone(), |stream| match stream { | ||
Ok(stream) => { | ||
do_echo(stream, Vec::with_capacity(16384)); | ||
Ok(()) | ||
} | ||
Err(code) => { | ||
println!("failed to accept; code = {}", code); | ||
Err(()) | ||
} | ||
}); | ||
println!("start epoll"); | ||
unsafe { | ||
epoll.run(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
[package] | ||
name = "http-server" | ||
version = "0.1.0" | ||
authors = ["Heyang Zhou <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[workspace] | ||
|
||
[dependencies] | ||
kernel-net = { path = "../../lib/kernel-net" } |
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,72 @@ | ||
#![feature(wasi_ext)] | ||
|
||
use kernel_net::{schedule, Epoll, Tcp4Listener, TcpStream}; | ||
use std::sync::Arc; | ||
|
||
fn serve(stream: Arc<TcpStream>, mut all: Vec<u8>) { | ||
let stream2 = stream.clone(); | ||
stream.read_async( | ||
Vec::with_capacity(512), | ||
move |result| { | ||
match result { | ||
Ok(buf) => { | ||
if buf.len() == 0 { | ||
return; | ||
} | ||
all.extend_from_slice(&buf); | ||
if all.len() > 4096 { | ||
println!("header too large"); | ||
return; | ||
} | ||
let s = match ::std::str::from_utf8(&all) { | ||
Ok(x) => x, | ||
Err(e) => { | ||
println!("not utf8: {:?}", e); | ||
return; | ||
} | ||
}; | ||
if let Some(_pos) = s.find("\r\n\r\n") { | ||
let body = format!( | ||
"Hello, world!\n", | ||
).into_bytes(); | ||
let stream = stream2.clone(); | ||
stream2.write_all_async( | ||
format!( | ||
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: close\r\nContent-Length: {}\r\n\r\n", | ||
body.len() | ||
).into_bytes(), | ||
|_| { | ||
stream.write_all_async(body, |_| {}); | ||
} | ||
); | ||
} else { | ||
schedule(|| serve(stream2, all)); | ||
} | ||
} | ||
Err(code) => { | ||
println!("failed to read; code = {}", code); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
fn main() { | ||
let epoll = Arc::new(Epoll::new()); | ||
let listener = Arc::new(Tcp4Listener::new("0.0.0.0", 2011, 128).unwrap()); | ||
|
||
listener.accept_async(epoll.clone(), |stream| match stream { | ||
Ok(stream) => { | ||
serve(stream, vec![]); | ||
Ok(()) | ||
} | ||
Err(code) => { | ||
println!("failed to accept; code = {}", code); | ||
Err(()) | ||
} | ||
}); | ||
println!("start epoll"); | ||
unsafe { | ||
epoll.run(); | ||
} | ||
} |
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,9 @@ | ||
[package] | ||
name = "pipe" | ||
version = "0.1.0" | ||
authors = ["Heyang Zhou <[email protected]>"] | ||
edition = "2018" | ||
|
||
[workspace] | ||
|
||
[dependencies] |
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,13 @@ | ||
use std::io::{Read, Write}; | ||
|
||
fn main() { | ||
let mut stdin = ::std::io::stdin(); | ||
let mut stdout = ::std::io::stdout(); | ||
let mut buf: Vec<u8> = vec![0; 512]; | ||
let mut total: u64 = 0; | ||
while total < 1048576u64 * 2048 { | ||
let n = stdin.read(&mut buf).unwrap(); | ||
stdout.write_all(&buf[..n]).unwrap(); | ||
total += n as u64; | ||
} | ||
} |
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,9 @@ | ||
[package] | ||
name = "wasmer-kernel-loader" | ||
version = "0.1.0" | ||
authors = ["Heyang Zhou <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
libc = "0.2.49" | ||
wasmer-runtime-core = { path = "../runtime-core" } |
Oops, something went wrong.