Source File
pipe.go
Belonging Package
golang.org/x/net/http2
package http2
import (
)
type pipe struct {
mu sync.Mutex
c sync.Cond // c.L lazily initialized to &p.mu
b pipeBuffer // nil when done reading
unread int // bytes unread when done
err error // read error once empty. non-nil means closed.
breakErr error // immediate read error (caller doesn't see rest of b)
donec chan struct{} // closed on error
readFn func() // optional code to run in Read before error
}
type pipeBuffer interface {
Len() int
io.Writer
io.Reader
}
func ( *pipe) () int {
.mu.Lock()
defer .mu.Unlock()
if .b == nil {
return .unread
}
return .b.Len()
}
func ( *pipe) ( []byte) ( int, error) {
.mu.Lock()
defer .mu.Unlock()
if .c.L == nil {
.c.L = &.mu
}
for {
if .breakErr != nil {
return 0, .breakErr
}
if .b != nil && .b.Len() > 0 {
return .b.Read()
}
if .err != nil {
if .readFn != nil {
.readFn() // e.g. copy trailers
.readFn = nil // not sticky like p.err
}
.b = nil
return 0, .err
}
.c.Wait()
}
}
var errClosedPipeWrite = errors.New("write on closed buffer")
func ( *pipe) ( error) { .closeWithError(&.err, , nil) }
func ( *pipe) ( error) { .closeWithError(&.breakErr, , nil) }
.closeDoneLocked()
}
}
return .donec
![]() |
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. |