You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gdns/server_tcp.go

36 lines
616 B
Go

package main
import (
"net"
"github.com/fangdingjun/go-log"
"github.com/miekg/dns"
)
func (srv *server) handleTCP(c net.Conn) {
defer c.Close()
log.Debugln("tcp from", c.RemoteAddr())
conn := dns.Conn{Conn: c}
for {
msg, err := conn.ReadMsg()
if err != nil {
log.Debugln("tcp read message", err)
break
}
reply := false
for _, up := range srv.upstreams {
m, err := queryUpstream(msg, up)
if err == nil {
log.Debugln("got reply", m.String())
conn.WriteMsg(m)
reply = true
break
}
log.Debugln("query upstream", up.String(), err)
}
if !reply {
break
}
}
}