func NewChanWriter(c chan<- []byte) *ChanWriter {
	return &ChanWriter{c: c, closed: make(chan bool)}
}
NewChanWriter creates a new ChanWriter that writes
to the given channel.
package fakenet
import (
	"errors"
	"io"
	"runtime"
	"sync"
	"time"
)
type ChanReader struct {
	mu       sync.Mutex
	buf      []byte
	c        <-chan []byte
	closedCh chan bool
	closed   bool
}
func NewChanReader(c <-chan []byte) *ChanReader {
	return &ChanReader{c: c, closedCh: make(chan bool)}
}
func (r *ChanReader) Close() error {
	close(r.closedCh)
	r.mu.Lock()
	r.closed = true
	r.mu.Unlock()
	return nil
}
var ErrClosed = errors.New("operation on closed channel")
var errUnimplemented = errors.New("unimplemented")
func (r *ChanReader) SetReadDeadline(t time.Time) error {
	return errUnimplemented
}
func (r *ChanReader) Read(buf []byte) (int, error) {
	r.mu.Lock()
	defer r.mu.Unlock()
	if r.closed {
		return 0, ErrClosed
	}
	for len(r.buf) == 0 {
		var ok bool
		select {
		case r.buf, ok = <-r.c:
			if !ok {
				return 0, io.EOF
			}
		case <-r.closedCh:
			return 0, ErrClosed
		}
	}
	n := copy(buf, r.buf)
	r.buf = r.buf[n:]
	return n, nil
}
type ChanWriter struct {
	c      chan<- []byte
	closed chan bool
}