Give bind its own wait group
In a waitgroup, all waits must come after all adds
This commit is contained in:
parent
5e924e5407
commit
1068d6b92b
6
conn.go
6
conn.go
@ -75,6 +75,7 @@ func unsafeCloseBind(device *Device) error {
|
|||||||
err = netc.bind.Close()
|
err = netc.bind.Close()
|
||||||
netc.bind = nil
|
netc.bind = nil
|
||||||
}
|
}
|
||||||
|
netc.stopping.Wait()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,10 +163,11 @@ func (device *Device) BindUpdate() error {
|
|||||||
|
|
||||||
// start receiving routines
|
// start receiving routines
|
||||||
|
|
||||||
device.state.starting.Add(ConnRoutineNumber)
|
device.net.starting.Add(ConnRoutineNumber)
|
||||||
device.state.stopping.Add(ConnRoutineNumber)
|
device.net.stopping.Add(ConnRoutineNumber)
|
||||||
go device.RoutineReceiveIncoming(ipv4.Version, netc.bind)
|
go device.RoutineReceiveIncoming(ipv4.Version, netc.bind)
|
||||||
go device.RoutineReceiveIncoming(ipv6.Version, netc.bind)
|
go device.RoutineReceiveIncoming(ipv6.Version, netc.bind)
|
||||||
|
device.net.starting.Wait()
|
||||||
|
|
||||||
device.log.Debug.Println("UDP bind has been updated")
|
device.log.Debug.Println("UDP bind has been updated")
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ type Device struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
net struct {
|
net struct {
|
||||||
|
starting sync.WaitGroup
|
||||||
|
stopping sync.WaitGroup
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
bind Bind // bind interface
|
bind Bind // bind interface
|
||||||
port uint16 // listening port
|
port uint16 // listening port
|
||||||
|
@ -125,11 +125,11 @@ func (device *Device) RoutineReceiveIncoming(IP int, bind Bind) {
|
|||||||
logDebug := device.log.Debug
|
logDebug := device.log.Debug
|
||||||
defer func() {
|
defer func() {
|
||||||
logDebug.Println("Routine: receive incoming IPv" + strconv.Itoa(IP) + " - stopped")
|
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")
|
logDebug.Println("Routine: receive incoming IPv" + strconv.Itoa(IP) + " - starting")
|
||||||
device.state.starting.Done()
|
device.net.starting.Done()
|
||||||
|
|
||||||
// receive datagrams until conn is closed
|
// receive datagrams until conn is closed
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user