Modify exit logging

This commit is contained in:
Nonoo 2020-10-19 09:53:49 +02:00
parent 322284e13f
commit 77d3f7bb40
2 changed files with 5 additions and 8 deletions

10
main.go
View file

@ -17,15 +17,11 @@ func exit(err error) {
if err != nil {
log.Error(err.Error())
}
log.Print("disconnecting")
if streams.audio.common.conn != nil {
streams.audio.sendDisconnect()
}
if streams.control.common.conn != nil {
streams.control.sendDisconnect()
}
streams.audio.sendDisconnect()
streams.control.sendDisconnect()
log.Print("exiting")
if err == nil {
os.Exit(0)
} else {

View file

@ -170,10 +170,11 @@ func (s *streamCommon) waitForPkt6Answer() {
}
func (s *streamCommon) sendDisconnect() {
if !s.gotRemoteSID {
if !s.gotRemoteSID || s.conn == nil {
return
}
log.Print(s.name + "/disconnecting")
s.send([]byte{0x10, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
byte(s.localSID >> 24), byte(s.localSID >> 16), byte(s.localSID >> 8), byte(s.localSID),
byte(s.remoteSID >> 24), byte(s.remoteSID >> 16), byte(s.remoteSID >> 8), byte(s.remoteSID)})