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