1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-01-05 20:09:16 +00:00

corrected the reading of the steward socket

This commit is contained in:
postmannen 2021-08-23 16:08:21 +02:00
parent b77f04bd5d
commit b332e13c61

View file

@ -23,22 +23,35 @@ func (s *server) readSocket(toRingbufferCh chan []subjectAndMessage) {
sendErrorLogMessage(toRingbufferCh, Node(s.nodeName), er)
}
b := make([]byte, 65535)
go func(conn net.Conn) {
defer conn.Close()
var readBytes []byte
for {
b := make([]byte, 1500)
_, err = conn.Read(b)
if err != nil {
er := fmt.Errorf("error: failed to read data from socket: %v", err)
if err != nil && err != io.EOF {
er := fmt.Errorf("error: failed to read data from tcp listener: %v", err)
sendErrorLogMessage(toRingbufferCh, Node(s.nodeName), er)
continue
return
}
b = bytes.Trim(b, "\x00")
readBytes = append(readBytes, b...)
if err == io.EOF {
break
}
}
readBytes = bytes.Trim(readBytes, "\x00")
// unmarshal the JSON into a struct
sam, err := convertBytesToSAM(b)
sam, err := convertBytesToSAM(readBytes)
if err != nil {
er := fmt.Errorf("error: malformed json: %v", err)
sendErrorLogMessage(toRingbufferCh, Node(s.nodeName), er)
continue
return
}
for i := range sam {
@ -51,7 +64,7 @@ func (s *server) readSocket(toRingbufferCh chan []subjectAndMessage) {
// Send the SAM struct to be picked up by the ring buffer.
toRingbufferCh <- sam
conn.Close()
}(conn)
}
}