mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Make streams system
This commit is contained in:
@@ -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>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user