Reduce recvBuffer's implementation's buffer size limits

pull/132/head
Andy Wang 4 years ago
parent c7c3f7706d
commit acdb0d35fa

@ -13,7 +13,8 @@ import (
// instead of byte-oriented. The integrity of datagrams written into this buffer is preserved.
// it won't get chopped up into individual bytes
type datagramBufferedPipe struct {
pLens []int
pLens []int
// lazily allocated
buf *bytes.Buffer
closed bool
rwCond *sync.Cond
@ -114,7 +115,7 @@ func (d *datagramBufferedPipe) Write(f Frame) (toBeClosed bool, err error) {
if d.closed {
return true, io.ErrClosedPipe
}
if d.buf.Len() <= BUF_SIZE_LIMIT {
if d.buf.Len() <= recvBufferSizeLimit {
// if d.buf gets too large, write() will panic. We don't want this to happen
break
}

@ -21,3 +21,8 @@ type recvBuffer interface {
// 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

@ -9,8 +9,6 @@ import (
"time"
)
const BUF_SIZE_LIMIT = 1 << 20 * 500
// The point of a streamBufferedPipe is that Read() will block until data is available
type streamBufferedPipe struct {
// only alloc when on first Read or Write
@ -105,7 +103,7 @@ func (p *streamBufferedPipe) Write(input []byte) (int, error) {
if p.closed {
return 0, io.ErrClosedPipe
}
if p.buf.Len() <= BUF_SIZE_LIMIT {
if p.buf.Len() <= recvBufferSizeLimit {
// if p.buf gets too large, write() will panic. We don't want this to happen
break
}

Loading…
Cancel
Save