@@ -583,7 +583,7 @@ impl Connection {
583583 }
584584
585585 // If the datagram is full, we need to start a new one.
586- if buf. len ( ) == buf . datagram_max_offset ( ) {
586+ if buf. datagram_remaining_mut ( ) == 0 {
587587 // Is 1 more datagram allowed?
588588 if buf. num_datagrams ( ) >= buf. max_datagrams ( ) {
589589 // No more datagrams allowed
@@ -656,7 +656,7 @@ impl Connection {
656656 pad_datagram = false ;
657657 }
658658
659- debug_assert ! ( buf. datagram_max_offset ( ) - buf . len ( ) >= MIN_PACKET_SPACE ) ;
659+ debug_assert ! ( buf. datagram_remaining_mut ( ) >= MIN_PACKET_SPACE ) ;
660660
661661 //
662662 // From here on, we've determined that a packet will definitely be sent.
@@ -750,10 +750,7 @@ impl Connection {
750750 ) ,
751751 }
752752 }
753- if pad_datagram {
754- builder. pad_to ( MIN_INITIAL_SIZE ) ;
755- }
756- builder. finish_and_track ( now, self , path_id, sent_frames) ;
753+ builder. finish_and_track ( now, self , path_id, sent_frames, pad_datagram) ;
757754 if space_id == self . highest_space {
758755 // Don't send another close packet
759756 self . close = false ;
@@ -788,6 +785,7 @@ impl Connection {
788785 non_retransmits : true ,
789786 ..SentFrames :: default ( )
790787 } ,
788+ false ,
791789 ) ;
792790 self . stats . udp_tx . on_sent ( 1 , buf. len ( ) ) ;
793791 return Some ( Transmit {
@@ -850,17 +848,18 @@ impl Connection {
850848 // Are we allowed to coalesce AND is there enough space for another *packet*
851849 // in this datagram?
852850 if coalesce
853- && builder. buf . segment_size ( ) - builder. predict_packet_size ( ) > MIN_PACKET_SPACE
851+ && builder
852+ . buf
853+ . datagram_remaining_mut ( )
854+ . saturating_sub ( builder. predict_packet_end ( ) )
855+ > MIN_PACKET_SPACE
854856 {
855857 // We can append/coalesce the next packet into the current
856858 // datagram. Finish the current packet without adding extra padding.
857- builder. finish_and_track ( now, self , path_id, sent_frames) ;
859+ builder. finish_and_track ( now, self , path_id, sent_frames, false ) ;
858860 } else {
859861 // We need a new datagram for the next packet. Finish the current
860862 // packet with padding.
861- if pad_datagram {
862- builder. pad_to ( MIN_INITIAL_SIZE ) ;
863- }
864863 if builder. buf . num_datagrams ( ) > 1 {
865864 // If too many padding bytes would be required to continue the
866865 // GSO batch after this packet, end the GSO batch here. Ensures
@@ -877,16 +876,14 @@ impl Connection {
877876 // are the only packets for which we might grow `buf_capacity`
878877 // by less than `segment_size`.
879878 const MAX_PADDING : usize = 16 ;
880- let packet_len_unpadded = builder. predict_packet_size ( ) ;
881- if packet_len_unpadded + MAX_PADDING < builder. buf . segment_size ( )
882- || builder. buf . datagram_start_offset ( ) + builder. buf . segment_size ( )
883- > builder. buf . datagram_max_offset ( )
879+ if builder. buf . datagram_remaining_mut ( )
880+ > builder. predict_packet_end ( ) + MAX_PADDING
884881 {
885882 trace ! (
886- "GSO truncated by demand for {} padding bytes or loss probe " ,
887- builder. buf. segment_size ( ) - packet_len_unpadded
883+ "GSO truncated by demand for {} padding bytes" ,
884+ builder. buf. datagram_remaining_mut ( ) - builder . predict_packet_end ( )
888885 ) ;
889- builder. finish_and_track ( now, self , path_id, sent_frames) ;
886+ builder. finish_and_track ( now, self , path_id, sent_frames, pad_datagram ) ;
890887 break ;
891888 }
892889
@@ -895,7 +892,7 @@ impl Connection {
895892 builder. pad_to ( builder. buf . segment_size ( ) as u16 ) ;
896893 }
897894
898- builder. finish_and_track ( now, self , path_id, sent_frames) ;
895+ builder. finish_and_track ( now, self , path_id, sent_frames, pad_datagram ) ;
899896
900897 if buf. num_datagrams ( ) == 1 {
901898 buf. clip_datagram_size ( ) ;
@@ -924,10 +921,7 @@ impl Connection {
924921 }
925922 } else {
926923 // Nothing more to send. This was the last packet.
927- if pad_datagram {
928- builder. pad_to ( MIN_INITIAL_SIZE ) ;
929- }
930- builder. finish_and_track ( now, self , path_id, sent_frames) ;
924+ builder. finish_and_track ( now, self , path_id, sent_frames, pad_datagram) ;
931925 break ;
932926 }
933927 }
@@ -987,7 +981,7 @@ impl Connection {
987981 non_retransmits : true ,
988982 ..Default :: default ( )
989983 } ;
990- builder. finish_and_track ( now, self , path_id, sent_frames) ;
984+ builder. finish_and_track ( now, self , path_id, sent_frames, false ) ;
991985
992986 self . stats . path . sent_plpmtud_probes += 1 ;
993987
0 commit comments