forked from quic-go/quic-go
remove mutex from flowController; locking is ensured by the manager
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package flowcontrol
|
package flowcontrol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/handshake"
|
"github.com/lucas-clemente/quic-go/handshake"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
)
|
)
|
||||||
@@ -19,8 +17,6 @@ type flowController struct {
|
|||||||
highestReceived protocol.ByteCount
|
highestReceived protocol.ByteCount
|
||||||
receiveFlowControlWindow protocol.ByteCount
|
receiveFlowControlWindow protocol.ByteCount
|
||||||
receiveFlowControlWindowIncrement protocol.ByteCount
|
receiveFlowControlWindowIncrement protocol.ByteCount
|
||||||
|
|
||||||
mutex sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newFlowController gets a new flow controller
|
// newFlowController gets a new flow controller
|
||||||
@@ -52,18 +48,12 @@ func (c *flowController) getSendFlowControlWindow() protocol.ByteCount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *flowController) AddBytesSent(n protocol.ByteCount) {
|
func (c *flowController) AddBytesSent(n protocol.ByteCount) {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
|
|
||||||
c.bytesSent += n
|
c.bytesSent += n
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateSendWindow should be called after receiving a WindowUpdateFrame
|
// UpdateSendWindow should be called after receiving a WindowUpdateFrame
|
||||||
// it returns true if the window was actually updated
|
// it returns true if the window was actually updated
|
||||||
func (c *flowController) UpdateSendWindow(newOffset protocol.ByteCount) bool {
|
func (c *flowController) UpdateSendWindow(newOffset protocol.ByteCount) bool {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
|
|
||||||
if newOffset > c.sendFlowControlWindow {
|
if newOffset > c.sendFlowControlWindow {
|
||||||
c.sendFlowControlWindow = newOffset
|
c.sendFlowControlWindow = newOffset
|
||||||
return true
|
return true
|
||||||
@@ -73,9 +63,6 @@ func (c *flowController) UpdateSendWindow(newOffset protocol.ByteCount) bool {
|
|||||||
|
|
||||||
// TODO: remove once the Stream doesn't use it anymore
|
// TODO: remove once the Stream doesn't use it anymore
|
||||||
func (c *flowController) SendWindowSize() protocol.ByteCount {
|
func (c *flowController) SendWindowSize() protocol.ByteCount {
|
||||||
c.mutex.RLock()
|
|
||||||
defer c.mutex.RUnlock()
|
|
||||||
|
|
||||||
sendFlowControlWindow := c.getSendFlowControlWindow()
|
sendFlowControlWindow := c.getSendFlowControlWindow()
|
||||||
|
|
||||||
if c.bytesSent > sendFlowControlWindow { // should never happen, but make sure we don't do an underflow here
|
if c.bytesSent > sendFlowControlWindow { // should never happen, but make sure we don't do an underflow here
|
||||||
@@ -85,18 +72,12 @@ func (c *flowController) SendWindowSize() protocol.ByteCount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *flowController) SendWindowOffset() protocol.ByteCount {
|
func (c *flowController) SendWindowOffset() protocol.ByteCount {
|
||||||
c.mutex.RLock()
|
|
||||||
defer c.mutex.RUnlock()
|
|
||||||
|
|
||||||
return c.getSendFlowControlWindow()
|
return c.getSendFlowControlWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateHighestReceived updates the highestReceived value, if the byteOffset is higher
|
// UpdateHighestReceived updates the highestReceived value, if the byteOffset is higher
|
||||||
// Should **only** be used for the stream-level FlowController
|
// Should **only** be used for the stream-level FlowController
|
||||||
func (c *flowController) UpdateHighestReceived(byteOffset protocol.ByteCount) protocol.ByteCount {
|
func (c *flowController) UpdateHighestReceived(byteOffset protocol.ByteCount) protocol.ByteCount {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
|
|
||||||
if byteOffset > c.highestReceived {
|
if byteOffset > c.highestReceived {
|
||||||
increment := byteOffset - c.highestReceived
|
increment := byteOffset - c.highestReceived
|
||||||
c.highestReceived = byteOffset
|
c.highestReceived = byteOffset
|
||||||
@@ -108,25 +89,16 @@ func (c *flowController) UpdateHighestReceived(byteOffset protocol.ByteCount) pr
|
|||||||
// IncrementHighestReceived adds an increment to the highestReceived value
|
// IncrementHighestReceived adds an increment to the highestReceived value
|
||||||
// Should **only** be used for the connection-level FlowController
|
// Should **only** be used for the connection-level FlowController
|
||||||
func (c *flowController) IncrementHighestReceived(increment protocol.ByteCount) {
|
func (c *flowController) IncrementHighestReceived(increment protocol.ByteCount) {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
|
|
||||||
c.highestReceived += increment
|
c.highestReceived += increment
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *flowController) AddBytesRead(n protocol.ByteCount) {
|
func (c *flowController) AddBytesRead(n protocol.ByteCount) {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
|
|
||||||
c.bytesRead += n
|
c.bytesRead += n
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaybeTriggerWindowUpdate determines if it is necessary to send a WindowUpdate
|
// MaybeTriggerWindowUpdate determines if it is necessary to send a WindowUpdate
|
||||||
// if so, it returns true and the offset of the window
|
// if so, it returns true and the offset of the window
|
||||||
func (c *flowController) MaybeTriggerWindowUpdate() (bool, protocol.ByteCount) {
|
func (c *flowController) MaybeTriggerWindowUpdate() (bool, protocol.ByteCount) {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
|
|
||||||
diff := c.receiveFlowControlWindow - c.bytesRead
|
diff := c.receiveFlowControlWindow - c.bytesRead
|
||||||
// Chromium implements the same threshold
|
// Chromium implements the same threshold
|
||||||
if diff < (c.receiveFlowControlWindowIncrement / 2) {
|
if diff < (c.receiveFlowControlWindowIncrement / 2) {
|
||||||
@@ -137,9 +109,6 @@ func (c *flowController) MaybeTriggerWindowUpdate() (bool, protocol.ByteCount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *flowController) CheckFlowControlViolation() bool {
|
func (c *flowController) CheckFlowControlViolation() bool {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
|
|
||||||
if c.highestReceived > c.receiveFlowControlWindow {
|
if c.highestReceived > c.receiveFlowControlWindow {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user