@@ -1493,6 +1493,7 @@ impl<'a> TcpSocket<'a> {
1493
1493
// from the sequence space.
1494
1494
let mut ack_len = 0 ;
1495
1495
let mut ack_of_fin = false ;
1496
+ let mut ack_all = false ;
1496
1497
if repr. control != TcpControl :: Rst {
1497
1498
if let Some ( ack_number) = repr. ack_number {
1498
1499
// Sequence number corresponding to the first byte in `tx_buffer`.
@@ -1514,6 +1515,8 @@ impl<'a> TcpSocket<'a> {
1514
1515
) ;
1515
1516
ack_of_fin = true ;
1516
1517
}
1518
+
1519
+ ack_all = self . remote_last_seq == ack_number
1517
1520
}
1518
1521
1519
1522
self . rtte . on_ack ( cx. now ( ) , ack_number) ;
@@ -1643,7 +1646,7 @@ impl<'a> TcpSocket<'a> {
1643
1646
// ACK packets in ESTABLISHED state reset the retransmit timer,
1644
1647
// except for duplicate ACK packets which preserve it.
1645
1648
( State :: Established , TcpControl :: None ) => {
1646
- if !self . timer . is_retransmit ( ) || ack_len != 0 {
1649
+ if !self . timer . is_retransmit ( ) || ack_all {
1647
1650
self . timer . set_for_idle ( cx. now ( ) , self . keep_alive ) ;
1648
1651
}
1649
1652
}
@@ -1662,7 +1665,9 @@ impl<'a> TcpSocket<'a> {
1662
1665
if ack_of_fin {
1663
1666
self . set_state ( State :: FinWait2 ) ;
1664
1667
}
1665
- self . timer . set_for_idle ( cx. now ( ) , self . keep_alive ) ;
1668
+ if ack_all {
1669
+ self . timer . set_for_idle ( cx. now ( ) , self . keep_alive ) ;
1670
+ }
1666
1671
}
1667
1672
1668
1673
// FIN packets in FIN-WAIT-1 state change it to CLOSING, or to TIME-WAIT
@@ -5137,6 +5142,85 @@ mod test {
5137
5142
recv ! ( s, time 1550 , Err ( Error :: Exhausted ) ) ;
5138
5143
}
5139
5144
5145
+ #[ test]
5146
+ fn test_data_retransmit_bursts_half_ack ( ) {
5147
+ let mut s = socket_established ( ) ;
5148
+ s. remote_mss = 6 ;
5149
+ s. send_slice ( b"abcdef012345" ) . unwrap ( ) ;
5150
+
5151
+ recv ! ( s, time 0 , Ok ( TcpRepr {
5152
+ control: TcpControl :: None ,
5153
+ seq_number: LOCAL_SEQ + 1 ,
5154
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5155
+ payload: & b"abcdef" [ ..] ,
5156
+ ..RECV_TEMPL
5157
+ } ) , exact) ;
5158
+ recv ! ( s, time 0 , Ok ( TcpRepr {
5159
+ control: TcpControl :: Psh ,
5160
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5161
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5162
+ payload: & b"012345" [ ..] ,
5163
+ ..RECV_TEMPL
5164
+ } ) , exact) ;
5165
+ // Acknowledge the first packet
5166
+ send ! ( s, time 5 , TcpRepr {
5167
+ seq_number: REMOTE_SEQ + 1 ,
5168
+ ack_number: Some ( LOCAL_SEQ + 1 + 6 ) ,
5169
+ window_len: 6 ,
5170
+ ..SEND_TEMPL
5171
+ } ) ;
5172
+ // The second packet should be re-sent.
5173
+ recv ! ( s, time 1500 , Ok ( TcpRepr {
5174
+ control: TcpControl :: Psh ,
5175
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5176
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5177
+ payload: & b"012345" [ ..] ,
5178
+ ..RECV_TEMPL
5179
+ } ) , exact) ;
5180
+
5181
+ recv ! ( s, time 1550 , Err ( Error :: Exhausted ) ) ;
5182
+ }
5183
+
5184
+ #[ test]
5185
+ fn test_data_retransmit_bursts_half_ack_close ( ) {
5186
+ let mut s = socket_established ( ) ;
5187
+ s. remote_mss = 6 ;
5188
+ s. send_slice ( b"abcdef012345" ) . unwrap ( ) ;
5189
+ s. close ( ) ;
5190
+
5191
+ recv ! ( s, time 0 , Ok ( TcpRepr {
5192
+ control: TcpControl :: None ,
5193
+ seq_number: LOCAL_SEQ + 1 ,
5194
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5195
+ payload: & b"abcdef" [ ..] ,
5196
+ ..RECV_TEMPL
5197
+ } ) , exact) ;
5198
+ recv ! ( s, time 0 , Ok ( TcpRepr {
5199
+ control: TcpControl :: Fin ,
5200
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5201
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5202
+ payload: & b"012345" [ ..] ,
5203
+ ..RECV_TEMPL
5204
+ } ) , exact) ;
5205
+ // Acknowledge the first packet
5206
+ send ! ( s, time 5 , TcpRepr {
5207
+ seq_number: REMOTE_SEQ + 1 ,
5208
+ ack_number: Some ( LOCAL_SEQ + 1 + 6 ) ,
5209
+ window_len: 6 ,
5210
+ ..SEND_TEMPL
5211
+ } ) ;
5212
+ // The second packet should be re-sent.
5213
+ recv ! ( s, time 1500 , Ok ( TcpRepr {
5214
+ control: TcpControl :: Fin ,
5215
+ seq_number: LOCAL_SEQ + 1 + 6 ,
5216
+ ack_number: Some ( REMOTE_SEQ + 1 ) ,
5217
+ payload: & b"012345" [ ..] ,
5218
+ ..RECV_TEMPL
5219
+ } ) , exact) ;
5220
+
5221
+ recv ! ( s, time 1550 , Err ( Error :: Exhausted ) ) ;
5222
+ }
5223
+
5140
5224
#[ test]
5141
5225
fn test_send_data_after_syn_ack_retransmit ( ) {
5142
5226
let mut s = socket_syn_received ( ) ;
0 commit comments