1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-01-07 12:59:15 +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) 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) _, err = conn.Read(b)
if err != nil { if err != nil && err != io.EOF {
er := fmt.Errorf("error: failed to read data from socket: %v", err) er := fmt.Errorf("error: failed to read data from tcp listener: %v", err)
sendErrorLogMessage(toRingbufferCh, Node(s.nodeName), er) 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 // unmarshal the JSON into a struct
sam, err := convertBytesToSAM(b) sam, err := convertBytesToSAM(readBytes)
if err != nil { if err != nil {
er := fmt.Errorf("error: malformed json: %v", err) er := fmt.Errorf("error: malformed json: %v", err)
sendErrorLogMessage(toRingbufferCh, Node(s.nodeName), er) sendErrorLogMessage(toRingbufferCh, Node(s.nodeName), er)
continue return
} }
for i := range sam { 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. // Send the SAM struct to be picked up by the ring buffer.
toRingbufferCh <- sam toRingbufferCh <- sam
conn.Close() }(conn)
} }
} }