From 566269275ed97812ec909b10ec77c7c037d9e2ea Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sat, 11 Nov 2017 23:26:44 +0100 Subject: Fixed blocking reader on closed socket --- src/device.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/device.go') diff --git a/src/device.go b/src/device.go index a348c68..033a387 100644 --- a/src/device.go +++ b/src/device.go @@ -23,10 +23,10 @@ type Device struct { } net struct { mutex sync.RWMutex - bind UDPBind // bind interface - port uint16 // listening port - fwmark uint32 // mark value (0 = disabled) - update *sync.Cond // the bind was updated + bind UDPBind // bind interface + port uint16 // listening port + fwmark uint32 // mark value (0 = disabled) + update sync.WaitGroup // the bind was updated (acting as a barrier) } mutex sync.RWMutex privateKey NoisePrivateKey @@ -167,7 +167,7 @@ func NewDevice(tun TUNDevice, logLevel int) *Device { device.net.port = 0 device.net.bind = nil - device.net.update = sync.NewCond(&device.net.mutex) + device.net.update.Add(1) // start workers @@ -209,9 +209,11 @@ func (device *Device) RemoveAllPeers() { } func (device *Device) Close() { + device.log.Info.Println("Closing device") device.RemoveAllPeers() close(device.signal.stop) CloseUDPListener(device) + device.tun.device.Close() } func (device *Device) WaitChannel() chan struct{} { -- cgit v1.2.3