func (p *Proxy) udpPacketLoop(conn *net.UDPConn) {
	log.Printf("Entering the UDP listener loop on %s", conn.LocalAddr())
	b := make([]byte, dns.MaxMsgSize)
	for {
		p.RLock()
		if !p.started {
			return
		}
		p.RUnlock()

		n, addr, err := conn.ReadFrom(b)
		// documentation says to handle the packet even if err occurs, so do that first
		if n > 0 {
			// make a copy of all bytes because ReadFrom() will overwrite contents of b on next call
			// we need the contents to survive the call because we're handling them in goroutine
			packet := make([]byte, n)
			copy(packet, b)
			go p.handleUDPPacket(packet, addr, conn) // ignore errors
		}
		if err != nil {
			if isConnClosed(err) {
				log.Printf("udpListen.ReadFrom() returned because we're reading from a closed connection, exiting loop")
				break
			}
			log.Printf("got error when reading from UDP listen: %s", err)
		}
	}
}
// udpPacketLoop listens for incoming UDP packets
udpPacketLoop listens for incoming UDP packets
// udpPacketLoop listens for incoming UDP packets
func (p *Proxy) udpPacketLoop(conn *net.UDPConn) {
	log.Printf("Entering the UDP listener loop on %s", conn.LocalAddr())
	b := make([]byte, dns.MaxMsgSize)
	for {
		p.RLock()
		if !p.started {
			return
		}
		p.RUnlock()
		n, addr, err := conn.ReadFrom(b)
		if n > 0 {
			packet := make([]byte, n)
			copy(packet, b)
			go p.handleUDPPacket(packet, addr, conn) 
		}
		if err != nil {
			if isConnClosed(err) {
				log.Printf("udpListen.ReadFrom() returned because we're reading from a closed connection, exiting loop")
				break
			}
			log.Printf("got error when reading from UDP listen: %s", err)
		}
	}
}
func ( p * Proxy ) udpPacketLoop ( conn * net . UDPConn ) { log . Printf ( " " , conn . LocalAddr ( ) ) b := make ( [ ] byte , dns . MaxMsgSize ) for { p . RLock ( ) if ! p . started { return } p . RUnlock ( ) n , addr , err := conn . ReadFrom ( b ) if n > 0 { packet := make ( [ ] byte , n ) copy ( packet , b ) go p . handleUDPPacket ( packet , addr , conn ) } if err != nil { if isConnClosed ( err ) { log . Printf ( " " ) break } log . Printf ( " " , err ) } } }
udpPacketLoop listens for incoming UDP packets
udpPacketLoop listens for incoming UDP packets
// documentation says to handle the packet even if err occurs, so do that first // make a copy of all bytes because ReadFrom() will overwrite contents of b on next call // we need the contents to survive the call because we're handling them in goroutine // ignore errors