forked from quic-go/quic-go
simplify sending of (connection-level) BLOCKED frames
This commit is contained in:
@@ -11,8 +11,9 @@ import (
|
||||
|
||||
type baseFlowController struct {
|
||||
// for sending data
|
||||
bytesSent protocol.ByteCount
|
||||
sendWindow protocol.ByteCount
|
||||
bytesSent protocol.ByteCount
|
||||
sendWindow protocol.ByteCount
|
||||
lastBlockedAt protocol.ByteCount
|
||||
|
||||
// for receiving data
|
||||
mutex sync.RWMutex
|
||||
@@ -72,12 +73,14 @@ func (c *baseFlowController) getWindowUpdate() protocol.ByteCount {
|
||||
return c.receiveWindow
|
||||
}
|
||||
|
||||
// IsBlocked says if it is blocked by flow control.
|
||||
// IsBlocked says if it is newly blocked by flow control.
|
||||
// For every offset, it only returns true once.
|
||||
// If it is blocked, the offset is returned.
|
||||
func (c *baseFlowController) IsBlocked() (bool, protocol.ByteCount) {
|
||||
if c.sendWindowSize() != 0 {
|
||||
func (c *baseFlowController) IsNewlyBlocked() (bool, protocol.ByteCount) {
|
||||
if c.sendWindowSize() != 0 || c.sendWindow == c.lastBlockedAt {
|
||||
return false, 0
|
||||
}
|
||||
c.lastBlockedAt = c.sendWindow
|
||||
return true, c.sendWindow
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,26 @@ var _ = Describe("Base Flow controller", func() {
|
||||
|
||||
It("says when it's blocked", func() {
|
||||
controller.UpdateSendWindow(100)
|
||||
Expect(controller.IsBlocked()).To(BeFalse())
|
||||
Expect(controller.IsNewlyBlocked()).To(BeFalse())
|
||||
controller.AddBytesSent(100)
|
||||
blocked, offset := controller.IsBlocked()
|
||||
blocked, offset := controller.IsNewlyBlocked()
|
||||
Expect(blocked).To(BeTrue())
|
||||
Expect(offset).To(Equal(protocol.ByteCount(100)))
|
||||
})
|
||||
|
||||
It("doesn't say that it's newly blocked multiple times for the same offset", func() {
|
||||
controller.UpdateSendWindow(100)
|
||||
controller.AddBytesSent(100)
|
||||
newlyBlocked, offset := controller.IsNewlyBlocked()
|
||||
Expect(newlyBlocked).To(BeTrue())
|
||||
Expect(offset).To(Equal(protocol.ByteCount(100)))
|
||||
newlyBlocked, _ = controller.IsNewlyBlocked()
|
||||
Expect(newlyBlocked).To(BeFalse())
|
||||
controller.UpdateSendWindow(150)
|
||||
controller.AddBytesSent(150)
|
||||
newlyBlocked, offset = controller.IsNewlyBlocked()
|
||||
Expect(newlyBlocked).To(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
Context("receive flow control", func() {
|
||||
|
||||
@@ -5,7 +5,7 @@ import "github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
type flowController interface {
|
||||
// for sending
|
||||
SendWindowSize() protocol.ByteCount
|
||||
IsBlocked() (bool, protocol.ByteCount)
|
||||
IsNewlyBlocked() (bool, protocol.ByteCount)
|
||||
UpdateSendWindow(protocol.ByteCount)
|
||||
AddBytesSent(protocol.ByteCount)
|
||||
// for receiving
|
||||
|
||||
@@ -233,9 +233,9 @@ var _ = Describe("Stream Flow controller", func() {
|
||||
controller.connection.UpdateSendWindow(50)
|
||||
controller.UpdateSendWindow(100)
|
||||
controller.AddBytesSent(50)
|
||||
blocked, _ := controller.connection.IsBlocked()
|
||||
blocked, _ := controller.connection.IsNewlyBlocked()
|
||||
Expect(blocked).To(BeTrue())
|
||||
Expect(controller.IsBlocked()).To(BeFalse())
|
||||
Expect(controller.IsNewlyBlocked()).To(BeFalse())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -65,17 +65,17 @@ func (_mr *MockConnectionFlowControllerMockRecorder) GetWindowUpdate() *gomock.C
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetWindowUpdate", reflect.TypeOf((*MockConnectionFlowController)(nil).GetWindowUpdate))
|
||||
}
|
||||
|
||||
// IsBlocked mocks base method
|
||||
func (_m *MockConnectionFlowController) IsBlocked() (bool, protocol.ByteCount) {
|
||||
ret := _m.ctrl.Call(_m, "IsBlocked")
|
||||
// IsNewlyBlocked mocks base method
|
||||
func (_m *MockConnectionFlowController) IsNewlyBlocked() (bool, protocol.ByteCount) {
|
||||
ret := _m.ctrl.Call(_m, "IsNewlyBlocked")
|
||||
ret0, _ := ret[0].(bool)
|
||||
ret1, _ := ret[1].(protocol.ByteCount)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// IsBlocked indicates an expected call of IsBlocked
|
||||
func (_mr *MockConnectionFlowControllerMockRecorder) IsBlocked() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "IsBlocked", reflect.TypeOf((*MockConnectionFlowController)(nil).IsBlocked))
|
||||
// IsNewlyBlocked indicates an expected call of IsNewlyBlocked
|
||||
func (_mr *MockConnectionFlowControllerMockRecorder) IsNewlyBlocked() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "IsNewlyBlocked", reflect.TypeOf((*MockConnectionFlowController)(nil).IsNewlyBlocked))
|
||||
}
|
||||
|
||||
// SendWindowSize mocks base method
|
||||
|
||||
@@ -65,17 +65,17 @@ func (_mr *MockStreamFlowControllerMockRecorder) GetWindowUpdate() *gomock.Call
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "GetWindowUpdate", reflect.TypeOf((*MockStreamFlowController)(nil).GetWindowUpdate))
|
||||
}
|
||||
|
||||
// IsBlocked mocks base method
|
||||
func (_m *MockStreamFlowController) IsBlocked() (bool, protocol.ByteCount) {
|
||||
ret := _m.ctrl.Call(_m, "IsBlocked")
|
||||
// IsNewlyBlocked mocks base method
|
||||
func (_m *MockStreamFlowController) IsNewlyBlocked() (bool, protocol.ByteCount) {
|
||||
ret := _m.ctrl.Call(_m, "IsNewlyBlocked")
|
||||
ret0, _ := ret[0].(bool)
|
||||
ret1, _ := ret[1].(protocol.ByteCount)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// IsBlocked indicates an expected call of IsBlocked
|
||||
func (_mr *MockStreamFlowControllerMockRecorder) IsBlocked() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "IsBlocked", reflect.TypeOf((*MockStreamFlowController)(nil).IsBlocked))
|
||||
// IsNewlyBlocked indicates an expected call of IsNewlyBlocked
|
||||
func (_mr *MockStreamFlowControllerMockRecorder) IsNewlyBlocked() *gomock.Call {
|
||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "IsNewlyBlocked", reflect.TypeOf((*MockStreamFlowController)(nil).IsNewlyBlocked))
|
||||
}
|
||||
|
||||
// SendWindowSize mocks base method
|
||||
|
||||
Reference in New Issue
Block a user