|
|
|
@ -41,6 +41,10 @@ pub struct Transport {
|
|
|
|
|
impl Transport { |
|
|
|
|
/// Create new transport with given interfaces
|
|
|
|
|
pub fn new(interfaces: Vec<Box<dyn Interface>>) -> Self { |
|
|
|
|
#[cfg(not(std))] |
|
|
|
|
if interfaces.iter().map(|interface| interface.has_blocking_main() as u8).sum::<u8>() > 1 { |
|
|
|
|
panic!("There is two interfaces with blocking main loops and we have no threads because this is no_std!"); |
|
|
|
|
} |
|
|
|
|
Self { interfaces, peers: vec![] } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -123,6 +127,21 @@ impl Transport {
|
|
|
|
|
Some((msg, self.find_or_add_peer(interface_id, peer_data))) |
|
|
|
|
} else { None } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Run one iteration of the main loop
|
|
|
|
|
pub fn main_loop_iteration(&mut self) -> IFResult<()> { |
|
|
|
|
#[cfg(std)] |
|
|
|
|
self.interfaces.par_iter_mut().map(|interface| interface.main_loop_iteration()).collect::<IFResult<_>>()?; |
|
|
|
|
#[cfg(not(std))] |
|
|
|
|
{ |
|
|
|
|
self.interfaces.iter_mut().map(|interface| if !interface.has_blocking_main() { interface.main_loop_iteration() } else { Ok(()) }).collect::<IFResult<_>>()?; |
|
|
|
|
let blocking_interface_index = self.interfaces.iter().position(|interface| interface.has_blocking_main()); |
|
|
|
|
if let Some(ind) = blocking_interface_index { |
|
|
|
|
self.interfaces[ind].main_loop_iteration()?; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
|