Skip to content

Commit

Permalink
Truncate GSO after assembling a short packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Apr 29, 2024
1 parent b2137a0 commit 60c8054
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,20 @@ impl Connection {
}

if num_datagrams > 1 {
// If too many padding bytes would be required to continue the GSO batch
// after this packet, end the GSO batch here. Ensures that fixed-size frames
// with heterogeneous sizes (e.g. application datagrams) won't inadvertently
// waste large amounts of bandwidth. The exact threshold is a bit arbitrary
// and might benefit from further tuning, though there's no universally
// optimal value.
const MAX_PADDING: usize = 16;
let packet_len_unpadded =
cmp::max(builder.min_size, buf.len()) + builder.tag_len;
if packet_len_unpadded + MAX_PADDING < segment_size as usize {
trace!("GSO truncated by {} byte packet", packet_len_unpadded);
break;
}

// Pad the current packet to GSO segment size so it can be included in the
// GSO batch.
builder.pad_to(segment_size);
Expand Down

0 comments on commit 60c8054

Please sign in to comment.