Fix race condition (update miekg/dns)

Update miekg/dns if this doesn't compile.
pull/18/head
Hugo Landau 10 years ago
parent 32140f0e5a
commit 14fe4c1d81

@ -8,6 +8,7 @@ import "github.com/miekg/dns"
import "os" import "os"
import "net" import "net"
import "fmt" import "fmt"
import "sync"
import "strings" import "strings"
import "path/filepath" import "path/filepath"
@ -22,6 +23,7 @@ type Server struct {
mux *dns.ServeMux mux *dns.ServeMux
udpListener *dns.Server udpListener *dns.Server
tcpListener *dns.Server tcpListener *dns.Server
wgStart sync.WaitGroup
} }
type ServerConfig struct { type ServerConfig struct {
@ -167,11 +169,14 @@ func (s *Server) loadKey(fn, privateFn string) (k *dns.DNSKEY, privatek dns.Priv
} }
func (s *Server) Start() error { func (s *Server) Start() error {
s.mux = dns.NewServeMux() s.mux = dns.NewServeMux()
s.mux.Handle(".", s.engine) s.mux.Handle(".", s.engine)
s.wgStart.Add(2)
s.udpListener = s.runListener("udp") s.udpListener = s.runListener("udp")
s.tcpListener = s.runListener("tcp") s.tcpListener = s.runListener("tcp")
s.wgStart.Wait()
return nil return nil
} }
@ -186,6 +191,9 @@ func (s *Server) runListener(net string) *dns.Server {
Addr: s.cfg.Bind, Addr: s.cfg.Bind,
Net: net, Net: net,
Handler: s.mux, Handler: s.mux,
NotifyStartedFunc: func() {
s.wgStart.Done()
},
} }
go s.doRunListener(ds) go s.doRunListener(ds)
return ds return ds

Loading…
Cancel
Save