use STREAM frames from the buffer for sending data

This commit is contained in:
Marten Seemann
2019-09-04 20:24:09 +07:00
parent 039d7ae888
commit 4cfbb2f134
5 changed files with 57 additions and 42 deletions

View File

@@ -17,7 +17,7 @@ func init() {
}
}
func getStreamFrame() *StreamFrame {
func GetStreamFrame() *StreamFrame {
f := pool.Get().(*StreamFrame)
return f
}

View File

@@ -7,12 +7,12 @@ import (
var _ = Describe("Pool", func() {
It("gets and puts STREAM frames", func() {
f := getStreamFrame()
f := GetStreamFrame()
putStreamFrame(f)
})
It("panics when putting a STREAM frame with a wrong capacity", func() {
f := getStreamFrame()
f := GetStreamFrame()
f.Data = []byte("foobar")
Expect(func() { putStreamFrame(f) }).To(Panic())
})

View File

@@ -59,7 +59,7 @@ func parseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamF
if dataLen < protocol.MinStreamFrameBufferSize {
frame = &StreamFrame{Data: make([]byte, dataLen)}
} else {
frame = getStreamFrame()
frame = GetStreamFrame()
// The STREAM frame can't be larger than the StreamFrame we obtained from the buffer,
// since those StreamFrames have a buffer length of the maximum packet size.
if dataLen > uint64(cap(frame.Data)) {
@@ -167,7 +167,7 @@ func (f *StreamFrame) MaybeSplitOffFrame(maxSize protocol.ByteCount, version pro
return nil, true
}
new := getStreamFrame()
new := GetStreamFrame()
new.StreamID = f.StreamID
new.Offset = f.Offset
new.FinBit = false