#[throws(CSE)]
pub fn mainloop(mut self) {
use MgmtChannelReadError::*;
- let resp = match self.chan.read()? {
- Ok(Some(cmd)) => execute(&mut self, cmd),
+ let resp = match self.chan.read() {
+ Ok(Some(cmd)) => match execute(&mut self, cmd),
Err(IO(ioe)) => {
eprintln!("{}: io error reading: {}", &self.desc, ioe);
return;
}
- Err(ParseFailed(s)) => MgmtResponse::Error {
+ Err(Parse(s)) => MgmtResponse::Error {
error: MgmtError::ParseFailed(s),
},
};
- serde_lexpr::to_writer(&mut cs.write, &resp)?;
+ self.chan.write(&resp)?;
}
#[throws(MgmtError)]
Parse(String),
IO(#[from] io::Error),
}
-display_as_debug!{MgmtChannelError}
+display_as_debug!{MgmtChannelReadError}
#[derive(Clone,Debug)]
pub struct MgmtChannel<U : Read + Write> {
MgmtChannel { read, write }
}
- #[throws(MgmthannelReadError)]
- fn read<T>(&mut self) -> Option<T> {
+ #[throws(MgmtChannelReadError)]
+ pub fn read<T>(&mut self) -> Option<T> {
let lq = self.read.next().map_err(MgmtChannelReadError::IO)?;
let incoming : T = lq.map(
|l| serde_lexpr::from_str(l)
).collect().map_err(|e| MgmtChannelReadError::Parse("{}", &e))?;
incoming
}
+
+ #[throws(io::Error)]
+ pub fn write<T:Serialize>(&mut self, val: &T) {
+ serde_lexpr::to_writer(&mut self.write, val)?;
+ }
}
trait IoTryClone : Sized {