summaryrefslogtreecommitdiff
path: root/examples/echo.rs
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2022-10-31 17:03:10 +0800
committerluwenpeng <[email protected]>2022-11-03 14:30:58 +0800
commit9db73f57c452aa05da55211fd30af568a57857fc (patch)
tree237c6b2adaad64da7733638c7fd2ab0c9d88b7f2 /examples/echo.rs
parent54d9885220d2e0cd0167f6cbb10c7b0d9e762df2 (diff)
[delete] example/echo.rsHEADlwp-self-study
[update] src/lib.rs -- 增加调试日志 [update] src/main.rs -- 增加调试日志 [update] src/tcp.rs i -- 增加调试日志 [update] src/reactor.rs -- 增加调试日志 [update] src/executor.rs -- 增加调试日志
Diffstat (limited to 'examples/echo.rs')
-rw-r--r--examples/echo.rs37
1 files changed, 0 insertions, 37 deletions
diff --git a/examples/echo.rs b/examples/echo.rs
deleted file mode 100644
index 644627a..0000000
--- a/examples/echo.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-//! Echo example.
-//! Use `nc 127.0.0.1 30000` to connect.
-
-use futures::StreamExt;
-use mini_rust_runtime::executor::Executor;
-use mini_rust_runtime::tcp::TcpListener;
-use tokio::io::{AsyncReadExt, AsyncWriteExt};
-
-fn main() {
- let ex = Executor::new();
- ex.block_on(serve);
-}
-
-async fn serve() {
- let mut listener = TcpListener::bind("127.0.0.1:30000").unwrap();
- while let Some(ret) = listener.next().await {
- if let Ok((mut stream, addr)) = ret {
- println!("accept a new connection from {} successfully", addr);
- let f = async move {
- let mut buf = [0; 4096];
- loop {
- match stream.read(&mut buf).await {
- Ok(n) => {
- if n == 0 || stream.write_all(&buf[..n]).await.is_err() {
- return;
- }
- }
- Err(_) => {
- return;
- }
- }
- }
- };
- Executor::spawn(f);
- }
- }
-}