Try to more gracefully handle shutdowns on Windows

This commit is contained in:
Neil Alexander 2019-07-06 11:52:30 +01:00
parent b2607a7205
commit 12486b0557
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 32 additions and 7 deletions

View file

@ -26,6 +26,7 @@ type Multicast struct {
groupAddr string
listeners map[string]*yggdrasil.TcpListener
listenPort uint16
isOpen bool
}
// Init prepares the multicast interface for use.
@ -61,6 +62,7 @@ func (m *Multicast) Start() error {
// Windows can't set this flag, so we need to handle it in other ways
}
m.isOpen = true
go m.multicastStarted()
go m.listen()
go m.announce()
@ -70,6 +72,8 @@ func (m *Multicast) Start() error {
// Stop is not implemented for multicast yet.
func (m *Multicast) Stop() error {
m.isOpen = false
m.sock.Close()
return nil
}
@ -246,6 +250,9 @@ func (m *Multicast) listen() {
for {
nBytes, rcm, fromAddr, err := m.sock.ReadFrom(bs)
if err != nil {
if !m.isOpen {
return
}
panic(err)
}
if rcm != nil {