adding network stream queuefor handling connections in a non blocking way

This commit is contained in:
michael-bailey 2021-03-21 22:42:35 +00:00
parent 592e630ee6
commit 77fe320aa7
1 changed files with 4 additions and 2 deletions

View File

@ -1,3 +1,5 @@
use std::collections::VecDeque;
use std::net::TcpStream;
use crate::client::Client;
use crate::messages::ServerMessage;
use std::io::BufWriter;
@ -14,6 +16,7 @@ use foundation::messages::network::{NetworkSockIn, NetworkSockOut};
pub struct NetworkManager {
listener: TcpListener,
connection_queue: VecDeque<TcpStream>,
server_channel: Sender<ServerMessage>,
}
@ -31,6 +34,7 @@ impl NetworkManager {
Arc::new(NetworkManager {
listener,
connection_queue: VecDeque::new(),
server_channel,
})
}
@ -40,7 +44,6 @@ impl ICooperative for NetworkManager {
fn tick(&self) {
println!("[NetworkManager]: Tick!");
// get all new connections
// handle each request
println!("[NetworkManager]: handling new connections!");
@ -63,7 +66,6 @@ impl ICooperative for NetworkManager {
writer.write_all(b"\n").unwrap_or_default();
writer.flush().unwrap_or_default();
// read the new request into a buffer
let res = reader.read_line(&mut buffer);
// if reading caused an error skip the connection