Skip to content

Commit

Permalink
Improve finish race condition management
Browse files Browse the repository at this point in the history
  • Loading branch information
SajjadPourali committed Mar 29, 2024
1 parent 0ce1b9a commit 8a30d36
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/stream/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ impl AsyncRead for IpStackTcpStream {
self.packet_to_send =
Some(self.create_rev_packet(FIN | ACK, TTL, None, Vec::new())?);
self.tcb.add_seq_one();
self.tcb.add_ack(1);
self.tcb.change_state(TcpState::FinWait2(true));
continue;
} else if matches!(self.shutdown, Shutdown::Pending(_))
Expand Down Expand Up @@ -410,22 +411,21 @@ impl AsyncRead for IpStackTcpStream {
} else if matches!(self.tcb.get_state(), TcpState::FinWait1(false)) {
if t.flags() == ACK {
self.tcb.change_last_ack(t.inner().acknowledgment_number);
self.tcb.add_ack(1);
self.tcb.change_state(TcpState::FinWait2(true));
continue;
} else if t.flags() == (FIN | ACK) {
self.tcb.add_seq_one();
self.tcb.add_ack(1);
self.packet_to_send =
Some(self.create_rev_packet(ACK, TTL, None, Vec::new())?);
self.tcb.change_send_window(t.inner().window_size);
self.tcb.change_state(TcpState::FinWait2(false));
self.tcb.change_state(TcpState::FinWait2(true));
continue;
}
} else if matches!(self.tcb.get_state(), TcpState::FinWait2(true)) {
if t.flags() == ACK {
self.tcb.change_state(TcpState::FinWait2(false));
} else if t.flags() == (FIN | ACK) {
self.tcb.add_ack(1);
self.packet_to_send =
Some(self.create_rev_packet(ACK, TTL, None, Vec::new())?);
self.tcb.change_state(TcpState::FinWait2(false));
Expand Down Expand Up @@ -468,7 +468,6 @@ impl AsyncWrite for IpStackTcpStream {
let seq = self.tcb.seq;
let payload_len = packet.payload.len();
let payload = packet.payload.clone();

self.packet_sender
.send(packet)
.or(Err(ErrorKind::UnexpectedEof))?;
Expand Down

0 comments on commit 8a30d36

Please sign in to comment.