Improve handling of buffer size in Go client
This commit is contained in:
parent
024204e439
commit
7f08e01f39
@ -2,9 +2,12 @@ package pipeio
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"io"
|
||||||
"bufio"
|
"bufio"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultBufSize = 65536
|
||||||
|
|
||||||
|
|
||||||
type pipeReader struct {
|
type pipeReader struct {
|
||||||
pipe *os.File
|
pipe *os.File
|
||||||
@ -21,6 +24,7 @@ func NewPipeReader(pipePath string) (*pipeReader, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
scanner.Buffer(make([]byte, defaultBufSize), defaultBufSize)
|
||||||
return &pipeReader{
|
return &pipeReader{
|
||||||
pipe: pipe,
|
pipe: pipe,
|
||||||
scanner: scanner,
|
scanner: scanner,
|
||||||
@ -50,9 +54,16 @@ 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 {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (preader *pipeReader) BufSize(size int) {
|
||||||
|
preader.scanner.Buffer(make([]byte, size), size)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type pipeWriter struct {
|
type pipeWriter struct {
|
||||||
pipe *os.File
|
pipe *os.File
|
||||||
|
Loading…
Reference in New Issue
Block a user