From d5ca637a0e8ec6a58e5a333668fb6bca377f92b8 Mon Sep 17 00:00:00 2001 From: xtaci Date: Tue, 7 Feb 2023 22:06:41 +0800 Subject: [PATCH] ignore prio settinn in writeFrameInternal --- shaper.go | 10 ++-------- shaper_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/shaper.go b/shaper.go index 0cc82b1..35773ee 100644 --- a/shaper.go +++ b/shaper.go @@ -6,14 +6,8 @@ func _itimediff(later, earlier uint32) int32 { type shaperHeap []writeRequest -func (h shaperHeap) Len() int { return len(h) } -func (h shaperHeap) Less(i, j int) bool { - if h[i].frame.sid == h[j].frame.sid { - return _itimediff(h[j].seq, h[i].seq) > 0 - } else { - return _itimediff(h[j].prio, h[i].prio) > 0 - } -} +func (h shaperHeap) Len() int { return len(h) } +func (h shaperHeap) Less(i, j int) bool { return _itimediff(h[j].seq, h[i].seq) > 0 } func (h shaperHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } func (h *shaperHeap) Push(x interface{}) { *h = append(*h, x.(writeRequest)) } diff --git a/shaper_test.go b/shaper_test.go index 572f4ae..95d0079 100644 --- a/shaper_test.go +++ b/shaper_test.go @@ -30,3 +30,25 @@ func TestShaper(t *testing.T) { lastPrio = w.prio } } + +func TestShaper2(t *testing.T) { + w1 := writeRequest{prio: 10, seq: 1} // stream 0 + w2 := writeRequest{prio: 10, seq: 2} + w3 := writeRequest{prio: 20, seq: 3} + w4 := writeRequest{prio: 100, seq: 4} + w5 := writeRequest{prio: (1 << 32) - 1, seq: 5} + w6 := writeRequest{prio: 10, seq: 1, frame: Frame{sid: 10}} // stream 1 + + var reqs shaperHeap + heap.Push(&reqs, w6) + heap.Push(&reqs, w5) + heap.Push(&reqs, w4) + heap.Push(&reqs, w3) + heap.Push(&reqs, w2) + heap.Push(&reqs, w1) + + for len(reqs) > 0 { + w := heap.Pop(&reqs).(writeRequest) + t.Log("prio:", w.prio, "sid:", w.frame.sid, "seq:", w.seq) + } +}