Move local state queries to its own module

This commit is contained in:
Santiago Carmuega 2021-11-29 08:23:58 -03:00
parent ff8743023b
commit 22b19e4cf3
5 changed files with 100 additions and 86 deletions

View file

@ -1,14 +1,8 @@
mod bearers;
use std::{
collections::HashMap,
io::{Read, Write},
sync::mpsc::{self, Receiver, Sender, TryRecvError},
thread::{self, JoinHandle},
time::{Duration, Instant},
};
use std::{collections::HashMap, io::{Read, Write}, sync::mpsc::{self, Receiver, Sender, TryRecvError}, thread::{self, JoinHandle}, time::{Duration, Instant}};
use log::{debug, error, warn};
use log::{debug, error, trace, warn};
pub trait Bearer: Read + Write + Send + Sync + Sized {
fn read_segment(&mut self) -> Result<(u16, u32, Payload), std::io::Error>;
@ -27,9 +21,6 @@ const MAX_SEGMENT_PAYLOAD_LENGTH: usize = 65535;
pub type Payload = Vec<u8>;
#[derive(Debug)]
pub struct Error {}
fn tx_round<TBearer>(
bearer: &mut TBearer,
ingress: &MuxIngress,
@ -52,7 +43,7 @@ where
}
Err(TryRecvError::Disconnected) => {
//TODO: remove handle from list
warn!("protocol handle disconnected");
trace!("protocol handle {} disconnected", id);
}
Err(TryRecvError::Empty) => (),
};
@ -124,7 +115,7 @@ pub struct Multiplexer {
}
impl Multiplexer {
pub fn setup<TBearer>(bearer: TBearer, protocols: &[u16]) -> Result<Multiplexer, Error>
pub fn setup<TBearer>(bearer: TBearer, protocols: &[u16]) -> Result<Multiplexer, Box<dyn std::error::Error>>
where
TBearer: Bearer + 'static,
{