@@ -229,7 +229,7 @@ pub struct Connection {
229229 // Queued non-retransmittable 1-RTT data
230230 //
231231 /// If the CONNECTION_CLOSE frame needs to be sent
232- close : bool ,
232+ connection_close_pending : bool ,
233233
234234 //
235235 // ACK frequency
@@ -426,7 +426,7 @@ impl Connection {
426426 } ,
427427 timers : TimerTable :: default ( ) ,
428428 authentication_failures : 0 ,
429- close : false ,
429+ connection_close_pending : false ,
430430
431431 ack_frequency : AckFrequencyState :: new ( get_max_ack_delay (
432432 & TransportParameters :: default ( ) ,
@@ -987,7 +987,7 @@ impl Connection {
987987 StateType :: Draining | StateType :: Closed => {
988988 // self.close is only reset once the associated packet had been
989989 // encoded successfully
990- if !self . close {
990+ if !self . connection_close_pending {
991991 self . app_limited = true ;
992992 return None ;
993993 }
@@ -996,7 +996,7 @@ impl Connection {
996996 _ => false ,
997997 } ;
998998
999- // Check whether we need to send an ACK_FREQUENCY frame
999+ // Schedule an ACK_FREQUENCY frame if a new one needs to be sent.
10001000 if let Some ( config) = & self . config . ack_frequency_config {
10011001 let rtt = self
10021002 . paths
@@ -1036,15 +1036,8 @@ impl Connection {
10361036 && self . remote_cids . contains_key ( id)
10371037 } ) ;
10381038
1039- if let Some ( challenge) = self . send_prev_path_challenge ( now, buf, path_id) {
1040- return Some ( challenge) ;
1041- }
1042-
1043- // Send an off-path PATH_RESPONSE. Prioritized over on-path data to ensure that
1044- // path validation can occur while the link is saturated.
1045- // TODO(@divma): I have no idea what this comment is supposed to mean
1046- if let Some ( response) = self . send_off_path_path_response ( now, buf, path_id) {
1047- return Some ( response) ;
1039+ if let Some ( transmit) = self . poll_transmit_off_path ( now, buf, path_id) {
1040+ return Some ( transmit) ;
10481041 }
10491042
10501043 let mut space_id = match path_id {
@@ -1246,7 +1239,7 @@ impl Connection {
12461239 can_send. other ,
12471240 self ,
12481241 ) ?;
1249- last_packet_number = Some ( builder. exact_number ) ;
1242+ last_packet_number = Some ( builder. packet_number ) ;
12501243 coalesce = coalesce && builder. can_coalesce ;
12511244
12521245 if space_id == SpaceId :: Initial && ( self . side . is_client ( ) || can_send. other ) {
@@ -1314,7 +1307,7 @@ impl Connection {
13141307 if space_id == self . highest_space {
13151308 // Don't send another close packet. Even with multipath we only send
13161309 // CONNECTION_CLOSE on a single path since we expect our paths to work.
1317- self . close = false ;
1310+ self . connection_close_pending = false ;
13181311 // `CONNECTION_CLOSE` is the final packet
13191312 break ;
13201313 } else {
@@ -1409,8 +1402,11 @@ impl Connection {
14091402 } else {
14101403 builder. finish_and_track ( now, self , path_id, pad_datagram) ;
14111404 }
1405+
1406+ // If this is the first datagram we set the segment size to the size of the
1407+ // first datagram.
14121408 if transmit. num_datagrams ( ) == 1 {
1413- transmit. clip_datagram_size ( ) ;
1409+ transmit. clip_segment_size ( ) ;
14141410 }
14151411 }
14161412 }
@@ -1508,6 +1504,15 @@ impl Connection {
15081504 return None ;
15091505 }
15101506
1507+ Some ( self . build_transmit ( path_id, transmit) )
1508+ }
1509+
1510+ fn build_transmit ( & mut self , path_id : PathId , transmit : TransmitBuf < ' _ > ) -> Transmit {
1511+ debug_assert ! (
1512+ !transmit. is_empty( ) ,
1513+ "must not be called with an empty transmit buffer"
1514+ ) ;
1515+
15111516 let network_path = self . path_data ( path_id) . network_path ;
15121517 trace ! (
15131518 segment_size = transmit. segment_size( ) ,
@@ -1529,7 +1534,7 @@ impl Connection {
15291534 . udp_tx
15301535 . on_sent ( transmit. num_datagrams ( ) as u64 , transmit. len ( ) ) ;
15311536
1532- Some ( Transmit {
1537+ Transmit {
15331538 destination : network_path. remote ,
15341539 size : transmit. len ( ) ,
15351540 ecn : if self . path_data ( path_id) . sending_ecn {
@@ -1542,7 +1547,23 @@ impl Connection {
15421547 _ => Some ( transmit. segment_size ( ) ) ,
15431548 } ,
15441549 src_ip : network_path. local_ip ,
1545- } )
1550+ }
1551+ }
1552+
1553+ /// poll_transmit logic for off-path data.
1554+ fn poll_transmit_off_path (
1555+ & mut self ,
1556+ now : Instant ,
1557+ buf : & mut Vec < u8 > ,
1558+ path_id : PathId ,
1559+ ) -> Option < Transmit > {
1560+ if let Some ( challenge) = self . send_prev_path_challenge ( now, buf, path_id) {
1561+ return Some ( challenge) ;
1562+ }
1563+ if let Some ( response) = self . send_off_path_path_response ( now, buf, path_id) {
1564+ return Some ( response) ;
1565+ }
1566+ None
15461567 }
15471568
15481569 /// Returns the [`SpaceId`] of the next packet space which has data to send
@@ -1741,13 +1762,14 @@ impl Connection {
17411762 /// Indicate what types of frames are ready to send for the given space
17421763 ///
17431764 /// *packet_size* is the number of bytes available to build the next packet.
1744- /// *close* indicates whether a CONNECTION_CLOSE frame needs to be sent.
1765+ /// *connection_close_pending* indicates whether a CONNECTION_CLOSE frame needs to be
1766+ /// sent.
17451767 fn space_can_send (
17461768 & mut self ,
17471769 space_id : SpaceId ,
17481770 path_id : PathId ,
17491771 packet_size : usize ,
1750- close : bool ,
1772+ connection_close_pending : bool ,
17511773 ) -> SendableFrames {
17521774 let space = & mut self . spaces [ space_id] ;
17531775 let space_has_crypto = space. crypto . is_some ( ) ;
@@ -1771,7 +1793,7 @@ impl Connection {
17711793 can_send |= self . can_send_1rtt ( path_id, frame_space_1rtt) ;
17721794 }
17731795
1774- can_send. close = close && space_has_crypto;
1796+ can_send. close = connection_close_pending && space_has_crypto;
17751797
17761798 can_send
17771799 }
@@ -2107,7 +2129,7 @@ impl Connection {
21072129 if !was_closed {
21082130 self . close_common ( ) ;
21092131 self . set_close_timer ( now) ;
2110- self . close = true ;
2132+ self . connection_close_pending = true ;
21112133 self . state . move_to_closed_local ( reason) ;
21122134 }
21132135 }
@@ -3168,7 +3190,7 @@ impl Connection {
31683190 ) ) ;
31693191 self . close_common ( ) ;
31703192 self . set_close_timer ( now) ;
3171- self . close = true ;
3193+ self . connection_close_pending = true ;
31723194 }
31733195 return ;
31743196 }
@@ -3815,7 +3837,7 @@ impl Connection {
38153837 . get ( & path_id)
38163838 . map ( |p| p. data . network_path )
38173839 . unwrap_or ( network_path) ;
3818- self . close = network_path == path_remote;
3840+ self . connection_close_pending = network_path == path_remote;
38193841 }
38203842 }
38213843
@@ -4889,7 +4911,7 @@ impl Connection {
48894911
48904912 if let Some ( reason) = close {
48914913 self . state . move_to_draining ( Some ( reason. into ( ) ) ) ;
4892- self . close = true ;
4914+ self . connection_close_pending = true ;
48934915 }
48944916
48954917 if Some ( number) == self . spaces [ SpaceId :: Data ] . for_path ( path_id) . rx_packet
@@ -5085,7 +5107,7 @@ impl Connection {
50855107 path_exclusive_only : bool ,
50865108 builder : & mut PacketBuilder < ' a , ' b > ,
50875109 ) {
5088- let pn = builder. exact_number ;
5110+ let pn = builder. packet_number ;
50895111 let is_multipath_negotiated = self . is_multipath_negotiated ( ) ;
50905112 let stats = & mut self . stats . frame_tx ;
50915113 let space = & mut self . spaces [ space_id] ;
0 commit comments