Compare commits

..

No commits in common. "dd32b6fe3fcde2c37e7091325c36c19e0d31aab5" and "6590084a1f9c23c7a1381f0c43e492ea78d983ef" have entirely different histories.

1 changed files with 55 additions and 108 deletions

View File

@ -154,7 +154,7 @@ mod remote_coremgmt {
) -> Result<()> {
let mut buffer = Vec::new();
loop {
let reply = drtio::aux_transact(
match drtio::aux_transact(
aux_mutex,
linkno,
routing_table,
@ -164,10 +164,9 @@ mod remote_coremgmt {
},
timer,
)
.await;
match reply {
Ok(Packet::CoreMgmtGetLogReply { last, length, data }) => {
.await?
{
Packet::CoreMgmtGetLogReply { last, length, data } => {
buffer.extend(&data[..length as usize]);
if last {
write_i8(stream, Reply::LogContent as i8).await?;
@ -175,16 +174,10 @@ mod remote_coremgmt {
return Ok(());
}
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
write_i8(stream, Reply::Error as i8).await?;
return Err(drtio::Error::UnexpectedReply.into());
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
return Err(e.into());
}
}
}
}
@ -204,22 +197,16 @@ mod remote_coremgmt {
&Packet::CoreMgmtClearLogRequest { destination },
timer,
)
.await;
.await?;
match reply {
Ok(Packet::CoreMgmtAck) => {
Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?;
Ok(())
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
write_i8(stream, Reply::Error as i8).await?;
Err(drtio::Error::UnexpectedReply.into())
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
Err(e.into())
return Err(drtio::Error::UnexpectedReply.into());
}
}
}
@ -245,7 +232,7 @@ mod remote_coremgmt {
break;
}
let reply = drtio::aux_transact(
match drtio::aux_transact(
aux_mutex,
linkno,
routing_table,
@ -255,20 +242,13 @@ mod remote_coremgmt {
},
timer,
)
.await;
match reply {
.await
{
Ok(Packet::CoreMgmtGetLogReply { last: _, length, data }) => {
write_chunk(stream, &data[..length as usize]).await?;
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
return Err(drtio::Error::UnexpectedReply.into());
}
Err(e) => {
error!("aux packet error ({})", e);
return Err(e.into());
}
_ => return Err(drtio::Error::UnexpectedReply.into()),
}
}
@ -294,22 +274,16 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
match reply {
Ok(Packet::CoreMgmtAck) => {
Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?;
Ok(())
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
write_i8(stream, Reply::Error as i8).await?;
Err(drtio::Error::UnexpectedReply.into())
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
Err(e.into())
return Err(drtio::Error::UnexpectedReply.into());
}
}
}
@ -333,22 +307,16 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
match reply {
Ok(Packet::CoreMgmtAck) => {
Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?;
Ok(())
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
write_i8(stream, Reply::Error as i8).await?;
Err(drtio::Error::UnexpectedReply.into())
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
Err(e.into())
return Err(drtio::Error::UnexpectedReply.into());
}
}
}
@ -378,12 +346,12 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
let mut buffer = Vec::<u8>::new();
loop {
match reply {
Ok(Packet::CoreMgmtConfigReadReply { last, length, value }) => {
Packet::CoreMgmtConfigReadReply { last, length, value } => {
buffer.extend(&value[..length as usize]);
if last {
@ -401,18 +369,13 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
write_i8(stream, Reply::Error as i8).await?;
return Err(drtio::Error::UnexpectedReply.into());
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
return Err(e.into());
}
}
}
}
@ -446,9 +409,9 @@ mod remote_coremgmt {
},
|reply| match reply {
Packet::CoreMgmtAck => Ok(()),
packet => {
error!("received unexpected aux packet: {:?}", packet);
Err(drtio::Error::UnexpectedReply)
_ => {
error!("received unknown packet");
Err(drtio::Error::UnexpectedReply.into())
}
},
)
@ -458,10 +421,9 @@ mod remote_coremgmt {
write_i8(stream, Reply::Success as i8).await?;
Ok(())
}
Err(e) => {
error!("aux packet error ({})", e);
error => {
write_i8(stream, Reply::Error as i8).await?;
Err(e.into())
error
}
}
}
@ -491,23 +453,17 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
match reply {
Ok(Packet::CoreMgmtAck) => {
Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?;
Ok(())
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
write_i8(stream, Reply::Error as i8).await?;
Err(drtio::Error::UnexpectedReply.into())
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
Err(e.into())
}
}
}
@ -528,23 +484,17 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
match reply {
Ok(Packet::CoreMgmtAck) => {
Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?;
Ok(())
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
write_i8(stream, Reply::Error as i8).await?;
Err(drtio::Error::UnexpectedReply.into())
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
Err(e.into())
}
}
}
@ -566,23 +516,18 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
match reply {
Ok(Packet::CoreMgmtAck) => {
Packet::CoreMgmtAck => {
write_i8(stream, Reply::RebootImminent as i8).await?;
Ok(())
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
error!("received unknown packet");
write_i8(stream, Reply::Error as i8).await?;
Err(drtio::Error::UnexpectedReply.into())
}
Err(e) => {
error!("aux packet error ({})", e);
write_i8(stream, Reply::Error as i8).await?;
Err(e.into())
}
}
}
@ -603,21 +548,18 @@ mod remote_coremgmt {
},
timer,
)
.await;
.await?;
match reply {
Ok(Packet::CoreMgmtAck) => {
Packet::CoreMgmtAck => {
write_i8(stream, Reply::Success as i8).await?;
Ok(())
}
Ok(packet) => {
error!("received unexpected aux packet: {:?}", packet);
_ => {
error!("received unknown packet");
write_i8(stream, Reply::Error as i8).await?;
Err(drtio::Error::UnexpectedReply.into())
}
Err(e) => {
error!("aux packet error ({})", e);
Err(e.into())
}
}
}
}
@ -639,7 +581,7 @@ mod local_coremgmt {
Ok(())
}
pub async fn pull_log(stream: &mut TcpStream, pull_id: &Rc<RefCell<u32>>) -> Result<()> {
pub async fn pull_log<'a>(stream: &'a mut TcpStream, pull_id: &Rc<RefCell<u32>>) -> Result<()> {
let id = {
let mut guard = pull_id.borrow_mut();
*guard += 1;
@ -696,7 +638,12 @@ mod local_coremgmt {
Ok(())
}
pub async fn config_write(stream: &mut TcpStream, cfg: &Rc<Config>, key: &String, value: Vec<u8>) -> Result<()> {
pub async fn config_write<'a>(
stream: &mut TcpStream,
cfg: &Rc<Config>,
key: &'a String,
value: Vec<u8>,
) -> Result<()> {
let value = cfg.write(&key, value);
if value.is_ok() {
debug!("write success");
@ -709,7 +656,7 @@ mod local_coremgmt {
Ok(())
}
pub async fn config_remove(stream: &mut TcpStream, cfg: &Rc<Config>, key: &String) -> Result<()> {
pub async fn config_remove<'a>(stream: &mut TcpStream, cfg: &Rc<Config>, key: &'a String) -> Result<()> {
let value = cfg.remove(&key);
if value.is_ok() {
debug!("erase success");