added multi msg reading
This commit is contained in:
11
main.go
11
main.go
@@ -64,12 +64,16 @@ func (daemon *LedDaemon) receive() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if length > 0 {
|
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{}
|
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 {
|
if err != nil {
|
||||||
log.Warningf("[%s] Couldn't decode protobuf msg!", daemon.name)
|
log.Warningf("[%s] Couldn't decode protobuf msg!", daemon.name)
|
||||||
continue
|
continue
|
||||||
@@ -91,6 +95,7 @@ func (daemon *LedDaemon) receive() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *LedDaemon) send() {
|
func (daemon *LedDaemon) send() {
|
||||||
|
Reference in New Issue
Block a user