mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Refactor Server into TCPServer and UDPServer
This commit is contained in:
parent
59c6513b31
commit
4ff46ad447
1 changed files with 21 additions and 16 deletions
37
caddy.go
37
caddy.go
|
@ -235,20 +235,9 @@ func listenerAddrEqual(ln net.Listener, addr string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// Server is a type that can listen and serve.
|
||||
//
|
||||
// These methods must be implemented in pairs. If the server uses
|
||||
// TCP, it should implement Listen() and Serve(). If it uses UDP
|
||||
// or some other protocol, it should implement ListenPacket() and
|
||||
// ServePacket(). If it uses both, all four methods should be
|
||||
// implemented. Any unimplemented methods should be made as no-ops
|
||||
// that simply return nil values.
|
||||
//
|
||||
// A Server must associate with exactly or one listeners and
|
||||
// zero or one packetconns.
|
||||
type Server interface {
|
||||
// TCP methods
|
||||
|
||||
// TCPServer is a type that can listen and serve connections.
|
||||
// A TCPServer must associate with exactly or one net.Listeners.
|
||||
type TCPServer interface {
|
||||
// Listen starts listening by creating a new listener
|
||||
// and returning it. It does not start accepting
|
||||
// connections. For UDP-only servers, this method
|
||||
|
@ -262,9 +251,11 @@ type Server interface {
|
|||
// words, until the server is stopped. For UDP-only
|
||||
// servers, this method can be a no-op that returns nil.
|
||||
Serve(net.Listener) error
|
||||
}
|
||||
|
||||
// UDP methods
|
||||
|
||||
// UDPServer is a type that can listen and serve packets.
|
||||
// A UDPServer must associate with exactly or one net.PacketConns.
|
||||
type UDPServer interface {
|
||||
// ListenPacket starts listening by creating a new packetconn
|
||||
// and returning it. It does not start accepting connections.
|
||||
// TCP-only servers may leave this method blank and return
|
||||
|
@ -280,6 +271,20 @@ type Server interface {
|
|||
ServePacket(net.PacketConn) error
|
||||
}
|
||||
|
||||
// Server is a type that can listen and serve. It supports both
|
||||
// TCP and UDP, although the UDPServer interface can be used
|
||||
// for more than just UDP.
|
||||
//
|
||||
// If the server uses TCP, it should implement TCPServer completely.
|
||||
// If it uses UDP or some other protocol, it should implement
|
||||
// UDPServer completely. If it uses both, both interfaces should be
|
||||
// fully implemented. Any unimplemented methods should be made as
|
||||
// no-ops that simply return nil values.
|
||||
type Server interface {
|
||||
TCPServer
|
||||
UDPServer
|
||||
}
|
||||
|
||||
// Stopper is a type that can stop serving. The stop
|
||||
// does not necessarily have to be graceful.
|
||||
type Stopper interface {
|
||||
|
|
Loading…
Reference in a new issue