httpserver: support QUIC reload

fix issue #958

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw 2017-01-26 14:54:25 +08:00
parent 16250da3f0
commit 65cb966d38

View File

@ -145,8 +145,17 @@ func (s *Server) Listen() (net.Listener, error) {
return ln.(*net.TCPListener), nil return ln.(*net.TCPListener), nil
} }
// ListenPacket is a noop to implement the Server interface. // ListenPacket creates udp connection for QUIC if it is enabled,
func (s *Server) ListenPacket() (net.PacketConn, error) { return nil, nil } func (s *Server) ListenPacket() (net.PacketConn, error) {
if QUIC {
udpAddr, err := net.ResolveUDPAddr("udp", s.Server.Addr)
if err != nil {
return nil, err
}
return net.ListenUDP("udp", udpAddr)
}
return nil, nil
}
// Serve serves requests on ln. It blocks until ln is closed. // Serve serves requests on ln. It blocks until ln is closed.
func (s *Server) Serve(ln net.Listener) error { func (s *Server) Serve(ln net.Listener) error {
@ -172,15 +181,6 @@ func (s *Server) Serve(ln net.Listener) error {
s.tlsGovChan = caddytls.RotateSessionTicketKeys(s.Server.TLSConfig) s.tlsGovChan = caddytls.RotateSessionTicketKeys(s.Server.TLSConfig)
} }
if QUIC {
go func() {
err := s.quicServer.ListenAndServe()
if err != nil {
log.Printf("[ERROR] listening for QUIC connections: %v", err)
}
}()
}
err := s.Server.Serve(ln) err := s.Server.Serve(ln)
if QUIC { if QUIC {
s.quicServer.Close() s.quicServer.Close()
@ -188,8 +188,14 @@ func (s *Server) Serve(ln net.Listener) error {
return err return err
} }
// ServePacket is a noop to implement the Server interface. // ServePacket serves QUIC requests on pc until it is closed.
func (s *Server) ServePacket(pc net.PacketConn) error { return nil } func (s *Server) ServePacket(pc net.PacketConn) error {
if QUIC {
err := s.quicServer.Serve(pc.(*net.UDPConn))
return fmt.Errorf("serving QUIC connections: %v", err)
}
return nil
}
// ServeHTTP is the entry point of all HTTP requests. // ServeHTTP is the entry point of all HTTP requests.
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {