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) themString := fmt.Sprintf("%s@%s", themAddrString, intf.info.remote)
intf.link.core.log.Infof("Connected %s: %s, source %s", intf.link.core.log.Infof("Connected %s: %s, source %s",
strings.ToUpper(intf.info.linkType), themString, intf.info.local) 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 // Start the link loop
go intf.peer.linkLoop() go intf.peer.linkLoop()
// Start the writer // Start the writer
@ -304,12 +302,13 @@ func (intf *linkInterface) handler() error {
}() }()
// Run reader loop // Run reader loop
for { for {
msg, err := intf.msgIO.readMsg() var msg []byte
msg, err = intf.msgIO.readMsg()
if len(msg) > 0 { if len(msg) > 0 {
intf.peer.handlePacket(msg) intf.peer.handlePacket(msg)
} }
if err != nil { if err != nil {
return err break
} }
select { select {
case signalAlive <- len(msg) > 0: 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
} }