Hi, I'm trying to handle multiple clients and stream some data for them. Here is what I'm doing right now:
let socket = TcpListener::bind("192.168.1.2:2424").await.unwrap();
while let Ok((tcp_stream, _)) = socket.accept().await {
println!("Dude Someone Triggered");
//Creating FiFo based data structure
let ring = HeapRb::<f32>::new(1000000);
let (producer, consumer) = ring.split();
let ws_stream = tokio_tungstenite::accept_async(tcp_stream).await.unwrap();
let timer = Instant::now();
//Spawn tasks for each client
tokio::spawn(record(producer)); //I produce data in this task
tokio::spawn(stream(timer, ws_stream, consumer));
//I send produced data to client in this "stream" task
//basically just pop the produced data in consumer and send via
//ws_stream.send(data.into()).await.unwrap();
//ws_stream.flush().await.unwrap();
}
What I want to do is, creating epoll mechanism. I don't want to create task for each client but handle with epoll. I want to do this because of performance reason and handling data to multiple client without struggling data transfer between threads. I saw poll_accept in tokio but not sure how can I use it or it's usable with websocket ?
And please correct me, if I'm in the wrong pattern.