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.
This commit is contained in:
parent
49f994fa80
commit
db98cd4e4b
2 changed files with 13 additions and 3 deletions
|
@ -53,7 +53,7 @@ func trapSignalsPosix() {
|
||||||
caddyfileMu.Lock()
|
caddyfileMu.Lock()
|
||||||
if caddyfile == nil {
|
if caddyfile == nil {
|
||||||
// Hmm, did spawing process forget to close stdin? Anyhow, this is unusual.
|
// 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()
|
caddyfileMu.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Addr string // Address we listen on
|
Addr string // Address we listen on
|
||||||
mux *dns.ServeMux
|
mux *dns.ServeMux
|
||||||
|
server [2]*dns.Server
|
||||||
tls bool // whether this server is serving all HTTPS hosts or not
|
tls bool // whether this server is serving all HTTPS hosts or not
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
OnDemandTLS bool // whether this server supports on-demand TLS (load certs at handshake-time)
|
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
|
// return the error from the udp listener, disregarding whatever
|
||||||
// happenend to the tcp one.
|
// happenend to the tcp one.
|
||||||
go func() {
|
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
|
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
|
// 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()
|
err = s.listener.Close()
|
||||||
}
|
}
|
||||||
s.listenerMu.Unlock()
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue