mirror of
https://github.com/caddyserver/caddy.git
synced 2026-06-29 21:31:41 +00: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:
parent
502a8979a8
commit
9315738dab
3 changed files with 98 additions and 44 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue