2019-08-22 10:48:10 +00:00
|
|
|
package multiplex
|
|
|
|
|
2020-04-09 17:56:17 +00:00
|
|
|
import (
|
2020-10-15 21:51:36 +00:00
|
|
|
"errors"
|
2020-04-09 17:56:17 +00:00
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
)
|
2019-08-22 10:48:10 +00:00
|
|
|
|
2020-10-15 21:51:36 +00:00
|
|
|
var ErrTimeout = errors.New("deadline exceeded")
|
|
|
|
|
2019-08-22 10:48:10 +00:00
|
|
|
type recvBuffer interface {
|
2020-04-08 13:59:09 +00:00
|
|
|
// Read calls' err must be nil | io.EOF | io.ErrShortBuffer
|
2020-10-15 21:51:36 +00:00
|
|
|
// 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.
|
2019-08-22 10:48:10 +00:00
|
|
|
io.ReadCloser
|
2020-04-12 10:33:11 +00:00
|
|
|
io.WriterTo
|
2020-01-22 21:12:32 +00:00
|
|
|
Write(Frame) (toBeClosed bool, err error)
|
2020-04-09 17:56:17 +00:00
|
|
|
SetReadDeadline(time time.Time)
|
2020-10-15 21:51:36 +00:00
|
|
|
// 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
|
2020-04-14 12:31:24 +00:00
|
|
|
SetWriteToTimeout(d time.Duration)
|
2019-08-22 10:48:10 +00:00
|
|
|
}
|
2020-10-18 13:56:58 +00:00
|
|
|
|
|
|
|
// 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
|