Source File
flowcontrol.go
Belonging Package
google.golang.org/grpc/internal/transport
package transport
import (
)
type writeQuota struct {
replenish func(n int)
}
func ( int32, <-chan struct{}) *writeQuota {
:= &writeQuota{
quota: ,
ch: make(chan struct{}, 1),
done: ,
}
.replenish = .realReplenish
return
}
func ( *writeQuota) ( int32) error {
for {
if atomic.LoadInt32(&.quota) > 0 {
atomic.AddInt32(&.quota, -)
return nil
}
select {
case <-.ch:
continue
case <-.done:
return errStreamDone
}
}
}
func ( *writeQuota) ( int) {
:= int32()
:= atomic.AddInt32(&.quota, )
:= -
if <= 0 && > 0 {
select {
case .ch <- struct{}{}:
default:
}
}
}
type trInFlow struct {
limit uint32
unacked uint32
effectiveWindowSize uint32
}
func ( *trInFlow) ( uint32) uint32 {
:= - .limit
.limit =
.updateEffectiveWindowSize()
return
}
func ( *trInFlow) ( uint32) uint32 {
.unacked +=
if .unacked >= .limit/4 {
:= .unacked
.unacked = 0
.updateEffectiveWindowSize()
return
}
.updateEffectiveWindowSize()
return 0
}
func ( *trInFlow) () uint32 {
:= .unacked
.unacked = 0
.updateEffectiveWindowSize()
return
}
func ( *trInFlow) () {
atomic.StoreUint32(&.effectiveWindowSize, .limit-.unacked)
}
func ( *trInFlow) () uint32 {
return atomic.LoadUint32(&.effectiveWindowSize)
}
type inFlow struct {
if .limit+ > maxWindowSize {
.delta = maxWindowSize - .limit
func ( *inFlow) ( uint32) error {
.mu.Lock()
.pendingData +=
if .pendingData+.pendingUpdate > .limit+.delta {
:= .limit
:= .pendingData + .pendingUpdate
.mu.Unlock()
return fmt.Errorf("received %d-bytes data exceeding the limit %d bytes", , )
}
.mu.Unlock()
return nil
}
func ( *inFlow) ( uint32) uint32 {
.mu.Lock()
if .pendingData == 0 {
.mu.Unlock()
return 0
}
.pendingData -=
if > .delta {
-= .delta
.delta = 0
} else {
.delta -=
= 0
}
.pendingUpdate +=
if .pendingUpdate >= .limit/4 {
:= .pendingUpdate
.pendingUpdate = 0
.mu.Unlock()
return
}
.mu.Unlock()
return 0
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |