use the STREAM frame buffer for receiving data

This commit is contained in:
Marten Seemann 2019-09-04 16:51:58 +07:00
parent 5ea33cd31e
commit ba1bcf6e0c
4 changed files with 394 additions and 221 deletions

View file

@ -33,6 +33,7 @@ type receiveStream struct {
finalOffset protocol.ByteCount
currentFrame []byte
currentFrameDone func()
currentFrameIsLast bool // is the currentFrame the last frame on this stream
readPosInFrame int
@ -185,7 +186,11 @@ func (s *receiveStream) readImpl(p []byte) (bool /*stream completed */, int, err
func (s *receiveStream) dequeueNextFrame() {
var offset protocol.ByteCount
offset, s.currentFrame = s.frameQueue.Pop()
// We're done with the last frame. Release the buffer.
if s.currentFrameDone != nil {
s.currentFrameDone()
}
offset, s.currentFrame, s.currentFrameDone = s.frameQueue.Pop()
s.currentFrameIsLast = offset+protocol.ByteCount(len(s.currentFrame)) >= s.finalOffset
s.readPosInFrame = 0
}
@ -237,7 +242,7 @@ func (s *receiveStream) handleStreamFrameImpl(frame *wire.StreamFrame) (bool /*
if s.canceledRead {
return frame.FinBit, nil
}
if err := s.frameQueue.Push(frame.Data, frame.Offset); err != nil {
if err := s.frameQueue.Push(frame.Data, frame.Offset, frame.PutBack); err != nil {
return false, err
}
s.signalRead()