wove/examples/tcp_echo.rs

77 lines
1.4 KiB
Rust

/*
use std::cell::RefCell;
use futures_lite::{FutureExt, StreamExt as FlStreamExt};
use futures_util::{
select, stream::FuturesUnordered, FutureExt as FuFutureExt, StreamExt as FuStreamExt,
};
use wove::{io::AsyncRead, io::AsyncWrite, Wove};
pub async fn go(wove: &Wove) -> std::io::Result<()> {
let mut listener = wove::net::TcpListener::bind(wove, "127.0.0.1:4838").await?;
let mut incoming = listener.incoming(wove);
let connections = RefCell::new(FuturesUnordered::new());
let mut accept = Box::pin(
async {
while let Some(connection) = FlStreamExt::next(&mut incoming).await {
let mut connection = connection?;
connections.borrow_mut().push(async move {
loop {
let data = connection
.read(wove, vec![0; 4096].into_boxed_slice())
.await?;
if data.len() == 0 {
break;
}
connection.write(wove, data).await?;
}
std::io::Result::Ok(())
});
}
std::io::Result::Ok(())
}
.fuse(),
);
let mut handle = Box::pin(
async {
while let Some(out) = FuStreamExt::next(&mut *connections.borrow_mut()).await {
out?;
}
std::io::Result::Ok(())
}
.fuse(),
);
loop {
select! {
res = handle => res?,
res = accept => res?,
}
}
}
pub fn main() {
let wove = Wove::new().unwrap();
let fut = async {
let run = async { wove.run().await? };
let go = go(&wove);
go.race(run).await
};
pollster::block_on(fut).unwrap();
}
*/
pub fn main() {
}