mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-06 12:54:40 +08:00
Allow for UDP servers (#935)
* Allow for UDP servers Extend the Server interface with ServePacket and ListenPacket - this is in the same vein as the net package. Plumb the packetconn through the start and restart phases. Rename RestartPair to RestartTriple as it now also contains a Packet. Not that these can now be nil, so we need to check for that when restarting. * Update the documentation
This commit is contained in:
@ -146,6 +146,9 @@ func (s *Server) Listen() (net.Listener, error) {
|
||||
return ln.(*net.TCPListener), nil
|
||||
}
|
||||
|
||||
// ListenPacket is a noop to implement the Server interface.
|
||||
func (s *Server) ListenPacket() (net.PacketConn, error) { return nil, nil }
|
||||
|
||||
// Serve serves requests on ln. It blocks until ln is closed.
|
||||
func (s *Server) Serve(ln net.Listener) error {
|
||||
if tcpLn, ok := ln.(*net.TCPListener); ok {
|
||||
@ -186,6 +189,9 @@ func (s *Server) Serve(ln net.Listener) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ServePacket is a noop to implement the Server interface.
|
||||
func (s *Server) ServePacket(pc net.PacketConn) error { return nil }
|
||||
|
||||
// ServeHTTP is the entry point of all HTTP requests.
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
|
Reference in New Issue
Block a user