@@ -192,14 +192,17 @@ impl Retransmit {
192
192
}
193
193
}
194
194
195
- fn commit ( & mut self , timestamp : u64 ) {
195
+ fn commit ( & mut self , timestamp : u64 ) -> bool {
196
196
if self . delay == 0 {
197
197
self . delay = 100 ; // ms
198
198
self . resend_at = timestamp + self . delay ;
199
+ false
199
200
} else if timestamp >= self . resend_at {
200
- net_trace ! ( "retransmitting after a {}ms delay" , self . delay) ;
201
201
self . resend_at = timestamp + self . delay ;
202
202
self . delay *= 2 ;
203
+ true
204
+ } else {
205
+ false
203
206
}
204
207
}
205
208
}
@@ -636,16 +639,18 @@ impl<'a> TcpSocket<'a> {
636
639
( _, TcpRepr { control : TcpControl :: Rst , .. } ) => {
637
640
net_trace ! ( "tcp:{}:{}: received RST" ,
638
641
self . local_endpoint, self . remote_endpoint) ;
642
+ self . set_state ( State :: Closed ) ;
639
643
self . local_endpoint = IpEndpoint :: default ( ) ;
640
644
self . remote_endpoint = IpEndpoint :: default ( ) ;
641
- self . set_state ( State :: Closed ) ;
642
645
return Ok ( ( ) )
643
646
}
644
647
645
648
// SYN packets in the LISTEN state change it to SYN-RECEIVED.
646
649
( State :: Listen , TcpRepr {
647
650
src_port, dst_port, control : TcpControl :: Syn , seq_number, ack_number : None , ..
648
651
} ) => {
652
+ net_trace ! ( "tcp:{}: received SYN" ,
653
+ self . local_endpoint) ;
649
654
self . local_endpoint = IpEndpoint :: new ( ip_repr. dst_addr ( ) , dst_port) ;
650
655
self . remote_endpoint = IpEndpoint :: new ( ip_repr. src_addr ( ) , src_port) ;
651
656
// FIXME: use something more secure here
@@ -706,9 +711,9 @@ impl<'a> TcpSocket<'a> {
706
711
// ACK packets in LAST-ACK state change it to CLOSED.
707
712
( State :: LastAck , TcpRepr { control : TcpControl :: None , .. } ) => {
708
713
// Clear the remote endpoint, or we'll send an RST there.
714
+ self . set_state ( State :: Closed ) ;
709
715
self . remote_endpoint = IpEndpoint :: default ( ) ;
710
716
self . local_seq_no += 1 ;
711
- self . set_state ( State :: Closed ) ;
712
717
}
713
718
714
719
_ => {
@@ -858,7 +863,10 @@ impl<'a> TcpSocket<'a> {
858
863
}
859
864
860
865
if should_send {
861
- self . retransmit . commit ( timestamp) ;
866
+ if self . retransmit . commit ( timestamp) {
867
+ net_trace ! ( "tcp:{}:{}: retransmit after {}ms" ,
868
+ self . local_endpoint, self . remote_endpoint, self . retransmit. delay) ;
869
+ }
862
870
863
871
repr. ack_number = Some ( ack_number) ;
864
872
self . remote_last_ack = ack_number;
0 commit comments