X-Git-Url: https://code.octet-stream.net/m17rt/blobdiff_plain/2813fcb83452c7fd91d799a984613a616180a067..bd5155840661f90aab8c06413fb1e9f256824b55:/m17app/src/tnc.rs diff --git a/m17app/src/tnc.rs b/m17app/src/tnc.rs index 99bacc7..e7799b4 100644 --- a/m17app/src/tnc.rs +++ b/m17app/src/tnc.rs @@ -6,8 +6,20 @@ use std::io::{Read, Write}; /// via a working implementation of try_clone(). We do not require `Clone` directly /// as this could not be fulfilled by `TcpStream`. pub trait Tnc: Read + Write + Sized + Send + 'static { + /// Return a copy of this TNC. + /// + /// `M17App` will use this to create a second instance of the supplied TNC then use + /// one of them for reading and one of them for writing, concurrently across two threads. + /// + /// Implementations do not need to worry about trying to make two simultaneous reads or + /// two simultaneous writes do something sensible. `M17App` will not do this and it would + /// probably produce garbled KISS messages anyway. fn try_clone(&mut self) -> Result; + + /// Start I/O. fn start(&mut self) -> Result<(), TncError>; + + /// Shut down I/O - it is assumed we cannot restart. fn close(&mut self) -> Result<(), TncError>; } @@ -19,7 +31,7 @@ pub enum TncError { impl Tnc for std::net::TcpStream { fn try_clone(&mut self) -> Result { - self.try_clone().map_err(|_| TncError::Unknown) + std::net::TcpStream::try_clone(self).map_err(|_| TncError::Unknown) } fn start(&mut self) -> Result<(), TncError> {