prioritize sending ACKs over sending new DATAGRAM frames (#3544)

This commit is contained in:
Marten Seemann 2022-09-09 11:38:38 +03:00 committed by GitHub
parent 62b82789c0
commit c57ea6f276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 32 deletions

View file

@ -1,12 +1,17 @@
package quic
import (
"sync"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/internal/wire"
)
type datagramQueue struct {
mx sync.Mutex
nextFrameSize protocol.ByteCount
sendQueue chan *wire.DatagramFrame
rcvQueue chan []byte
@ -17,17 +22,20 @@ type datagramQueue struct {
dequeued chan struct{}
logger utils.Logger
logger utils.Logger
version protocol.VersionNumber
}
func newDatagramQueue(hasData func(), logger utils.Logger) *datagramQueue {
func newDatagramQueue(hasData func(), logger utils.Logger, v protocol.VersionNumber) *datagramQueue {
return &datagramQueue{
hasData: hasData,
sendQueue: make(chan *wire.DatagramFrame, 1),
rcvQueue: make(chan []byte, protocol.DatagramRcvQueueLen),
dequeued: make(chan struct{}),
closed: make(chan struct{}),
logger: logger,
hasData: hasData,
sendQueue: make(chan *wire.DatagramFrame, 1),
nextFrameSize: protocol.InvalidByteCount,
rcvQueue: make(chan []byte, protocol.DatagramRcvQueueLen),
dequeued: make(chan struct{}),
closed: make(chan struct{}),
logger: logger,
version: v,
}
}
@ -36,6 +44,9 @@ func newDatagramQueue(hasData func(), logger utils.Logger) *datagramQueue {
func (h *datagramQueue) AddAndWait(f *wire.DatagramFrame) error {
select {
case h.sendQueue <- f:
h.mx.Lock()
h.nextFrameSize = f.Length(h.version)
h.mx.Unlock()
h.hasData()
case <-h.closed:
return h.closeErr
@ -53,6 +64,9 @@ func (h *datagramQueue) AddAndWait(f *wire.DatagramFrame) error {
func (h *datagramQueue) Get() *wire.DatagramFrame {
select {
case f := <-h.sendQueue:
h.mx.Lock()
h.nextFrameSize = protocol.InvalidByteCount
h.mx.Unlock()
h.dequeued <- struct{}{}
return f
default:
@ -60,6 +74,12 @@ func (h *datagramQueue) Get() *wire.DatagramFrame {
}
}
func (h *datagramQueue) NextFrameSize() protocol.ByteCount {
h.mx.Lock()
defer h.mx.Unlock()
return h.nextFrameSize
}
// HandleDatagramFrame handles a received DATAGRAM frame.
func (h *datagramQueue) HandleDatagramFrame(f *wire.DatagramFrame) {
data := make([]byte, len(f.Data))