Improve buffer management in pipeReader

This commit is contained in:
Kristóf Tóth 2019-04-23 10:26:20 +02:00
parent 7f08e01f39
commit 33d142ca08

View File

@ -4,6 +4,7 @@ import (
"os" "os"
"io" "io"
"bufio" "bufio"
"errors"
) )
const defaultBufSize = 65536 const defaultBufSize = 65536
@ -54,14 +55,17 @@ func (preader *pipeReader) RecvMessage() []byte {
if preader.scanner.Scan() { if preader.scanner.Scan() {
return preader.scanner.Bytes() return preader.scanner.Bytes()
} }
if err := preader.scanner.Err(); err != io.EOF { if err := preader.scanner.Err(); err != nil && err != io.EOF {
if err == bufio.ErrTooLong {
err = errors.New("pipeReader buffer too small!")
}
panic(err) panic(err)
} }
return nil return nil
} }
func (preader *pipeReader) BufSize(size int) { func (preader *pipeReader) BufSize(size int) {
preader.scanner.Buffer(make([]byte, size), size) preader.scanner.Buffer(make([]byte, defaultBufSize), size)
} }