@@ -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 ( ) ,
@@ -970,7 +970,7 @@ impl Connection {
970970 StateType :: Draining | StateType :: Closed => {
971971 // self.close is only reset once the associated packet had been
972972 // encoded successfully
973- if !self . close {
973+ if !self . connection_close_pending {
974974 self . app_limited = true ;
975975 return None ;
976976 }
@@ -979,7 +979,7 @@ impl Connection {
979979 _ => false ,
980980 } ;
981981
982- // Check whether we need to send an ACK_FREQUENCY frame
982+ // Schedule an ACK_FREQUENCY frame if a new one needs to be sent.
983983 if let Some ( config) = & self . config . ack_frequency_config {
984984 let rtt = self
985985 . paths
@@ -1019,15 +1019,8 @@ impl Connection {
10191019 && self . remote_cids . contains_key ( id)
10201020 } ) ;
10211021
1022- if let Some ( challenge) = self . send_prev_path_challenge ( now, buf, path_id) {
1023- return Some ( challenge) ;
1024- }
1025-
1026- // Send an off-path PATH_RESPONSE. Prioritized over on-path data to ensure that
1027- // path validation can occur while the link is saturated.
1028- // TODO(@divma): I have no idea what this comment is supposed to mean
1029- if let Some ( response) = self . send_off_path_path_response ( now, buf, path_id) {
1030- return Some ( response) ;
1022+ if let Some ( transmit) = self . poll_transmit_off_path ( now, buf, path_id) {
1023+ return Some ( transmit) ;
10311024 }
10321025
10331026 let mut space_id = match path_id {
@@ -1249,7 +1242,7 @@ impl Connection {
12491242 can_send. other ,
12501243 self ,
12511244 ) ?;
1252- last_packet_number = Some ( builder. exact_number ) ;
1245+ last_packet_number = Some ( builder. packet_number ) ;
12531246 coalesce = coalesce && builder. can_coalesce ;
12541247
12551248 if space_id == SpaceId :: Initial && ( self . side . is_client ( ) || can_send. other ) {
@@ -1317,7 +1310,7 @@ impl Connection {
13171310 if space_id == self . highest_space {
13181311 // Don't send another close packet. Even with multipath we only send
13191312 // CONNECTION_CLOSE on a single path since we expect our paths to work.
1320- self . close = false ;
1313+ self . connection_close_pending = false ;
13211314 // `CONNECTION_CLOSE` is the final packet
13221315 break ;
13231316 } else {
@@ -1412,8 +1405,11 @@ impl Connection {
14121405 } else {
14131406 builder. finish_and_track ( now, self , path_id, pad_datagram) ;
14141407 }
1408+
1409+ // If this is the first datagram we set the segment size to the size of the
1410+ // first datagram.
14151411 if transmit. num_datagrams ( ) == 1 {
1416- transmit. clip_datagram_size ( ) ;
1412+ transmit. clip_segment_size ( ) ;
14171413 }
14181414 }
14191415 }
@@ -1511,6 +1507,15 @@ impl Connection {
15111507 return None ;
15121508 }
15131509
1510+ Some ( self . build_transmit ( path_id, transmit) )
1511+ }
1512+
1513+ fn build_transmit ( & mut self , path_id : PathId , transmit : TransmitBuf < ' _ > ) -> Transmit {
1514+ debug_assert ! (
1515+ !transmit. is_empty( ) ,
1516+ "must not be called with an empty transmit buffer"
1517+ ) ;
1518+
15141519 let network_path = self . path_data ( path_id) . network_path ;
15151520 trace ! (
15161521 segment_size = transmit. segment_size( ) ,
@@ -1532,7 +1537,7 @@ impl Connection {
15321537 . udp_tx
15331538 . on_sent ( transmit. num_datagrams ( ) as u64 , transmit. len ( ) ) ;
15341539
1535- Some ( Transmit {
1540+ Transmit {
15361541 destination : network_path. remote ,
15371542 size : transmit. len ( ) ,
15381543 ecn : if self . path_data ( path_id) . sending_ecn {
@@ -1545,7 +1550,23 @@ impl Connection {
15451550 _ => Some ( transmit. segment_size ( ) ) ,
15461551 } ,
15471552 src_ip : network_path. local_ip ,
1548- } )
1553+ }
1554+ }
1555+
1556+ /// poll_transmit logic for off-path data.
1557+ fn poll_transmit_off_path (
1558+ & mut self ,
1559+ now : Instant ,
1560+ buf : & mut Vec < u8 > ,
1561+ path_id : PathId ,
1562+ ) -> Option < Transmit > {
1563+ if let Some ( challenge) = self . send_prev_path_challenge ( now, buf, path_id) {
1564+ return Some ( challenge) ;
1565+ }
1566+ if let Some ( response) = self . send_off_path_path_response ( now, buf, path_id) {
1567+ return Some ( response) ;
1568+ }
1569+ None
15491570 }
15501571
15511572 /// Returns the [`SpaceId`] of the next packet space which has data to send
@@ -1744,13 +1765,14 @@ impl Connection {
17441765 /// Indicate what types of frames are ready to send for the given space
17451766 ///
17461767 /// *packet_size* is the number of bytes available to build the next packet.
1747- /// *close* indicates whether a CONNECTION_CLOSE frame needs to be sent.
1768+ /// *connection_close_pending* indicates whether a CONNECTION_CLOSE frame needs to be
1769+ /// sent.
17481770 fn space_can_send (
17491771 & mut self ,
17501772 space_id : SpaceId ,
17511773 path_id : PathId ,
17521774 packet_size : usize ,
1753- close : bool ,
1775+ connection_close_pending : bool ,
17541776 ) -> SendableFrames {
17551777 let space = & mut self . spaces [ space_id] ;
17561778 let space_has_crypto = space. crypto . is_some ( ) ;
@@ -1774,7 +1796,7 @@ impl Connection {
17741796 can_send |= self . can_send_1rtt ( path_id, frame_space_1rtt) ;
17751797 }
17761798
1777- can_send. close = close && space_has_crypto;
1799+ can_send. close = connection_close_pending && space_has_crypto;
17781800
17791801 can_send
17801802 }
@@ -2109,7 +2131,7 @@ impl Connection {
21092131 if !was_closed {
21102132 self . close_common ( ) ;
21112133 self . set_close_timer ( now) ;
2112- self . close = true ;
2134+ self . connection_close_pending = true ;
21132135 self . state . move_to_closed_local ( reason) ;
21142136 }
21152137 }
@@ -3170,7 +3192,7 @@ impl Connection {
31703192 ) ) ;
31713193 self . close_common ( ) ;
31723194 self . set_close_timer ( now) ;
3173- self . close = true ;
3195+ self . connection_close_pending = true ;
31743196 }
31753197 return ;
31763198 }
@@ -3817,7 +3839,7 @@ impl Connection {
38173839 . get ( & path_id)
38183840 . map ( |p| p. data . network_path )
38193841 . unwrap_or ( network_path) ;
3820- self . close = network_path == path_remote;
3842+ self . connection_close_pending = network_path == path_remote;
38213843 }
38223844 }
38233845
@@ -4891,7 +4913,7 @@ impl Connection {
48914913
48924914 if let Some ( reason) = close {
48934915 self . state . move_to_draining ( Some ( reason. into ( ) ) ) ;
4894- self . close = true ;
4916+ self . connection_close_pending = true ;
48954917 }
48964918
48974919 if Some ( number) == self . spaces [ SpaceId :: Data ] . for_path ( path_id) . rx_packet
@@ -5087,7 +5109,7 @@ impl Connection {
50875109 path_exclusive_only : bool ,
50885110 builder : & mut PacketBuilder < ' a , ' b > ,
50895111 ) {
5090- let pn = builder. exact_number ;
5112+ let pn = builder. packet_number ;
50915113 let is_multipath_negotiated = self . is_multipath_negotiated ( ) ;
50925114 let stats = & mut self . stats . frame_tx ;
50935115 let space = & mut self . spaces [ space_id] ;
0 commit comments