fixed tcp collector

This commit is contained in:
Timo Volkmann 2021-01-15 14:51:51 +01:00
parent 0fbc6e2758
commit b0e18cb212

View File

@ -1,7 +1,6 @@
package core package core
import ( import (
"bufio"
"fmt" "fmt"
"git.timovolkmann.de/gyrogpsc/ublox" "git.timovolkmann.de/gyrogpsc/ublox"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -212,18 +211,18 @@ func (t *tcpCollector) connectionHandler(conn net.Conn) {
conn.Close() conn.Close()
}() }()
sc := bufio.NewScanner(conn) buf := make([]byte, 2048)
skipped := 0 skipped := 0
//loop: //loop:
for sc.Scan() { for {
// Read the incoming connection into the buffer. // Read the incoming connection into the buffer.
res := append([]byte{}, sc.Bytes()...) n, err := conn.Read(buf)
if err2 := sc.Err(); err2 != nil { if err != nil {
logrus.Warn("lost tcp link:", err2) fmt.Println("TCP error - reading from connection:", n, err.Error())
break break
} }
select { select {
case t.out <- res: case t.out <- buf:
skipped = 0 skipped = 0
default: default:
logrus.Traceln("skip collecting tcp messages") logrus.Traceln("skip collecting tcp messages")