Remove mutex lock during call dns.ResponseWriter.WriteMsg

Write io buffer needn't mutex operation.
Refere to kenshinx/godns#1
This commit is contained in:
kenshinx 2015-02-12 16:06:09 +08:00
parent 8e504da15a
commit ef7d8f8fa2

View File

@ -27,7 +27,6 @@ type GODNSHandler struct {
resolver *Resolver resolver *Resolver
cache Cache cache Cache
hosts Hosts hosts Hosts
mu *sync.Mutex
} }
func NewHandler() *GODNSHandler { func NewHandler() *GODNSHandler {
@ -73,7 +72,7 @@ func NewHandler() *GODNSHandler {
hosts := NewHosts(settings.Hosts, settings.Redis) hosts := NewHosts(settings.Hosts, settings.Redis)
return &GODNSHandler{resolver, cache, hosts, new(sync.Mutex)} return &GODNSHandler{resolver, cache, hosts}
} }
func (h *GODNSHandler) do(Net string, w dns.ResponseWriter, req *dns.Msg) { func (h *GODNSHandler) do(Net string, w dns.ResponseWriter, req *dns.Msg) {
@ -127,10 +126,8 @@ func (h *GODNSHandler) do(Net string, w dns.ResponseWriter, req *dns.Msg) {
Debug("%s didn't hit cache: %s", Q.String(), err) Debug("%s didn't hit cache: %s", Q.String(), err)
} else { } else {
Debug("%s hit cache", Q.String()) Debug("%s hit cache", Q.String())
h.mu.Lock()
mesg.Id = req.Id mesg.Id = req.Id
w.WriteMsg(mesg) w.WriteMsg(mesg)
h.mu.Unlock()
return return
} }
} }