fixed wrong type of variable

This commit is contained in:
2017-12-12 19:37:58 +01:00
parent d3018819de
commit 23702d237d

20
main.go
View File

@@ -55,44 +55,44 @@ func check(e error) {
}
}
func (ledd *LedDaemon) receive() {
func (daemon *LedDaemon) receive() {
for {
message := make([]byte, 4096)
length, err := ledd.socket.Read(message)
length, err := daemon.socket.Read(message)
if err != nil {
ledd.socket.Close()
daemon.socket.Close()
break
}
if length > 0 {
msgLen := binary.BigEndian.Uint32(message[0:3])
log.Debugf("[%s] Read %d bytes, first protobuf is %d long", ledd.name, length, msgLen)
log.Debugf("[%s] Read %d bytes, first protobuf is %d long", daemon.name, length, msgLen)
backendMsg := &ledd.BackendWrapperMessage{}
err = proto.Unmarshal(message[4:msgLen], backendMsg)
if err != nil {
log.Warningf("[%s] Couldn't decode protobuf msg!", ledd.name)
log.Warningf("[%s] Couldn't decode protobuf msg!", daemon.name)
continue
}
switch msg := backendMsg.Msg.(type) {
case *ledd.BackendWrapperMessage_MLedd:
ledd.name = msg.MLedd.Name
daemon.name = msg.MLedd.Name
log.Infof("Connection with LedD (%s) etablished and registered", msg.MLedd.Name)
}
}
}
}
func (ledd *LedDaemon) send() {
defer ledd.socket.Close()
func (daemon *LedDaemon) send() {
defer daemon.socket.Close()
for {
select {
case message, ok := <-ledd.data:
case message, ok := <-daemon.data:
if !ok {
return
}
ledd.socket.Write(message)
daemon.socket.Write(message)
}
}
}