From cb07e446b64c65334e7c366ba63d92cc089afe42 Mon Sep 17 00:00:00 2001 From: Qian Wang Date: Mon, 21 Jan 2019 21:15:18 +0000 Subject: [PATCH] Fix issue which the closing frame padding gets send as acutal data --- internal/multiplex/frameSorter.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/internal/multiplex/frameSorter.go b/internal/multiplex/frameSorter.go index 3c0ebac..1cf35f6 100644 --- a/internal/multiplex/frameSorter.go +++ b/internal/multiplex/frameSorter.go @@ -73,11 +73,17 @@ func (s *Stream) recvNewFrame() { // when there's no ooo packages in heap and we receive the next package in order if len(s.sh) == 0 && f.Seq == s.nextRecvSeq { - s.pushFrame(f) if f.Closing == 1 { // empty data indicates closing signal s.sortedBufCh <- []byte{} return + } else { + s.sortedBufCh <- f.Payload + s.nextRecvSeq += 1 + if s.nextRecvSeq == 0 { // getting wrapped + s.rev += 1 + s.wrapMode = false + } } continue } @@ -108,23 +114,20 @@ func (s *Stream) recvNewFrame() { heap.Push(&s.sh, fs) // Keep popping from the heap until empty or to the point that the wanted seq was not received for len(s.sh) > 0 && s.sh[0].frame.Seq == s.nextRecvSeq { - frame := heap.Pop(&s.sh).(*frameNode).frame - if frame.Closing == 1 { + f = heap.Pop(&s.sh).(*frameNode).frame + if f.Closing == 1 { // empty data indicates closing signal s.sortedBufCh <- []byte{} return + } else { + s.sortedBufCh <- f.Payload + s.nextRecvSeq += 1 + if s.nextRecvSeq == 0 { // getting wrapped + s.rev += 1 + s.wrapMode = false + } } - s.pushFrame(frame) } } } - -func (s *Stream) pushFrame(f *Frame) { - s.sortedBufCh <- f.Payload - s.nextRecvSeq += 1 - if s.nextRecvSeq == 0 { // getting wrapped - s.rev += 1 - s.wrapMode = false - } -}