From b0e18cb212d26717fc62a125095b9baf85cfc62c Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Fri, 15 Jan 2021 14:51:51 +0100 Subject: [PATCH] fixed tcp collector --- core/collectors.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/core/collectors.go b/core/collectors.go index 3cb3093..f59c79b 100644 --- a/core/collectors.go +++ b/core/collectors.go @@ -1,7 +1,6 @@ package core import ( - "bufio" "fmt" "git.timovolkmann.de/gyrogpsc/ublox" "github.com/sirupsen/logrus" @@ -212,18 +211,18 @@ func (t *tcpCollector) connectionHandler(conn net.Conn) { conn.Close() }() - sc := bufio.NewScanner(conn) + buf := make([]byte, 2048) skipped := 0 //loop: - for sc.Scan() { + for { // Read the incoming connection into the buffer. - res := append([]byte{}, sc.Bytes()...) - if err2 := sc.Err(); err2 != nil { - logrus.Warn("lost tcp link:", err2) + n, err := conn.Read(buf) + if err != nil { + fmt.Println("TCP error - reading from connection:", n, err.Error()) break } select { - case t.out <- res: + case t.out <- buf: skipped = 0 default: logrus.Traceln("skip collecting tcp messages")