package http2
import "math"
func NewRandomWriteScheduler () WriteScheduler {
return &randomWriteScheduler {sq : make (map [uint32 ]*writeQueue )}
}
type randomWriteScheduler struct {
zero writeQueue
sq map [uint32 ]*writeQueue
queuePool writeQueuePool
}
func (ws *randomWriteScheduler ) OpenStream (streamID uint32 , options OpenStreamOptions ) {
}
func (ws *randomWriteScheduler ) CloseStream (streamID uint32 ) {
q , ok := ws .sq [streamID ]
if !ok {
return
}
delete (ws .sq , streamID )
ws .queuePool .put (q )
}
func (ws *randomWriteScheduler ) AdjustStream (streamID uint32 , priority PriorityParam ) {
}
func (ws *randomWriteScheduler ) Push (wr FrameWriteRequest ) {
if wr .isControl () {
ws .zero .push (wr )
return
}
id := wr .StreamID ()
q , ok := ws .sq [id ]
if !ok {
q = ws .queuePool .get ()
ws .sq [id ] = q
}
q .push (wr )
}
func (ws *randomWriteScheduler ) Pop () (FrameWriteRequest , bool ) {
if !ws .zero .empty () {
return ws .zero .shift (), true
}
for streamID , q := range ws .sq {
if wr , ok := q .consume (math .MaxInt32 ); ok {
if q .empty () {
delete (ws .sq , streamID )
ws .queuePool .put (q )
}
return wr , true
}
}
return FrameWriteRequest {}, false
}
The pages are generated with Golds v0.8.2 . (GOOS=linux 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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds .