mirror of
https://github.com/guilhermewerner/mini-redis
synced 2025-06-16 23:15:06 +00:00
Implement Some Tokio Tutorials
This commit is contained in:
21
Tutorial/EchoCopy.rs
Normal file
21
Tutorial/EchoCopy.rs
Normal file
@ -0,0 +1,21 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use tokio::io;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
let mut listener = TcpListener::bind("127.0.0.1:6142").await.unwrap();
|
||||
|
||||
loop {
|
||||
let (mut socket, _) = listener.accept().await?;
|
||||
|
||||
tokio::spawn(async move {
|
||||
let (mut rd, mut wr) = socket.split();
|
||||
|
||||
if io::copy(&mut rd, &mut wr).await.is_err() {
|
||||
eprintln!("failed to copy");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user