Fixed blocking reader on closed socket

This commit is contained in:
Mathias Hall-Andersen
2017-11-11 23:26:44 +01:00
parent 892276aa64
commit 566269275e
4 changed files with 32 additions and 23 deletions
+7 -6
View File
@@ -95,23 +95,22 @@ func (device *Device) addToHandshakeQueue(
func (device *Device) RoutineReceiveIncomming(IPVersion int) {
logDebug := device.log.Debug
logDebug.Println("Routine, receive incomming, started")
logDebug.Println("Routine, receive incomming, IP version:", IPVersion)
for {
// wait for bind
logDebug.Println("Waiting for udp bind")
device.net.mutex.Lock()
logDebug.Println("Waiting for UDP socket, IP version:", IPVersion)
device.net.update.Wait()
device.net.mutex.RLock()
bind := device.net.bind
device.net.mutex.Unlock()
device.net.mutex.RUnlock()
if bind == nil {
continue
}
logDebug.Println("LISTEN\n\n\n")
// receive datagrams until conn is closed
buffer := device.GetMessageBuffer()
@@ -427,6 +426,8 @@ func (device *Device) RoutineHandshake() {
err = peer.SendBuffer(packet)
if err == nil {
peer.TimerAnyAuthenticatedPacketTraversal()
} else {
logError.Println("Failed to send response to:", peer.String(), err)
}
case MessageResponseType: