added multi msg reading

This commit is contained in:
2017-12-12 22:31:26 +01:00
parent 14566eb2a6
commit 5480c4011e

11
main.go
View File

@@ -64,12 +64,16 @@ func (daemon *LedDaemon) receive() {
break
}
if length > 0 {
msgLen := binary.BigEndian.Uint32(message[0:4])
log.Debugf("[%s] Read %d bytes", daemon.socket.RemoteAddr(), length)
log.Debugf("[%s] Read %d bytes, first protobuf is %d long", daemon.name, length, msgLen)
for i := 0; i < length; {
msgLen := int(binary.BigEndian.Uint32(message[i:i+4]))
log.Debugf("[%s] Reading protobuf after %d (len=%d)", daemon.socket.RemoteAddr(), i, msgLen)
backendMsg := &ledd.BackendWrapperMessage{}
err = proto.Unmarshal(message[4:msgLen+4], backendMsg)
err = proto.Unmarshal(message[i+4:i+msgLen+4], backendMsg)
i += msgLen + 4
if err != nil {
log.Warningf("[%s] Couldn't decode protobuf msg!", daemon.name)
continue
@@ -91,6 +95,7 @@ func (daemon *LedDaemon) receive() {
}
}
}
}
}
func (daemon *LedDaemon) send() {