@@ -1460,6 +1460,7 @@ impl<'a> Socket<'a> {
1460
1460
// from the sequence space.
1461
1461
let mut ack_len = 0 ;
1462
1462
let mut ack_of_fin = false ;
1463
+ let mut ack_all = false ;
1463
1464
if repr. control != TcpControl :: Rst {
1464
1465
if let Some ( ack_number) = repr. ack_number {
1465
1466
// Sequence number corresponding to the first byte in `tx_buffer`.
@@ -1477,6 +1478,8 @@ impl<'a> Socket<'a> {
1477
1478
tcp_trace ! ( "received ACK of FIN" ) ;
1478
1479
ack_of_fin = true ;
1479
1480
}
1481
+
1482
+ ack_all = self . remote_last_seq == ack_number
1480
1483
}
1481
1484
1482
1485
self . rtte . on_ack ( cx. now ( ) , ack_number) ;
@@ -1585,7 +1588,7 @@ impl<'a> Socket<'a> {
1585
1588
// ACK packets in ESTABLISHED state reset the retransmit timer,
1586
1589
// except for duplicate ACK packets which preserve it.
1587
1590
( State :: Established , TcpControl :: None ) => {
1588
- if !self . timer . is_retransmit ( ) || ack_len != 0 {
1591
+ if !self . timer . is_retransmit ( ) || ack_all {
1589
1592
self . timer . set_for_idle ( cx. now ( ) , self . keep_alive ) ;
1590
1593
}
1591
1594
}
@@ -1604,7 +1607,9 @@ impl<'a> Socket<'a> {
1604
1607
if ack_of_fin {
1605
1608
self . set_state ( State :: FinWait2 ) ;
1606
1609
}
1607
- self . timer . set_for_idle ( cx. now ( ) , self . keep_alive ) ;
1610
+ if ack_all {
1611
+ self . timer . set_for_idle ( cx. now ( ) , self . keep_alive ) ;
1612
+ }
1608
1613
}
1609
1614
1610
1615
// FIN packets in FIN-WAIT-1 state change it to CLOSING, or to TIME-WAIT
@@ -4979,6 +4984,85 @@ mod test {
4979
4984
recv_nothing ! ( s, time 1550 ) ;
4980
4985
}
4981
4986
4987
+ #[ test]
4988
+ fn test_data_retransmit_bursts_half_ack ( ) {
4989
+ let mut s = socket_established ( ) ;
4990
+ s. remote_mss = 6 ;
4991
+ s. send_slice ( b"abcdef012345" ) . unwrap ( ) ;
4992
+
4993
+ recv ! ( s, time 0 , Ok ( TcpRepr {
4994
+ control: TcpControl :: None ,
4995
+ seq_number: LOCAL_SEQ + 1 ,
4996
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
4997
+ payload: & b"abcdef" [ ..] ,
4998
+ ..RECV_TEMPL
4999
+ } ) , exact) ;
5000
+ recv ! ( s, time 0 , Ok ( TcpRepr {
5001
+ control: TcpControl :: Psh ,
5002
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5003
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5004
+ payload: & b"012345" [ ..] ,
5005
+ ..RECV_TEMPL
5006
+ } ) , exact) ;
5007
+ // Acknowledge the first packet
5008
+ send ! ( s, time 5 , TcpRepr {
5009
+ seq_number: REMOTE_SEQ + 1 ,
5010
+ ack_number: Some ( LOCAL_SEQ + 1 + 6 ) ,
5011
+ window_len: 6 ,
5012
+ ..SEND_TEMPL
5013
+ } ) ;
5014
+ // The second packet should be re-sent.
5015
+ recv ! ( s, time 1500 , Ok ( TcpRepr {
5016
+ control: TcpControl :: Psh ,
5017
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5018
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5019
+ payload: & b"012345" [ ..] ,
5020
+ ..RECV_TEMPL
5021
+ } ) , exact) ;
5022
+
5023
+ recv_nothing ! ( s, time 1550 ) ;
5024
+ }
5025
+
5026
+ #[ test]
5027
+ fn test_data_retransmit_bursts_half_ack_close ( ) {
5028
+ let mut s = socket_established ( ) ;
5029
+ s. remote_mss = 6 ;
5030
+ s. send_slice ( b"abcdef012345" ) . unwrap ( ) ;
5031
+ s. close ( ) ;
5032
+
5033
+ recv ! ( s, time 0 , Ok ( TcpRepr {
5034
+ control: TcpControl :: None ,
5035
+ seq_number: LOCAL_SEQ + 1 ,
5036
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5037
+ payload: & b"abcdef" [ ..] ,
5038
+ ..RECV_TEMPL
5039
+ } ) , exact) ;
5040
+ recv ! ( s, time 0 , Ok ( TcpRepr {
5041
+ control: TcpControl :: Fin ,
5042
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5043
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5044
+ payload: & b"012345" [ ..] ,
5045
+ ..RECV_TEMPL
5046
+ } ) , exact) ;
5047
+ // Acknowledge the first packet
5048
+ send ! ( s, time 5 , TcpRepr {
5049
+ seq_number: REMOTE_SEQ + 1 ,
5050
+ ack_number: Some ( LOCAL_SEQ + 1 + 6 ) ,
5051
+ window_len: 6 ,
5052
+ ..SEND_TEMPL
5053
+ } ) ;
5054
+ // The second packet should be re-sent.
5055
+ recv ! ( s, time 1500 , Ok ( TcpRepr {
5056
+ control: TcpControl :: Fin ,
5057
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5058
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5059
+ payload: & b"012345" [ ..] ,
5060
+ ..RECV_TEMPL
5061
+ } ) , exact) ;
5062
+
5063
+ recv_nothing ! ( s, time 1550 ) ;
5064
+ }
5065
+
4982
5066
#[ test]
4983
5067
fn test_send_data_after_syn_ack_retransmit ( ) {
4984
5068
let mut s = socket_syn_received ( ) ;
0 commit comments