diff --git a/connection.go b/connection.go index e9845b81..4d645d40 100644 --- a/connection.go +++ b/connection.go @@ -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 { diff --git a/connection_test.go b/connection_test.go index c842e98f..54148772 100644 --- a/connection_test.go +++ b/connection_test.go @@ -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()