Просмотр исходного кода

Do receive-triggered polls based packets received.

Not amount of raw payload. This allows for the case where the received
payload is only padding, for example. (That can't happen with the
current downstream encoding scheme, which doesn't allow for padding, so
I believe this change results in equivalent behavior.)
David Fifield 6 лет назад
Родитель
Сommit
4663433c08
1 измененных файлов с 15 добавлено и 11 удалено
  1. 15 11
      dnstt-client/dns.go

+ 15 - 11
dnstt-client/dns.go

@@ -191,27 +191,31 @@ func (c *DNSPacketConn) recvLoop(transport net.PacketConn) error {
 		}
 		}
 
 
 		payload := dnsResponsePayload(&resp, c.domain)
 		payload := dnsResponsePayload(&resp, c.domain)
-		// Reading anything gives sendLoop license to poll immediately.
-		if len(payload) > 0 {
-			select {
-			case c.pollChan <- struct{}{}:
-			default:
-			}
-			select {
-			case c.pollChan <- struct{}{}:
-			default:
-			}
-		}
 
 
 		// Pull out the packets contained in the payload.
 		// Pull out the packets contained in the payload.
 		r := bytes.NewReader(payload)
 		r := bytes.NewReader(payload)
+		any := false
 		for {
 		for {
 			p, err := nextPacket(r)
 			p, err := nextPacket(r)
 			if err != nil {
 			if err != nil {
 				break
 				break
 			}
 			}
+			any = true
 			c.QueuePacketConn.QueueIncoming(p, addr)
 			c.QueuePacketConn.QueueIncoming(p, addr)
 		}
 		}
+
+		// If the payload contained one or more packets, permit sendLoop
+		// to poll immediately.
+		if any {
+			select {
+			case c.pollChan <- struct{}{}:
+			default:
+			}
+			select {
+			case c.pollChan <- struct{}{}:
+			default:
+			}
+		}
 	}
 	}
 }
 }