handle ChannelClose

This commit is contained in:
nora 2022-02-20 21:50:50 +01:00
parent cb73214bc3
commit f2195133fb
6 changed files with 38 additions and 7 deletions

View file

@ -199,7 +199,6 @@ impl Connection {
loop {
debug!("Waiting for next frame");
let frame = frame::read_frame(&mut self.stream, self.max_frame_size).await?;
debug!(?frame);
self.reset_timeout();
match frame.kind {
@ -219,6 +218,7 @@ impl Connection {
// todo: handle closing
}
Method::ChannelOpen { .. } => self.channel_open(frame.channel).await?,
Method::ChannelClose { .. } => self.channel_close(frame.channel, method).await?,
_ => {
let channel_handle = self
.channels
@ -283,6 +283,27 @@ impl Connection {
Ok(())
}
async fn channel_close(&mut self, num: u16, method: Method) -> Result<()> {
if let Method::ChannelClose {
reply_code: code,
reply_text: reason,
..
} = method
{
info!(%code, %reason, "Closing channel");
if let Some(channel) = self.channels.remove(&num) {
drop(channel);
self.send_method(num, Method::ChannelCloseOk).await?;
} else {
return Err(ConException::Todo.into_trans());
}
} else {
unreachable!()
}
Ok(())
}
fn reset_timeout(&mut self) {
if self.heartbeat_delay != 0 {
let next = Duration::from_secs(u64::from(self.heartbeat_delay));