Skip to content

Commit

Permalink
fix: KCP session is closing while listener tries to input #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Banyc authored and zonyitoo committed Jun 12, 2023
1 parent 2ab3f2b commit 89979a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ impl KcpListener {
// if let Err(err) = kcp.input(packet) {
// error!("kcp.input failed, peer: {}, conv: {}, error: {}, packet: {:?}", peer_addr, conv, err, ByteStr::new(packet));
// }
session.input(packet).await;
if session.input(packet).await.is_err() {
trace!("[SESSION] KCP session is closing while listener tries to input");
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ impl KcpSession {
self.notify();
}

pub async fn input(&self, buf: &[u8]) {
self.input_tx.send(buf.to_owned()).await.expect("input channel closed")
pub async fn input(&self, buf: &[u8]) -> Result<(), SessionClosedError> {
self.input_tx.send(buf.to_owned()).await.map_err(|_| SessionClosedError)
}

pub async fn conv(&self) -> u32 {
Expand All @@ -269,6 +269,8 @@ impl KcpSession {
}
}

pub struct SessionClosedError;

struct KcpSessionUniq(Arc<KcpSession>);

impl Drop for KcpSessionUniq {
Expand Down

0 comments on commit 89979a8

Please sign in to comment.