Commit 59c6513b authored by Matthew Holt's avatar Matthew Holt

Clarify some godoc

parent aede4ccb
...@@ -235,37 +235,48 @@ func listenerAddrEqual(ln net.Listener, addr string) bool { ...@@ -235,37 +235,48 @@ func listenerAddrEqual(ln net.Listener, addr string) bool {
return false return false
} }
// Server is a type that can listen and serve. A Server // Server is a type that can listen and serve.
// must associate with exactly zero or one listeners and packetconns. //
// The listed method "pair up", Listen() and Serve() are needed for a // These methods must be implemented in pairs. If the server uses
// TCP server and ListenPacket() and ServePacket() are needed for a // TCP, it should implement Listen() and Serve(). If it uses UDP
// UDP server. Do both TCP and UDP means all four are needed. // 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 { type Server interface {
// TCP methods
// Listen starts listening by creating a new listener // Listen starts listening by creating a new listener
// and returning it. It does not start accepting // and returning it. It does not start accepting
// connections. // connections. For UDP-only servers, this method
// can be a no-op that returns (nil, nil).
Listen() (net.Listener, error) Listen() (net.Listener, error)
// ListenPacket starts listening by creating a new packetconn
// and returning it. It does not start accepting connections.
// For a TCP only server this method can be a noop and just
// return (nil, nil).
ListenPacket() (net.PacketConn, error)
// Serve starts serving using the provided listener. // Serve starts serving using the provided listener.
// Serve must start the server loop nearly immediately, // Serve must start the server loop nearly immediately,
// or at least not return any errors before the server // or at least not return any errors before the server
// loop begins. Serve blocks indefinitely, or in other // loop begins. Serve blocks indefinitely, or in other
// words, until the server is stopped. // words, until the server is stopped. For UDP-only
// servers, this method can be a no-op that returns nil.
Serve(net.Listener) error Serve(net.Listener) error
// UDP methods
// 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
// (nil, nil).
ListenPacket() (net.PacketConn, error)
// ServePacket starts serving using the provided packetconn. // ServePacket starts serving using the provided packetconn.
// ServePacket must start the server loop nearly immediately, // ServePacket must start the server loop nearly immediately,
// or at least not return any errors before the server // or at least not return any errors before the server
// loop begins. ServePacket blocks indefinitely, or in other // loop begins. ServePacket blocks indefinitely, or in other
// words, until the server is stopped. // words, until the server is stopped. For TCP-only servers,
// For a TCP only server this method can be a noop and just // this method can be a no-op that returns nil.
// return nil.
ServePacket(net.PacketConn) error ServePacket(net.PacketConn) error
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment