buffered reader
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jake Hillion 2021-01-23 18:39:01 +00:00
parent 18d3b23658
commit 1e0bda09f4

View File

@ -1,6 +1,7 @@
package tcp
import (
"bufio"
"encoding/binary"
"fmt"
"io"
@ -208,10 +209,12 @@ func (f *Flow) consumeMarshalled() {
}
func (f *Flow) produceMarshalled() {
buf := bufio.NewReader(f.conn)
for {
t1 := time.Now()
lengthBytes := make([]byte, 4)
if n, err := io.LimitReader(f.conn, 4).Read(lengthBytes); err != nil {
if n, err := io.LimitReader(buf, 4).Read(lengthBytes); err != nil {
f.produceErrors <- err
return
} else if n != 4 {
@ -224,7 +227,7 @@ func (f *Flow) produceMarshalled() {
var read uint32
for read < length {
if n, err := io.LimitReader(f.conn, int64(length-read)).Read(dataBytes[read:]); err != nil {
if n, err := io.LimitReader(buf, int64(length-read)).Read(dataBytes[read:]); err != nil {
f.produceErrors <- err
return
} else {