set the offset in BLOCKED and STREAM_BLOCKED frames

This commit is contained in:
Marten Seemann
2017-12-14 15:19:55 +07:00
parent 69998c19cb
commit 00edfb7461
12 changed files with 51 additions and 33 deletions

View File

@@ -79,11 +79,16 @@ func (c *baseFlowController) getWindowUpdate() protocol.ByteCount {
return c.receiveWindow
}
func (c *baseFlowController) IsBlocked() bool {
// IsBlocked says if it is blocked by flow control.
// If it is blocked, the offset is returned.
func (c *baseFlowController) IsBlocked() (bool, protocol.ByteCount) {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.sendWindowSize() == 0
if c.sendWindowSize() != 0 {
return false, 0
}
return true, c.sendWindow
}
// maybeAdjustWindowIncrement increases the receiveWindowIncrement if we're sending updates too often.

View File

@@ -54,7 +54,9 @@ var _ = Describe("Base Flow controller", func() {
controller.UpdateSendWindow(100)
Expect(controller.IsBlocked()).To(BeFalse())
controller.AddBytesSent(100)
Expect(controller.IsBlocked()).To(BeTrue())
blocked, offset := controller.IsBlocked()
Expect(blocked).To(BeTrue())
Expect(offset).To(Equal(protocol.ByteCount(100)))
})
})

View File

@@ -5,7 +5,7 @@ import "github.com/lucas-clemente/quic-go/internal/protocol"
type flowController interface {
// for sending
SendWindowSize() protocol.ByteCount
IsBlocked() bool
IsBlocked() (bool, protocol.ByteCount)
UpdateSendWindow(protocol.ByteCount)
AddBytesSent(protocol.ByteCount)
// for receiving

View File

@@ -233,7 +233,8 @@ var _ = Describe("Stream Flow controller", func() {
controller.connection.UpdateSendWindow(50)
controller.UpdateSendWindow(100)
controller.AddBytesSent(50)
Expect(controller.connection.IsBlocked()).To(BeTrue())
blocked, _ := controller.connection.IsBlocked()
Expect(blocked).To(BeTrue())
Expect(controller.IsBlocked()).To(BeFalse())
})
})