Skip to content

Commit

Permalink
Send incomplete fin packets even if nagle enabled
Browse files Browse the repository at this point in the history
If we have an incomplete packet to send and the socket has been closed
then send it. Without this change (with nagle enabled) we wait for the
penultimate packet in the stream to be acked before sending the final
packet even if there's plenty of space in the window.
  • Loading branch information
mbirtwell authored and SquidDev committed Nov 23, 2022
1 parent c79203a commit e51e750
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,12 @@ impl<'a> TcpSocket<'a> {
_ => false,
};

if self.nagle && data_in_flight && !can_send_full {
// If we're applying the Nagle algorithm we don't want to send more
// until one of:
// * There's no data in flight
// * We can send a full packet
// * We have all the data we'll ever send (we're closing send)
if self.nagle && data_in_flight && !can_send_full && !want_fin {
can_send = false;
}

Expand Down Expand Up @@ -7000,6 +7005,29 @@ mod test {
);
}

#[test]
fn test_final_packet_in_stream_doesnt_wait_for_nagle() {
let mut s = socket_established();
s.remote_mss = 6;
s.send_slice(b"abcdef0").unwrap();
s.socket.close();

recv!(s, time 0, Ok(TcpRepr {
control: TcpControl::None,
seq_number: LOCAL_SEQ + 1,
ack_number: Some(REMOTE_SEQ + 1),
payload: &b"abcdef"[..],
..RECV_TEMPL
}), exact);
recv!(s, time 0, Ok(TcpRepr {
control: TcpControl::Fin,
seq_number: LOCAL_SEQ + 1 + 6,
ack_number: Some(REMOTE_SEQ + 1),
payload: &b"0"[..],
..RECV_TEMPL
}), exact);
}

// =========================================================================================//
// Tests for packet filtering.
// =========================================================================================//
Expand Down

0 comments on commit e51e750

Please sign in to comment.