Skip to content

Commit

Permalink
fix pingpong
Browse files Browse the repository at this point in the history
  • Loading branch information
KKRainbow committed Jan 25, 2025
1 parent b829577 commit 0f2fea1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ impl KcpConnectionState {
)
}

fn is_local_closed(&self) -> bool {
matches!(
self.fsm,
KcpConnectionFSM::LocalClosed | KcpConnectionFSM::Closed
)
}

fn is_closed(&self) -> bool {
matches!(self.fsm, KcpConnectionFSM::Closed)
}
Expand Down Expand Up @@ -480,10 +487,6 @@ impl KcpEndpoint {
async move {
while let Some(packet) = input_receiver.recv().await {
tracing::trace!("recv packet: {:?}", packet);
if Self::try_handle_pingpong(&data, &packet, &output_sender).await {
continue;
}

let conv = ConnId::from(&packet);
if packet.header().is_data() && packet.payload().len() > 0 {
if let Some(mut conn) = data.conn_map.get_mut(&conv) {
Expand Down Expand Up @@ -525,6 +528,14 @@ impl KcpEndpoint {
}
} else {
let state = state.unwrap();

if !state.is_closed()
&& !state.is_local_closed()
&& Self::try_handle_pingpong(&data, &packet, &output_sender).await
{
continue;
}

let prev_established = state.is_established();
let ret = state.handle_packet(&packet);
tracing::trace!(?conv, ?state, "handle packet for conn, ret: {:?}", ret);
Expand Down

0 comments on commit 0f2fea1

Please sign in to comment.