Commit db98cd4e authored by Miek Gieben's avatar Miek Gieben

Use *dns.Server (#99)

This does not fix the reload issue, but will give us flexibility
to access the packetConn and listener to make this all work.
parent 49f994fa
......@@ -53,7 +53,7 @@ func trapSignalsPosix() {
caddyfileMu.Lock()
if caddyfile == nil {
// Hmm, did spawing process forget to close stdin? Anyhow, this is unusual.
log.Println("[ERROR] SIGUSR1: no Caddyfile to reload (was stdin left open?)")
log.Println("[ERROR] SIGUSR1: no Corefile to reload (was stdin left open?)")
caddyfileMu.Unlock()
continue
}
......
......@@ -31,6 +31,7 @@ import (
type Server struct {
Addr string // Address we listen on
mux *dns.ServeMux
server [2]*dns.Server
tls bool // whether this server is serving all HTTPS hosts or not
TLSConfig *tls.Config
OnDemandTLS bool // whether this server supports on-demand TLS (load certs at handshake-time)
......@@ -159,11 +160,13 @@ func (s *Server) ListenAndServe() error {
// return the error from the udp listener, disregarding whatever
// happenend to the tcp one.
go func() {
dns.ListenAndServe(s.Addr, "tcp", s.mux)
s.server[0] = &dns.Server{Addr: s.Addr, Net: "tcp", Handler: s.mux}
s.server[0].ListenAndServe()
}()
close(s.startChan) // unblock anyone waiting for this to start listening
return dns.ListenAndServe(s.Addr, "udp", s.mux)
s.server[1] = &dns.Server{Addr: s.Addr, Net: "udp", Handler: s.mux}
return s.server[1].ListenAndServe()
}
// setup prepares the server s to begin listening; it should be
......@@ -242,6 +245,13 @@ func (s *Server) Stop() (err error) {
err = s.listener.Close()
}
s.listenerMu.Unlock()
// Don't know if the above is still valid.
for _, s1 := range s.server {
if err := s1.Shutdown(); err != nil {
return err
}
}
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment