diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-11-11 23:26:44 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-11-11 23:26:44 +0100 |
commit | 566269275ed97812ec909b10ec77c7c037d9e2ea (patch) | |
tree | a5cf35234f15728dee85918088502ad5653a9513 /src/conn.go | |
parent | 892276aa64ca9b14d2e96186b83145ab2f5ce25a (diff) |
Fixed blocking reader on closed socket
Diffstat (limited to 'src/conn.go')
-rw-r--r-- | src/conn.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/conn.go b/src/conn.go index aa0b72b..0347262 100644 --- a/src/conn.go +++ b/src/conn.go @@ -37,15 +37,14 @@ func parseEndpoint(s string) (*net.UDPAddr, error) { /* Must hold device and net lock */ func unsafeCloseUDPListener(device *Device) error { + var err error netc := &device.net if netc.bind != nil { - if err := netc.bind.Close(); err != nil { - return err - } + err = netc.bind.Close() netc.bind = nil - netc.update.Broadcast() + netc.update.Add(1) } - return nil + return err } // must inform all listeners @@ -63,7 +62,7 @@ func UpdateUDPListener(device *Device) error { return err } - // wait for reader + // assumption: netc.update WaitGroup should be exactly 1 // open new sockets @@ -93,9 +92,10 @@ func UpdateUDPListener(device *Device) error { peer.mutex.Unlock() } - // inform readers of updated bind + // decrease waitgroup to 0 - netc.update.Broadcast() + device.log.Debug.Println("UDP bind has been updated") + netc.update.Done() } return nil |