fix Writing of multiple StreamFrames in Stream.Write method

fixes #147
This commit is contained in:
Marten Seemann
2016-05-26 11:04:48 +07:00
parent 3a08041ab3
commit 93771708ae
2 changed files with 14 additions and 3 deletions

View File

@@ -202,7 +202,7 @@ func (s *stream) Write(p []byte) (int, error) {
dataLen := utils.MinByteCount(protocol.ByteCount(len(p)), remainingBytesInWindow)
data := make([]byte, dataLen)
copy(data, p)
copy(data, p[dataWritten:])
err := s.session.queueStreamFrame(&frames.StreamFrame{
StreamID: s.streamID,
Offset: s.writeOffset,

View File

@@ -17,7 +17,7 @@ import (
)
type mockStreamHandler struct {
frames []frames.Frame
frames []*frames.StreamFrame
receivedBlockedCalled bool
receivedBlockedForStream protocol.StreamID
@@ -334,11 +334,14 @@ var _ = Describe("Stream", func() {
Context("flow control", func() {
It("writes everything if the flow control window is big enough", func() {
data := []byte{0xDE, 0xCA, 0xFB, 0xAD}
updated := str.flowController.UpdateSendWindow(4)
Expect(updated).To(BeTrue())
n, err := str.Write([]byte{0xDE, 0xCA, 0xFB, 0xAD})
n, err := str.Write(data)
Expect(n).To(Equal(4))
Expect(err).ToNot(HaveOccurred())
Expect(handler.frames).To(HaveLen(1))
Expect(handler.frames[0].Data).To(Equal(data))
})
It("doesn't care about the connection flow control window if it is not contributing", func() {
@@ -383,6 +386,11 @@ var _ = Describe("Stream", func() {
Expect(b).To(BeTrue())
Expect(n).To(Equal(2))
Expect(str.writeOffset).To(Equal(protocol.ByteCount(3)))
Expect(handler.frames).To(HaveLen(2))
Expect(handler.frames[0].Offset).To(Equal(protocol.ByteCount(0)))
Expect(handler.frames[0].Data).To(Equal([]byte{0x42}))
Expect(handler.frames[1].Offset).To(Equal(protocol.ByteCount(1)))
Expect(handler.frames[1].Data).To(Equal([]byte{0x13, 0x37}))
})
It("does not write too much data after receiving a window update", func() {
@@ -400,6 +408,9 @@ var _ = Describe("Stream", func() {
Expect(n).To(Equal(2))
Expect(str.writeOffset).To(Equal(protocol.ByteCount(2)))
Expect(err).ToNot(HaveOccurred())
Expect(handler.frames).To(HaveLen(2))
Expect(handler.frames[0].Data).To(Equal([]byte{0x13}))
Expect(handler.frames[1].Data).To(Equal([]byte{0x37}))
})
It("waits for a connection flow control window update", func() {