Cloak/internal/multiplex/recvBuffer.go

29 lines
982 B
Go
Raw Normal View History

package multiplex
2020-04-09 17:56:17 +00:00
import (
"errors"
2020-04-09 17:56:17 +00:00
"io"
"time"
)
var ErrTimeout = errors.New("deadline exceeded")
type recvBuffer interface {
2020-04-08 13:59:09 +00:00
// Read calls' err must be nil | io.EOF | io.ErrShortBuffer
// Read should NOT return error on a closed streamBuffer with a non-empty buffer.
// Instead, it should behave as if it hasn't been closed. Closure is only relevant
// when the buffer is empty.
io.ReadCloser
2020-04-12 10:33:11 +00:00
io.WriterTo
Write(Frame) (toBeClosed bool, err error)
2020-04-09 17:56:17 +00:00
SetReadDeadline(time time.Time)
// SetWriteToTimeout sets the duration a recvBuffer waits in a WriteTo call when nothing
// has been written for a while. After that duration it should return ErrTimeout
SetWriteToTimeout(d time.Duration)
}
// size we want the amount of unread data in buffer to grow before recvBuffer.Write blocks.
// If the buffer grows larger than what the system's memory can offer at the time of recvBuffer.Write,
// a panic will happen.
const recvBufferSizeLimit = defaultSendRecvBufSize << 12