5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-09 23:20:28 +00:00

add the relevant error to the default logging when a connection is closed

This commit is contained in:
Arceliar 2019-02-24 12:59:30 -06:00
parent 042adb0516
commit bb3edd5e55

View File

@ -162,8 +162,6 @@ func (intf *linkInterface) handler() error {
themString := fmt.Sprintf("%s@%s", themAddrString, intf.info.remote)
intf.link.core.log.Infof("Connected %s: %s, source %s",
strings.ToUpper(intf.info.linkType), themString, intf.info.local)
defer intf.link.core.log.Infof("Disconnected %s: %s, source %s",
strings.ToUpper(intf.info.linkType), themString, intf.info.local)
// Start the link loop
go intf.peer.linkLoop()
// Start the writer
@ -304,12 +302,13 @@ func (intf *linkInterface) handler() error {
}()
// Run reader loop
for {
msg, err := intf.msgIO.readMsg()
var msg []byte
msg, err = intf.msgIO.readMsg()
if len(msg) > 0 {
intf.peer.handlePacket(msg)
}
if err != nil {
return err
break
}
select {
case signalAlive <- len(msg) > 0:
@ -317,5 +316,8 @@ func (intf *linkInterface) handler() error {
}
}
////////////////////////////////////////////////////////////////////////////////
return nil
// Remember to set `err` to something useful before returning
intf.link.core.log.Infof("Disconnected %s: %s, source %s, reason: %s",
strings.ToUpper(intf.info.linkType), themString, intf.info.local, err)
return err
}