blob: ce9aad5336432f4ca7d43c99a6401328dccd254b [file] [log] [blame]
// Copyright 2014 The Go Authors.
// See
// Licensed under the same terms as Go itself:
package http2
import (
type pipe struct {
b buffer
c sync.Cond
m sync.Mutex
// Read waits until data is available and copies bytes
// from the buffer into p.
func (r *pipe) Read(p []byte) (n int, err error) {
defer r.c.L.Unlock()
for r.b.Len() == 0 && !r.b.closed {
return r.b.Read(p)
// Write copies bytes from p into the buffer and wakes a reader.
// It is an error to write more data than the buffer can hold.
func (w *pipe) Write(p []byte) (n int, err error) {
defer w.c.L.Unlock()
defer w.c.Signal()
return w.b.Write(p)
func (c *pipe) Close(err error) {
defer c.c.L.Unlock()
defer c.c.Signal()