connection: only queue flow control frames once when sending a batch

This commit is contained in:
Marten Seemann 2023-04-30 12:53:37 +02:00
parent d1bbde3580
commit db4e929ccf
2 changed files with 30 additions and 20 deletions

View file

@ -1805,6 +1805,27 @@ func (s *connection) sendPackets() error {
return nil
}
if isBlocked, offset := s.connFlowController.IsNewlyBlocked(); isBlocked {
s.framer.QueueControlFrame(&wire.DataBlockedFrame{MaximumData: offset})
}
s.windowUpdateQueue.QueueAll()
if !s.handshakeConfirmed {
packet, err := s.packer.PackCoalescedPacket(false, s.mtuDiscoverer.CurrentSize(), s.version)
if err != nil || packet == nil {
return err
}
s.sentFirstPacket = true
s.sendPackedCoalescedPacket(packet, now)
sendMode := s.sentPacketHandler.SendMode()
if sendMode == ackhandler.SendPacingLimited {
s.resetPacingDeadline()
} else if sendMode == ackhandler.SendAny {
s.pacingDeadline = deadlineSendImmediately
}
return nil
}
for {
sent, err := s.sendPacket(now)
if err != nil || !sent {
@ -1821,11 +1842,7 @@ func (s *connection) sendPackets() error {
sendMode := s.sentPacketHandler.SendMode()
if sendMode == ackhandler.SendPacingLimited {
deadline := s.sentPacketHandler.TimeUntilSend()
if deadline.IsZero() {
deadline = deadlineSendImmediately
}
s.pacingDeadline = deadline
s.resetPacingDeadline()
return nil
}
if sendMode != ackhandler.SendAny {
@ -1834,6 +1851,14 @@ func (s *connection) sendPackets() error {
}
}
func (s *connection) resetPacingDeadline() {
deadline := s.sentPacketHandler.TimeUntilSend()
if deadline.IsZero() {
deadline = deadlineSendImmediately
}
s.pacingDeadline = deadline
}
func (s *connection) maybeSendAckOnlyPacket() error {
if !s.handshakeConfirmed {
packet, err := s.packer.PackCoalescedPacket(true, s.mtuDiscoverer.CurrentSize(), s.version)
@ -1903,20 +1928,6 @@ func (s *connection) sendProbePacket(encLevel protocol.EncryptionLevel) error {
}
func (s *connection) sendPacket(now time.Time) (bool, error) {
if isBlocked, offset := s.connFlowController.IsNewlyBlocked(); isBlocked {
s.framer.QueueControlFrame(&wire.DataBlockedFrame{MaximumData: offset})
}
s.windowUpdateQueue.QueueAll()
if !s.handshakeConfirmed {
packet, err := s.packer.PackCoalescedPacket(false, s.mtuDiscoverer.CurrentSize(), s.version)
if err != nil || packet == nil {
return false, err
}
s.sentFirstPacket = true
s.sendPackedCoalescedPacket(packet, now)
return true, nil
}
p, buffer, err := s.packer.PackPacket(false, now, s.mtuDiscoverer.CurrentSize(), s.version)
if err != nil {
if err == errNothingToPack {

View file

@ -1256,7 +1256,6 @@ var _ = Describe("Connection", func() {
conn.sentPacketHandler = sph
fc := mocks.NewMockConnectionFlowController(mockCtrl)
fc.EXPECT().IsNewlyBlocked().Return(true, protocol.ByteCount(1337))
fc.EXPECT().IsNewlyBlocked()
p, buffer := getShortHeaderPacket(1)
packer.EXPECT().PackPacket(false, gomock.Any(), gomock.Any(), conn.version).Return(p, buffer, nil)
packer.EXPECT().PackPacket(false, gomock.Any(), gomock.Any(), conn.version).Return(shortHeaderPacket{}, nil, errNothingToPack).AnyTimes()