err = netc.bind.Close()
netc.bind = nil
}
+ netc.stopping.Wait()
return err
}
// start receiving routines
- device.state.starting.Add(ConnRoutineNumber)
- device.state.stopping.Add(ConnRoutineNumber)
+ device.net.starting.Add(ConnRoutineNumber)
+ device.net.stopping.Add(ConnRoutineNumber)
go device.RoutineReceiveIncoming(ipv4.Version, netc.bind)
go device.RoutineReceiveIncoming(ipv6.Version, netc.bind)
+ device.net.starting.Wait()
device.log.Debug.Println("UDP bind has been updated")
}
}
net struct {
+ starting sync.WaitGroup
+ stopping sync.WaitGroup
mutex sync.RWMutex
bind Bind // bind interface
port uint16 // listening port
logDebug := device.log.Debug
defer func() {
logDebug.Println("Routine: receive incoming IPv" + strconv.Itoa(IP) + " - stopped")
- device.state.stopping.Done()
+ device.net.stopping.Done()
}()
logDebug.Println("Routine: receive incoming IPv" + strconv.Itoa(IP) + " - starting")
- device.state.starting.Done()
+ device.net.starting.Done()
// receive datagrams until conn is closed