From 7f08e01f39b9352701e9d376b3219e8474dffac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 17 Apr 2019 17:07:08 +0200 Subject: [PATCH] Improve handling of buffer size in Go client --- clients/go/pipeio/pipeio.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clients/go/pipeio/pipeio.go b/clients/go/pipeio/pipeio.go index c93e49e..24bc871 100644 --- a/clients/go/pipeio/pipeio.go +++ b/clients/go/pipeio/pipeio.go @@ -2,9 +2,12 @@ package pipeio import ( "os" + "io" "bufio" ) +const defaultBufSize = 65536 + type pipeReader struct { pipe *os.File @@ -21,6 +24,7 @@ func NewPipeReader(pipePath string) (*pipeReader, error) { if err != nil { return nil, err } + scanner.Buffer(make([]byte, defaultBufSize), defaultBufSize) return &pipeReader{ pipe: pipe, scanner: scanner, @@ -50,9 +54,16 @@ func (preader *pipeReader) RecvMessage() []byte { if preader.scanner.Scan() { return preader.scanner.Bytes() } + if err := preader.scanner.Err(); err != io.EOF { + panic(err) + } return nil } +func (preader *pipeReader) BufSize(size int) { + preader.scanner.Buffer(make([]byte, size), size) +} + type pipeWriter struct { pipe *os.File