Make streams system

This commit is contained in:
Michael Mikovsky
2025-11-25 17:31:09 -07:00
parent 6863e08a0a
commit b43f2f5181
10 changed files with 395 additions and 202 deletions
+17 -4
View File
@@ -1,6 +1,8 @@
mod connection;
// mod connection;
mod tcp_stream;
pub use tcp_stream::TcpStream;
pub use connection::Connection;
// pub use connection::Connection;
use crate::ModuleError;
@@ -9,8 +11,19 @@ pub trait Stream<T>: Send + Sync {
// fn get_info(&self) -> String;
fn is_alive(&self) -> bool;
fn len(&self) -> usize;
fn read(&self) -> Vec<T>;
fn has_recv(&self) -> bool;
/// Possibly blocking stream read function
fn read(&mut self) -> Vec<T>;
/// Non-blocking read function
fn try_read(&mut self) -> Vec<T> {
if self.has_recv() {
self.read()
} else {
Vec::new()
}
}
fn write(&mut self, data: T) -> Result<(), ModuleError>;