Improve buffer management in pipeReader
This commit is contained in:
parent
7f08e01f39
commit
33d142ca08
@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"io"
|
||||
"bufio"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const defaultBufSize = 65536
|
||||
@ -54,14 +55,17 @@ func (preader *pipeReader) RecvMessage() []byte {
|
||||
if preader.scanner.Scan() {
|
||||
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)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (preader *pipeReader) BufSize(size int) {
|
||||
preader.scanner.Buffer(make([]byte, size), size)
|
||||
preader.scanner.Buffer(make([]byte, defaultBufSize), size)
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user